Skip to content

Commit

Permalink
[win] Make build-able on vs2017
Browse files Browse the repository at this point in the history
* Cherry pick update to `gyp`
* Import C# and powershell script to get info on vs2017
* update vcbuild.bat & configure
  • Loading branch information
refack committed Mar 14, 2017
1 parent d77a758 commit f75864e
Show file tree
Hide file tree
Showing 9 changed files with 498 additions and 36 deletions.
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,11 @@ def configure_static(o):
if options.enable_asan:
o['libraries'] += ['-static-libasan']

def config_vs2017(o):
if os.environ['GYP_MSVS_VERSION'] != '2017': return
o['msbuild_toolset'] = os.environ['PLATFORM_TOOLSET']
o['msvs_windows_target_platform_version'] = os.environ['SDK2017']


def write(filename, data):
filename = os.path.join(root_dir, filename)
Expand Down Expand Up @@ -1316,6 +1321,7 @@ configure_openssl(output)
configure_intl(output)
configure_static(output)
configure_inspector(output)
config_vs2017(output)

# variables should be a root level element,
# move everything else to target_defaults
Expand Down
3 changes: 2 additions & 1 deletion tools/gyp/pylib/gyp/MSVSUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'loadable_module': 'dll',
'shared_library': 'dll',
'static_library': 'lib',
'windows_driver': 'sys',
}


Expand Down Expand Up @@ -110,7 +111,7 @@ def ShardTargets(target_list, target_dicts):
else:
new_target_dicts[t] = target_dicts[t]
# Shard dependencies.
for t in new_target_dicts:
for t in sorted(new_target_dicts):
for deptype in ('dependencies', 'dependencies_original'):
dependencies = copy.copy(new_target_dicts[t].get(deptype, []))
new_dependencies = []
Expand Down
53 changes: 41 additions & 12 deletions tools/gyp/pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class VisualStudioVersion(object):

def __init__(self, short_name, description,
solution_version, project_version, flat_sln, uses_vcxproj,
path, sdk_based, default_toolset=None):
path, sdk_based, default_toolset=None, compatible_sdks=list()):
self.short_name = short_name
self.description = description
self.solution_version = solution_version
Expand All @@ -28,6 +28,8 @@ def __init__(self, short_name, description,
self.path = path
self.sdk_based = sdk_based
self.default_toolset = default_toolset
compatible_sdks.sort(key=lambda v: float(v.replace('v', '')), reverse=True)
self.compatible_sdks = compatible_sdks

def ShortName(self):
return self.short_name
Expand Down Expand Up @@ -68,17 +70,19 @@ def DefaultToolset(self):
of a user override."""
return self.default_toolset

def SetupScript(self, target_arch):
def _SetupScriptInternal(self, target_arch):
"""Returns a command (with arguments) to be used to set up the
environment."""
# Check if we are running in the SDK command line environment and use
# the setup script from the SDK if so. |target_arch| should be either
# 'x86' or 'x64'.
# If WindowsSDKDir is set and SetEnv.Cmd exists then we are using the
# depot_tools build tools and should run SetEnv.Cmd to set up the
# environment. The check for WindowsSDKDir alone is not sufficient because
# this is set by running vcvarsall.bat.
assert target_arch in ('x86', 'x64')
sdk_dir = os.environ.get('WindowsSDKDir')
if self.sdk_based and sdk_dir:
return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')),
'/' + target_arch]
if sdk_dir:
setup_path = os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd'))
if self.sdk_based and sdk_dir and os.path.exists(setup_path):
return [setup_path, '/' + target_arch]
else:
# We don't use VC/vcvarsall.bat for x86 because vcvarsall calls
# vcvars32, which it can only find if VS??COMNTOOLS is set, which it
Expand Down Expand Up @@ -106,6 +110,14 @@ def SetupScript(self, target_arch):
return [os.path.normpath(
os.path.join(self.path, 'VC/vcvarsall.bat')), arg]

def SetupScript(self, target_arch):
script_data = self._SetupScriptInternal(target_arch)
script_path = script_data[0]
if not os.path.exists(script_path):
raise Exception('%s is missing - make sure VC++ tools are installed.' %
script_path)
return script_data


def _RegistryQueryBase(sysdir, key, value):
"""Use reg.exe to read a particular key.
Expand Down Expand Up @@ -226,6 +238,16 @@ def _CreateVersion(name, path, sdk_based=False):
if path:
path = os.path.normpath(path)
versions = {
'2017': VisualStudioVersion('2017',
'Visual Studio 2017',
solution_version='12.00',
project_version='15.0',
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset='v141',
compatible_sdks=['v8.1', 'v10.0']),
'2015': VisualStudioVersion('2015',
'Visual Studio 2015',
solution_version='12.00',
Expand Down Expand Up @@ -338,14 +360,14 @@ def _DetectVisualStudioVersions(versions_to_check, force_express):
A list of visual studio versions installed in descending order of
usage preference.
Base this on the registry and a quick check if devenv.exe exists.
Only versions 8-10 are considered.
Possibilities are:
2005(e) - Visual Studio 2005 (8)
2008(e) - Visual Studio 2008 (9)
2010(e) - Visual Studio 2010 (10)
2012(e) - Visual Studio 2012 (11)
2013(e) - Visual Studio 2013 (12)
2015 - Visual Studio 2015 (14)
2017 - Visual Studio 2017 (15)
Where (e) is e for express editions of MSVS and blank otherwise.
"""
version_to_year = {
Expand All @@ -355,6 +377,7 @@ def _DetectVisualStudioVersions(versions_to_check, force_express):
'11.0': '2012',
'12.0': '2013',
'14.0': '2015',
'15.0': '2017'
}
versions = []
for version in versions_to_check:
Expand Down Expand Up @@ -385,13 +408,18 @@ def _DetectVisualStudioVersions(versions_to_check, force_express):

# The old method above does not work when only SDK is installed.
keys = [r'HKLM\Software\Microsoft\VisualStudio\SxS\VC7',
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7']
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7',
r'HKLM\Software\Microsoft\VisualStudio\SxS\VS7',
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VS7']
for index in range(len(keys)):
path = _RegistryGetValue(keys[index], version)
if not path:
continue
path = _ConvertToCygpath(path)
if version != '14.0': # There is no Express edition for 2015.
if version == '15.0':
if os.path.exists(path):
versions.append(_CreateVersion('2017', path))
elif version != '14.0': # There is no Express edition for 2015.
versions.append(_CreateVersion(version_to_year[version] + 'e',
os.path.join(path, '..'), sdk_based=True))

Expand All @@ -410,7 +438,7 @@ def SelectVisualStudioVersion(version='auto', allow_fallback=True):
if version == 'auto':
version = os.environ.get('GYP_MSVS_VERSION', 'auto')
version_map = {
'auto': ('14.0', '12.0', '10.0', '9.0', '8.0', '11.0'),
'auto': ('15.0', '14.0', '12.0', '10.0', '9.0', '8.0', '11.0'),
'2005': ('8.0',),
'2005e': ('8.0',),
'2008': ('9.0',),
Expand All @@ -422,6 +450,7 @@ def SelectVisualStudioVersion(version='auto', allow_fallback=True):
'2013': ('12.0',),
'2013e': ('12.0',),
'2015': ('14.0',),
'2017': ('15.0',),
}
override_path = os.environ.get('GYP_MSVS_OVERRIDE_PATH')
if override_path:
Expand Down
Loading

0 comments on commit f75864e

Please sign in to comment.