Returns a command (with arguments) to be used to set up the environment.
(self, target_arch)
| 85 | return self.default_toolset |
| 86 | |
| 87 | def _SetupScriptInternal(self, target_arch): |
| 88 | """Returns a command (with arguments) to be used to set up the |
| 89 | environment.""" |
| 90 | assert target_arch in ("x86", "x64", "arm64"), "target_arch not supported" |
| 91 | # If WindowsSDKDir is set and SetEnv.Cmd exists then we are using the |
| 92 | # depot_tools build tools and should run SetEnv.Cmd to set up the |
| 93 | # environment. The check for WindowsSDKDir alone is not sufficient because |
| 94 | # this is set by running vcvarsall.bat. |
| 95 | sdk_dir = os.environ.get("WindowsSDKDir", "") |
| 96 | setup_path = JoinPath(sdk_dir, "Bin", "SetEnv.Cmd") |
| 97 | if self.sdk_based and sdk_dir and os.path.exists(setup_path): |
| 98 | return [setup_path, "/" + target_arch] |
| 99 | |
| 100 | is_host_arch_x64 = ( |
| 101 | os.environ.get("PROCESSOR_ARCHITECTURE") == "AMD64" |
| 102 | or os.environ.get("PROCESSOR_ARCHITEW6432") == "AMD64" |
| 103 | ) |
| 104 | |
| 105 | # For VS2017 (and newer) it's fairly easy |
| 106 | if self.short_name >= "2017": |
| 107 | script_path = JoinPath( |
| 108 | self.path, "VC", "Auxiliary", "Build", "vcvarsall.bat" |
| 109 | ) |
| 110 | |
| 111 | # Always use a native executable, cross-compiling if necessary. |
| 112 | host_arch = ( |
| 113 | "amd64" |
| 114 | if is_host_arch_x64 |
| 115 | else ( |
| 116 | "arm64" |
| 117 | if os.environ.get("PROCESSOR_ARCHITECTURE") == "ARM64" |
| 118 | else "x86" |
| 119 | ) |
| 120 | ) |
| 121 | msvc_target_arch = {"x64": "amd64"}.get(target_arch, target_arch) |
| 122 | arg = host_arch |
| 123 | if host_arch != msvc_target_arch: |
| 124 | arg += "_" + msvc_target_arch |
| 125 | |
| 126 | return [script_path, arg] |
| 127 | |
| 128 | # We try to find the best version of the env setup batch. |
| 129 | vcvarsall = JoinPath(self.path, "VC", "vcvarsall.bat") |
| 130 | if target_arch == "x86": |
| 131 | if ( |
| 132 | self.short_name >= "2013" |
| 133 | and self.short_name[-1] != "e" |
| 134 | and is_host_arch_x64 |
| 135 | ): |
| 136 | # VS2013 and later, non-Express have a x64-x86 cross that we want |
| 137 | # to prefer. |
| 138 | return [vcvarsall, "amd64_x86"] |
| 139 | else: |
| 140 | # Otherwise, the standard x86 compiler. We don't use VC/vcvarsall.bat |
| 141 | # for x86 because vcvarsall calls vcvars32, which it can only find if |
| 142 | # VS??COMNTOOLS is set, which isn't guaranteed. |
| 143 | return [JoinPath(self.path, "Common7", "Tools", "vsvars32.bat")] |
| 144 | elif target_arch == "x64": |
no test coverage detected