Skip to content

Commit d0e93e0

Browse files
committed
gyp: sync code base with nodejs repo
1 parent 04da736 commit d0e93e0

28 files changed

+965
-383
lines changed

gyp/AUTHORS

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ Ryan Norton <[email protected]>
1111
David J. Sankel <[email protected]>
1212
Eric N. Vander Weele <[email protected]>
1313
Tom Freudenberg <[email protected]>
14+
Julien Brianceau <[email protected]>
15+
Refael Ackermann <[email protected]>

gyp/DEPS

-24
This file was deleted.

gyp/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GYP can Generate Your Projects.
2+
===================================
3+
4+
Documents are available at [gyp.gsrc.io](https://gyp.gsrc.io), or you can check out ```md-pages``` branch to read those documents offline.

gyp/codereview.settings

-10
This file was deleted.

gyp/pylib/gyp/MSVSNew.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import hashlib
88
import os
99
import random
10+
from operator import attrgetter
1011

1112
import gyp.common
1213

@@ -59,9 +60,6 @@ def __cmp__(self, other):
5960
# Sort by name then guid (so things are in order on vs2008).
6061
return cmp((self.name, self.get_guid()), (other.name, other.get_guid()))
6162

62-
def __lt__(self, other):
63-
return self.__cmp__(other) < 0
64-
6563

6664
class MSVSFolder(MSVSSolutionEntry):
6765
"""Folder in a Visual Studio project or solution."""
@@ -89,7 +87,7 @@ def __init__(self, path, name = None, entries = None,
8987
self.guid = guid
9088

9189
# Copy passed lists (or set to empty lists)
92-
self.entries = sorted(list(entries or []))
90+
self.entries = sorted(entries or [], key=attrgetter('path'))
9391
self.items = list(items or [])
9492

9593
self.entry_type_guid = ENTRY_TYPE_GUIDS['folder']
@@ -233,7 +231,7 @@ def Write(self, writer=gyp.common.WriteOnDiff):
233231
if isinstance(e, MSVSFolder):
234232
entries_to_check += e.entries
235233

236-
all_entries = sorted(all_entries)
234+
all_entries = sorted(all_entries, key=attrgetter('path'))
237235

238236
# Open file and print header
239237
f = writer(self.path)

gyp/pylib/gyp/MSVSSettings.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
467467
msvs_tool[msvs_setting](msvs_value, msbuild_settings)
468468
except ValueError as e:
469469
print('Warning: while converting %s/%s to MSBuild, '
470-
'%s' % (msvs_tool_name, msvs_setting, e), file=stderr)
470+
'%s' % (msvs_tool_name, msvs_setting, e), file=stderr)
471471
else:
472472
_ValidateExclusionSetting(msvs_setting,
473473
msvs_tool,
@@ -477,7 +477,7 @@ def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
477477
stderr)
478478
else:
479479
print('Warning: unrecognized tool %s while converting to '
480-
'MSBuild.' % msvs_tool_name, file=stderr)
480+
'MSBuild.' % msvs_tool_name, file=stderr)
481481
return msbuild_settings
482482

483483

@@ -598,6 +598,7 @@ def _ValidateSettings(validators, settings, stderr):
598598
_Same(_compile, 'UseFullPaths', _boolean) # /FC
599599
_Same(_compile, 'WholeProgramOptimization', _boolean) # /GL
600600
_Same(_compile, 'XMLDocumentationFileName', _file_name)
601+
_Same(_compile, 'CompileAsWinRT', _boolean) # /ZW
601602

