Chromium Code Reviews| Index: build/vs_toolchain.py |
| diff --git a/build/vs_toolchain.py b/build/vs_toolchain.py |
| index fca394ea699e07454b24ebb58b922e5be78332d2..3aa2f494101234d248de6475885ff268171b2c69 100755 |
| --- a/build/vs_toolchain.py |
| +++ b/build/vs_toolchain.py |
| @@ -37,8 +37,8 @@ def SetEnvironmentAndGetRuntimeDllDirs(): |
| bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
| # When running on a non-Windows host, only do this if the SDK has explicitly |
| # been downloaded before (in which case json_data_file will exist). |
| - if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file)) |
| - and depot_tools_win_toolchain): |
| + if (depot_tools_win_toolchain and (sys.platform in ('win32', 'cygwin') |
| + or os.path.exists(json_data_file))): |
| if ShouldUpdateToolchain(): |
| Update() |
| with open(json_data_file, 'r') as tempf: |
| @@ -72,16 +72,14 @@ def SetEnvironmentAndGetRuntimeDllDirs(): |
| os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) |
| for k, v in gyp_defines_dict.iteritems()) |
| - os.environ['WINDOWSSDKDIR'] = win_sdk |
| + os.environ['WindowsSdkDir'] = win_sdk |
| os.environ['WDK_DIR'] = wdk |
| # Include the VS runtime in the PATH in case it's not machine-installed. |
| runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs) |
| os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH'] |
| elif sys.platform == 'win32' and not depot_tools_win_toolchain: |
| - if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: |
| - os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath() |
| - if not 'GYP_MSVS_VERSION' in os.environ: |
| - os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion() |
| + GetVisualStudioVersion() |
| + DetectVisualStudioPath() |
| # When using an installed toolchain these files aren't needed in the output |
| # directory in order to run binaries locally, but they are needed in order |
| @@ -122,11 +120,34 @@ def _RegistryGetValue(key, value): |
| except ImportError: |
| raise Exception('The python library _winreg not found.') |
| - |
| +year_to_version = { |
| + '2013': '12.0', |
| + '2015': '14.0', |
| + '2017': '15.0', |
| +} |
| def GetVisualStudioVersion(): |
| """Return GYP_MSVS_VERSION of Visual Studio. |
| """ |
| - return os.environ.get('GYP_MSVS_VERSION', CURRENT_DEFAULT_TOOLCHAIN_VERSION) |
| + if 'VisualStudioVersion' not in os.environ: |
| + raise ValueError('Please run from within a VS console (with ENV variables)') |
| + |
| + ver = os.environ['VisualStudioVersion'] |
| + year = year_to_version.keys()[year_to_version.values().index(ver)] |
| + |
| + if year not in year_to_version: |
| + years = ', '.join(year_to_version.keys()) |
| + raise ValueError('Visual Studio version %s not supported.' |
| + 'Supported versions are: %s' % (year, years)) |
| + |
| + if 'GYP_MSVS_VERSION' in os.environ: |
| + wanted = os.environ.get('GYP_MSVS_VERSION') |
| + if wanted != year: |
| + raise ValueError('GYP_MSVS_VERSION does not match VS console version' |
| + '%s != %s(%s)' % (wanted, year, ver)) |
| + else: |
| + os.environ['GYP_MSVS_VERSION'] = year |
| + |
| + return year |
| def DetectVisualStudioPath(): |
| @@ -135,41 +156,18 @@ def DetectVisualStudioPath(): |
| # Note that this code is used from |
| # build/toolchain/win/setup_toolchain.py as well. |
| - version_as_year = GetVisualStudioVersion() |
| - year_to_version = { |
| - '2013': '12.0', |
| - '2015': '14.0', |
| - '2017': '15.0', |
| - } |
| - if version_as_year not in year_to_version: |
| - raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)' |
| - ' not supported. Supported versions are: %s') % ( |
| - version_as_year, ', '.join(year_to_version.keys()))) |
| - version = year_to_version[version_as_year] |
| - if version_as_year == '2017': |
| - # The VC++ 2017 install location needs to be located using COM instead of |
| - # the registry. For details see: |
| - # https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/ |
| - # For now we use a hardcoded default with an environment variable override. |
| - path = r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional' |
| - path = os.environ.get('vs2017_install', path) |
| - if os.path.exists(path): |
| - return path |
| + GetVisualStudioVersion() |
| + if 'VSINSTALLDIR' not in os.environ: |
| + raise ValueError('Please run from within a VS console (with ENV variables)') |
| + if 'GYP_MSVS_OVERRIDE_PATH' in os.environ: |
| + path = os.environ['GYP_MSVS_OVERRIDE_PATH'] |
| else: |
| - keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, |
| - r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version] |
| - for key in keys: |
| - path = _RegistryGetValue(key, 'InstallDir') |
| - if not path: |
| - continue |
| - path = os.path.normpath(os.path.join(path, '..', '..')) |
| - return path |
| - |
| - raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' |
| - ' not found.') % (version_as_year)) |
| + path = os.environ['VSINSTALLDIR'] |
| + os.environ['GYP_MSVS_OVERRIDE_PATH'] = path |
| + return path |
| -def _VersionNumber(): |
| +def _SdkFileSuffix(): |
|
brucedawson
2017/03/27 23:23:52
This needs a larger comment to explain what this n
|
| """Gets the standard version number ('120', '140', etc.) based on |
| GYP_MSVS_VERSION.""" |
| vs_version = GetVisualStudioVersion() |
| @@ -177,8 +175,9 @@ def _VersionNumber(): |
| return '120' |
| if vs_version == '2015': |
| return '140' |
| + # even on 2017 (a.k.a. vc1410 version of files is 140) |
| if vs_version == '2017': |
| - return '150' |
| + return '140' |
| raise ValueError('Unexpected GYP_MSVS_VERSION') |
| @@ -223,11 +222,7 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix): |
| # Copy the UCRT files needed by VS 2015 from the Windows SDK. This location |
| # includes the api-ms-win-crt-*.dll files that are not found in the Windows |
| # directory. These files are needed for component builds. |
| - # If WINDOWSSDKDIR is not set use the default SDK path. This will be the case |
| - # when DEPOT_TOOLS_WIN_TOOLCHAIN=0 and vcvarsall.bat has not been run. |
| - win_sdk_dir = os.path.normpath( |
| - os.environ.get('WINDOWSSDKDIR', |
| - 'C:\\Program Files (x86)\\Windows Kits\\10')) |
| + win_sdk_dir = os.path.normpath(os.environ['WindowsSdkDir']) |
| ucrt_dll_dirs = os.path.join(win_sdk_dir, r'Redist\ucrt\DLLs', target_cpu) |
| ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll')) |
| assert len(ucrt_files) > 0 |
| @@ -243,30 +238,24 @@ def _CopyRuntime(target_dir, source_dir, target_cpu, debug): |
| """Copy the VS runtime DLLs, only if the target doesn't exist, but the target |
| directory does exist. Handles VS 2013, VS 2015, and VS 2017.""" |
| suffix = "d.dll" if debug else ".dll" |
| + dll_pattern = "%s" + _SdkFileSuffix() + suffix |
| if GetVisualStudioVersion() in ['2015', '2017']: |
| # VS 2017 uses the same CRT DLLs as VS 2015. |
| - _CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix, |
| - suffix) |
| + _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix) |
| else: |
| - _CopyRuntime2013(target_dir, source_dir, 'msvc%s120' + suffix) |
| + _CopyRuntime2013(target_dir, source_dir, 'msvc' + dll_pattern) |
|
brucedawson
2017/03/27 23:23:52
You'll need to rebase as the 2013 support was just
|
| # Copy the PGO runtime library to the release directories. |
| if not debug and os.environ.get('GYP_MSVS_OVERRIDE_PATH'): |
| - pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), |
| - 'VC', 'bin') |
| - pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') |
| - pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' |
| - if target_cpu == "x86": |
| - source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) |
| - if os.path.exists(source_x86): |
| - _CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll), source_x86) |
| - elif target_cpu == "x64": |
| - source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) |
| - if os.path.exists(source_x64): |
| - _CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll), |
| - source_x64) |
| + pgo_runtime_dll = 'pgort' + _SdkFileSuffix() + '.dll' |
| + paths = subprocess.check_output(['where.exe', pgo_runtime_dll])\ |
| + .strip()\ |
| + .split('\n') |
| + source = paths[-1].strip() |
| + if os.path.exists(source): |
| + _CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll), source) |
| else: |
| - raise NotImplementedError("Unexpected target_cpu value:" + target_cpu) |
| + raise NotImplementedError("could not find " + pgo_runtime_dll) |
| def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
| @@ -390,7 +379,7 @@ def Update(force=False): |
| depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
| # Necessary so that get_toolchain_if_necessary.py will put the VS toolkit |
| # in the correct directory. |
| - os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion() |
| + GetVisualStudioVersion() |
| get_toolchain_args = [ |
| sys.executable, |
| os.path.join(depot_tools_path, |
| @@ -415,14 +404,7 @@ def SetEnvironmentAndGetSDKDir(): |
| """Gets location information about the current sdk (must have been |
| previously updated by 'update'). This is used for the GN build.""" |
| runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() |
| - |
| - # If WINDOWSSDKDIR is not set, search the default SDK path and set it. |
| - if not 'WINDOWSSDKDIR' in os.environ: |
| - default_sdk_path = 'C:\\Program Files (x86)\\Windows Kits\\10' |
| - if os.path.isdir(default_sdk_path): |
| - os.environ['WINDOWSSDKDIR'] = default_sdk_path |
| - |
| - return NormalizePath(os.environ['WINDOWSSDKDIR']) |
| + return NormalizePath(os.environ['WindowsSdkDir']) |
| def GetToolchainDir(): |