Skip to content

Commit 8f34b83

Browse files
refackMylesBorins
authored andcommitted
1 parent ffe572a commit 8f34b83

10 files changed

+279
-383
lines changed

tools/gyp/gyptest.py

+174-206
Large diffs are not rendered by default.

tools/gyp/pylib/gyp/MSVSVersion.py

+47-29
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import glob
1414

1515

16+
def JoinPath(*args):
17+
return os.path.normpath(os.path.join(*args))
18+
19+
1620
class VisualStudioVersion(object):
1721
"""Information regarding a version of Visual Studio."""
1822

@@ -71,45 +75,59 @@ def DefaultToolset(self):
7175
of a user override."""
7276
return self.default_toolset
7377

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

114132
def SetupScript(self, target_arch):
115133
script_data = self._SetupScriptInternal(target_arch)

tools/gyp/pylib/gyp/easy_xml.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import re
66
import os
7+
import locale
78

89

910
def XmlToString(content, encoding='utf-8', pretty=False):
@@ -116,6 +117,10 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False,
116117
if win32 and os.linesep != '\r\n':
117118
xml_string = xml_string.replace('\n', '\r\n')
118119

120+
default_encoding = locale.getdefaultlocale()[1]
121+
if default_encoding and default_encoding.upper() != encoding.upper():
122+
xml_string = xml_string.decode(default_encoding).encode(encoding)
123+
119124
# Get the old content
120125
try:
121126
f = open(path, 'r')

tools/gyp/pylib/gyp/generator/compile_commands_json.py

-115
This file was deleted.

tools/gyp/pylib/gyp/generator/make.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def CalculateGeneratorInputInfo(params):
147147
# special "figure out circular dependencies" flags around the entire
148148
# input list during linking.
149149
quiet_cmd_link = LINK($(TOOLSET)) $@
150-
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
150+
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
151151
152152
# We support two kinds of shared objects (.so):
153153
# 1) shared_library, which is just bundling together many dependent libraries
@@ -2074,10 +2074,10 @@ def CalculateMakefilePath(build_file, base_name):
20742074
'AR.target': GetEnvironFallback(('AR_target', 'AR'), '$(AR)'),
20752075
'CXX.target': GetEnvironFallback(('CXX_target', 'CXX'), '$(CXX)'),
20762076
'LINK.target': GetEnvironFallback(('LINK_target', 'LINK'), '$(LINK)'),
2077-
'CC.host': GetEnvironFallback(('CC_host', 'CC'), 'gcc'),
2078-
'AR.host': GetEnvironFallback(('AR_host', 'AR'), 'ar'),
2079-
'CXX.host': GetEnvironFallback(('CXX_host', 'CXX'), 'g++'),
2080-
'LINK.host': GetEnvironFallback(('LINK_host', 'LINK'), '$(CXX.host)'),
2077+
'CC.host': GetEnvironFallback(('CC_host',), 'gcc'),
2078+
'AR.host': GetEnvironFallback(('AR_host',), 'ar'),
2079+
'CXX.host': GetEnvironFallback(('CXX_host',), 'g++'),
2080+
'LINK.host': GetEnvironFallback(('LINK_host',), '$(CXX.host)'),
20812081
})
20822082

20832083
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])

tools/gyp/pylib/gyp/generator/msvs.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,19 @@ def _ConfigWindowsTargetPlatformVersion(config_data, version):
306306
continue
307307
version = MSVSVersion._RegistryGetValue(key % ver, 'ProductVersion') or ''
308308
# Find a matching entry in sdk_dir\include.
309-
names = sorted([x for x in os.listdir(r'%s\include' % sdk_dir)
309+
expected_sdk_dir=r'%s\include' % sdk_dir
310+
names = sorted([x for x in (os.listdir(expected_sdk_dir)
311+
if os.path.isdir(expected_sdk_dir)
312+
else []
313+
)
310314
if x.startswith(version)], reverse=True)
311-
return names[0]
315+
if names:
316+
return names[0]
317+
else:
318+
print >> sys.stdout, (
319+
'Warning: No include files found for '
320+
'detected Windows SDK version %s' % (version)
321+
)
312322

313323

314324
def _BuildCommandLineForRuleRaw(spec, cmd, cygwin_shell, has_input_path,
@@ -1717,14 +1727,17 @@ def _GetCopies(spec):
17171727
src_bare = src[:-1]
17181728
base_dir = posixpath.split(src_bare)[0]
17191729
outer_dir = posixpath.split(src_bare)[1]
1720-
cmd = 'cd "%s" && xcopy /e /f /y "%s" "%s\\%s\\"' % (
1721-
_FixPath(base_dir), outer_dir, _FixPath(dst), outer_dir)
1730+
fixed_dst = _FixPath(dst)
1731+
full_dst = '"%s\\%s\\"' % (fixed_dst, outer_dir)
1732+
cmd = 'mkdir %s 2>nul & cd "%s" && xcopy /e /f /y "%s" %s' % (
1733+
full_dst, _FixPath(base_dir), outer_dir, full_dst)
17221734
copies.append(([src], ['dummy_copies', dst], cmd,
1723-
'Copying %s to %s' % (src, dst)))
1735+
'Copying %s to %s' % (src, fixed_dst)))
17241736
else:
1737+
fix_dst = _FixPath(cpy['destination'])
17251738
cmd = 'mkdir "%s" 2>nul & set ERRORLEVEL=0 & copy /Y "%s" "%s"' % (
1726-
_FixPath(cpy['destination']), _FixPath(src), _FixPath(dst))
1727-
copies.append(([src], [dst], cmd, 'Copying %s to %s' % (src, dst)))
1739+
fix_dst, _FixPath(src), _FixPath(dst))
1740+
copies.append(([src], [dst], cmd, 'Copying %s to %s' % (src, fix_dst)))
17281741
return copies
17291742

17301743

@@ -2718,7 +2731,7 @@ def _GetMSBuildGlobalProperties(spec, version, guid, gyp_file_name):
27182731
properties[0].append(['WindowsTargetPlatformVersion',
27192732
str(msvs_windows_sdk_version)])
27202733
elif version.compatible_sdks:
2721-
raise GypError('%s requires any SDK of %o version, but non were found' %
2734+
raise GypError('%s requires any SDK of %s version, but none were found' %
27222735
(version.description, version.compatible_sdks))
27232736

27242737
if platform_name == 'ARM':

tools/gyp/pylib/gyp/generator/ninja.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1931,10 +1931,6 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params,
19311931
ld = os.path.join(build_to_root, value)
19321932
if key == 'LD.host':
19331933
ld_host = os.path.join(build_to_root, value)
1934-
if key == 'LDXX':
1935-
ldxx = os.path.join(build_to_root, value)
1936-
if key == 'LDXX.host':
1937-
ldxx_host = os.path.join(build_to_root, value)
19381934
if key == 'NM':
19391935
nm = os.path.join(build_to_root, value)
19401936
if key == 'NM.host':
@@ -2028,7 +2024,6 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params,
20282024
CommandWithWrapper('CXX.host', wrappers, cxx_host))
20292025
if flavor == 'win':
20302026
master_ninja.variable('ld_host', ld_host)
2031-
master_ninja.variable('ldxx_host', ldxx_host)
20322027
else:
20332028
master_ninja.variable('ld_host', CommandWithWrapper(
20342029
'LINK', wrappers, ld_host))
@@ -2153,13 +2148,13 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params,
21532148
restat=True,
21542149
command=mtime_preserving_solink_base % {'suffix': '@$link_file_list'},
21552150
rspfile='$link_file_list',
2156-
rspfile_content='-Wl,--start-group $in $solibs $libs -Wl,--end-group',
2151+
rspfile_content='-Wl,--start-group $in -Wl,--end-group $solibs $libs',
21572152
pool='link_pool')
21582153
master_ninja.rule(
21592154
'link',
21602155
description='LINK $out',
21612156
command=('$ld $ldflags -o $out '
2162-
'-Wl,--start-group $in $solibs $libs -Wl,--end-group'),
2157+
'-Wl,--start-group $in -Wl,--end-group $solibs $libs'),
21632158
pool='link_pool')
21642159
elif flavor == 'win':
21652160
master_ninja.rule(

tools/gyp/pylib/gyp/mac_tool.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,21 @@ def _CopyXIBFile(self, source, dest):
105105

106106
ibtool_section_re = re.compile(r'/\*.*\*/')
107107
ibtool_re = re.compile(r'.*note:.*is clipping its content')
108-
ibtoolout = subprocess.Popen(args, stdout=subprocess.PIPE)
108+
try:
109+
stdout = subprocess.check_output(args)
110+
except subprocess.CalledProcessError as e:
111+
print(e.output)
112+
raise
109113
current_section_header = None
110-
for line in ibtoolout.stdout:
114+
for line in stdout.splitlines():
111115
if ibtool_section_re.match(line):
112116
current_section_header = line
113117
elif not ibtool_re.match(line):
114118
if current_section_header:
115-
sys.stdout.write(current_section_header)
119+
print(current_section_header)
116120
current_section_header = None
117-
sys.stdout.write(line)
118-
return ibtoolout.returncode
121+
print(line)
122+
return 0
119123

120124
def _ConvertToBinary(self, dest):
121125
subprocess.check_call([

0 commit comments

Comments
 (0)