602603
_Same(_compile, 'AssemblerOutput',
603604
_Enumeration(['NoListing',

gyp/pylib/gyp/MSVSSettings_test.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
"""Unit tests for the MSVSSettings.py file."""
88

9-
try:
10-
from cStringIO import StringIO
11-
except ImportError:
12-
from io import StringIO
13-
149
import unittest
1510
import gyp.MSVSSettings as MSVSSettings
1611

12+
try:
13+
from StringIO import StringIO # Python 2
14+
except ImportError:
15+
from io import StringIO # Python 3
16+
1717

1818
class TestSequenceFunctions(unittest.TestCase):
1919

gyp/pylib/gyp/MSVSUtil.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'loadable_module': 'dll',
1515
'shared_library': 'dll',
1616
'static_library': 'lib',
17+
'windows_driver': 'sys',
1718
}
1819

1920

@@ -110,7 +111,7 @@ def ShardTargets(target_list, target_dicts):
110111
else:
111112
new_target_dicts[t] = target_dicts[t]
112113
# Shard dependencies.
113-
for t in new_target_dicts:
114+
for t in sorted(new_target_dicts):
114115
for deptype in ('dependencies', 'dependencies_original'):
115116
dependencies = copy.copy(new_target_dicts[t].get(deptype, []))
116117
new_dependencies = []

gyp/pylib/gyp/MSVSVersion.py

+104-43
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
PY3 = bytes != str
1616

1717

18+
def JoinPath(*args):
19+
return os.path.normpath(os.path.join(*args))
20+
21+
1822
class VisualStudioVersion(object):
1923
"""Information regarding a version of Visual Studio."""
2024

2125
def __init__(self, short_name, description,
2226
solution_version, project_version, flat_sln, uses_vcxproj,
23-
path, sdk_based, default_toolset=None):
27+
path, sdk_based, default_toolset=None, compatible_sdks=None):
2428
self.short_name = short_name
2529
self.description = description
2630
self.solution_version = solution_version
@@ -30,6 +34,9 @@ def __init__(self, short_name, description,
3034
self.path = path
3135
self.sdk_based = sdk_based
3236
self.default_toolset = default_toolset
37+
compatible_sdks = compatible_sdks or []
38+
compatible_sdks.sort(key=lambda v: float(v.replace('v', '')), reverse=True)
39+
self.compatible_sdks = compatible_sdks
3340

3441
def ShortName(self):
3542
return self.short_name
@@ -70,43 +77,67 @@ def DefaultToolset(self):
7077
of a user override."""
7178
return self.default_toolset
7279

73-
def SetupScript(self, target_arch):
80+
81+
def _SetupScriptInternal(self, target_arch):
7482
"""Returns a command (with arguments) to be used to set up the
7583
environment."""
76-
# Check if we are running in the SDK command line environment and use
77-
# the setup script from the SDK if so. |target_arch| should be either
78-
# 'x86' or 'x64'.
79-
assert target_arch in ('x86', 'x64')
80-
sdk_dir = os.environ.get('WindowsSDKDir')
81-
if self.sdk_based and sdk_dir:
82-
return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')),
83-
'/' + target_arch]
84-
else:
85-
# We don't use VC/vcvarsall.bat for x86 because vcvarsall calls
86-
# vcvars32, which it can only find if VS??COMNTOOLS is set, which it
87-
# isn't always.
88-
if target_arch == 'x86':
89-
if self.short_name >= '2013' and self.short_name[-1] != 'e' and (
90-
os.environ.get('PROCESSOR_ARCHITECTURE') == 'AMD64' or
91-
os.environ.get('PROCESSOR_ARCHITEW6432') == 'AMD64'):
92-
# VS2013 and later, non-Express have a x64-x86 cross that we want
93-
# to prefer.
94-
return [os.path.normpath(
95-
os.path.join(self.path, 'VC/vcvarsall.bat')), 'amd64_x86']
96-
# Otherwise, the standard x86 compiler.
97-
return [os.path.normpath(
98-
os.path.join(self.path, 'Common7/Tools/vsvars32.bat'))]
84+
assert target_arch in ('x86', 'x64'), "target_arch not supported"
85+
# If WindowsSDKDir is set and SetEnv.Cmd exists then we are using the
86+
# depot_tools build tools and should run SetEnv.Cmd to set up the
87+
# environment. The check for WindowsSDKDir alone is not sufficient because
88+
# this is set by running vcvarsall.bat.
89+
sdk_dir = os.environ.get('WindowsSDKDir', '')
90+
setup_path = JoinPath(sdk_dir, 'Bin', 'SetEnv.Cmd')
91+
if self.sdk_based and sdk_dir and os.path.exists(setup_path):
92+
return [setup_path, '/' + target_arch]
93+
94+
is_host_arch_x64 = (
95+
os.environ.get('PROCESSOR_ARCHITECTURE') == 'AMD64' or
96+
os.environ.get('PROCESSOR_ARCHITEW6432') == 'AMD64'
97+
)
98+
99+
# For VS2017 (and newer) it's fairly easy
100+
if self.short_name >= '2017':
101+
script_path = JoinPath(self.path,
102+
'VC', 'Auxiliary', 'Build', 'vcvarsall.bat')
103+
104+
# Always use a native executable, cross-compiling if necessary.
105+
host_arch = 'amd64' if is_host_arch_x64 else 'x86'
106+
msvc_target_arch = 'amd64' if target_arch == 'x64' else 'x86'
107+
arg = host_arch
108+
if host_arch != msvc_target_arch:
109+
arg += '_' + msvc_target_arch
110+
111+
return [script_path, arg]
112+
113+
# We try to find the best version of the env setup batch.
114+
vcvarsall = JoinPath(self.path, 'VC', 'vcvarsall.bat')
115+
if target_arch == 'x86':
116+
if self.short_name >= '2013' and self.short_name[-1] != 'e' and \
117+
is_host_arch_x64:
118+
# VS2013 and later, non-Express have a x64-x86 cross that we want
119+
# to prefer.
120+
return [vcvarsall, 'amd64_x86']
99121
else:
100-
assert target_arch == 'x64'
101-
arg = 'x86_amd64'
102-
# Use the 64-on-64 compiler if we're not using an express
103-
# edition and we're running on a 64bit OS.
104-
if self.short_name[-1] != 'e' and (
105-
os.environ.get('PROCESSOR_ARCHITECTURE') == 'AMD64' or
106-
os.environ.get('PROCESSOR_ARCHITEW6432') == 'AMD64'):
107-
arg = 'amd64'
108-
return [os.path.normpath(
109-
os.path.join(self.path, 'VC/vcvarsall.bat')), arg]
122+
# Otherwise, the standard x86 compiler. We don't use VC/vcvarsall.bat
123+
# for x86 because vcvarsall calls vcvars32, which it can only find if
124+
# VS??COMNTOOLS is set, which isn't guaranteed.
125+
return [JoinPath(self.path, 'Common7', 'Tools', 'vsvars32.bat')]
126+
elif target_arch == 'x64':
127+
arg = 'x86_amd64'
128+
# Use the 64-on-64 compiler if we're not using an express edition and
129+
# we're running on a 64bit OS.
130+
if self.short_name[-1] != 'e' and is_host_arch_x64:
131+
arg = 'amd64'
132+
return [vcvarsall, arg]
133+
134+
def SetupScript(self, target_arch):
135+
script_data = self._SetupScriptInternal(target_arch)
136+
script_path = script_data[0]
137+
if not os.path.exists(script_path):
138+
raise Exception('%s is missing - make sure VC++ tools are installed.' %
139+
script_path)
140+
return script_data
110141

111142

112143
def _RegistryQueryBase(sysdir, key, value):
@@ -181,11 +212,11 @@ def _RegistryGetValueUsingWinReg(key, value):
181212
ImportError if _winreg is unavailable.
182213
"""
183214
try:
184-
# Python 2
185-
from _winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
215+
# Python 2
216+
from _winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
186217
except ImportError:
187-
# Python 3
188-
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
218+
# Python 3
219+
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
189220

190221
try:
191222
root, subkey = key.split('\\', 1)
@@ -236,6 +267,26 @@ def _CreateVersion(name, path, sdk_based=False):
236267
if path:
237268
path = os.path.normpath(path)
238269
versions = {
270+
'2019': VisualStudioVersion('2019',
271+
'Visual Studio 2019',
272+
solution_version='12.00',
273+
project_version='16.0',
274+
flat_sln=False,
275+
uses_vcxproj=True,
276+
path=path,
277+
sdk_based=sdk_based,
278+
default_toolset='v142',
279+
compatible_sdks=['v8.1', 'v10.0']),
280+
'2017': VisualStudioVersion('2017',
281+
'Visual Studio 2017',
282+
solution_version='12.00',
283+
project_version='15.0',
284+
flat_sln=False,
285+
uses_vcxproj=True,
286+
path=path,
287+
sdk_based=sdk_based,
288+
default_toolset='v141',
289+
compatible_sdks=['v8.1', 'v10.0']),
239290
'2015': VisualStudioVersion('2015',
240291
'Visual Studio 2015',
241292
solution_version='12.00',
@@ -350,14 +401,15 @@ def _DetectVisualStudioVersions(versions_to_check, force_express):
350401
A list of visual studio versions installed in descending order of
351402
usage preference.
352403
Base this on the registry and a quick check if devenv.exe exists.
353-
Only versions 8-10 are considered.
354404
Possibilities are:
355405
2005(e) - Visual Studio 2005 (8)
356406
2008(e) - Visual Studio 2008 (9)
357407
2010(e) - Visual Studio 2010 (10)
358408
2012(e) - Visual Studio 2012 (11)
359409
2013(e) - Visual Studio 2013 (12)
360410
2015 - Visual Studio 2015 (14)
411+
2017 - Visual Studio 2017 (15)
412+
2019 - Visual Studio 2019 (16)
361413
Where (e) is e for express editions of MSVS and blank otherwise.
362414
"""
363415
version_to_year = {
@@ -367,6 +419,8 @@ def _DetectVisualStudioVersions(versions_to_check, force_express):
367419
'11.0': '2012',
368420
'12.0': '2013',
369421
'14.0': '2015',
422+
'15.0': '2017',
423+
'16.0': '2019',
370424
}
371425
versions = []
372426
for version in versions_to_check:
@@ -397,13 +451,18 @@ def _DetectVisualStudioVersions(versions_to_check, force_express):
397451

398452
# The old method above does not work when only SDK is installed.
399453
keys = [r'HKLM\Software\Microsoft\VisualStudio\SxS\VC7',
400-
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7']
454+
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7',
455+
r'HKLM\Software\Microsoft\VisualStudio\SxS\VS7',
456+
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VS7']
401457
for index in range(len(keys)):
402458
path = _RegistryGetValue(keys[index], version)
403459
if not path:
404460
continue
405461
path = _ConvertToCygpath(path)
406-
if version != '14.0': # There is no Express edition for 2015.
462+
if version == '15.0':
463+
if os.path.exists(path):
464+
versions.append(_CreateVersion('2017', path))
465+
elif version != '14.0': # There is no Express edition for 2015.
407466
versions.append(_CreateVersion(version_to_year[version] + 'e',
408467
os.path.join(path, '..'), sdk_based=True))
409468

@@ -422,7 +481,7 @@ def SelectVisualStudioVersion(version='auto', allow_fallback=True):
422481
if version == 'auto':
423482
version = os.environ.get('GYP_MSVS_VERSION', 'auto')
424483
version_map = {
425-
'auto': ('14.0', '12.0', '10.0', '9.0', '8.0', '11.0'),
484+
'auto': ('16.0', '15.0', '14.0', '12.0', '10.0', '9.0', '8.0', '11.0'),
426485
'2005': ('8.0',),
427486
'2005e': ('8.0',),
428487
'2008': ('9.0',),
@@ -434,6 +493,8 @@ def SelectVisualStudioVersion(version='auto', allow_fallback=True):
434493
'2013': ('12.0',),
435494
'2013e': ('12.0',),
436495
'2015': ('14.0',),
496+
'2017': ('15.0',),
497+
'2019': ('16.0',),
437498
}
438499
override_path = os.environ.get('GYP_MSVS_OVERRIDE_PATH')
439500
if override_path:

0 commit comments

Comments
 (0)