Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iteritems() -> items() in compile_commands_json.py #1947

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gyp/pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import gyp
import glob

PY3 = bytes != str


class VisualStudioVersion(object):
"""Information regarding a version of Visual Studio."""
Expand Down Expand Up @@ -132,6 +134,8 @@ def _RegistryQueryBase(sysdir, key, value):
# Obtain the stdout from reg.exe, reading to the end so p.returncode is valid
# Note that the error text may be in [1] in some cases
text = p.communicate()[0]
if PY3:
text = text.decode('utf-8')
# Check return code from reg.exe; officially 0==success and 1==error
if p.returncode:
return None
Expand Down Expand Up @@ -334,6 +338,8 @@ def _ConvertToCygpath(path):
if sys.platform == 'cygwin':
p = subprocess.Popen(['cygpath', path], stdout=subprocess.PIPE)
path = p.communicate()[0].strip()
if PY3:
path = path.decode('utf-8')
return path


Expand Down
6 changes: 3 additions & 3 deletions gyp/pylib/gyp/generator/compile_commands_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def CalculateVariables(default_variables, params):

def AddCommandsForTarget(cwd, target, params, per_config_commands):
output_dir = params['generator_flags']['output_dir']
for configuration_name, configuration in target['configurations'].iteritems():
for configuration_name, configuration in target['configurations'].items():
builddir_name = os.path.join(output_dir, configuration_name)

if IsMac(params):
Expand Down Expand Up @@ -92,7 +92,7 @@ def resolve(filename):

def GenerateOutput(target_list, target_dicts, data, params):
per_config_commands = {}
for qualified_target, target in target_dicts.iteritems():
for qualified_target, target in target_dicts.items():
build_file, target_name, toolset = (
gyp.common.ParseQualifiedTarget(qualified_target))
if IsMac(params):
Expand All @@ -102,7 +102,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
AddCommandsForTarget(cwd, target, params, per_config_commands)

output_dir = params['generator_flags']['output_dir']
for configuration_name, commands in per_config_commands.iteritems():
for configuration_name, commands in per_config_commands.items():
filename = os.path.join(output_dir,
configuration_name,
'compile_commands.json')
Expand Down
6 changes: 6 additions & 0 deletions gyp/pylib/gyp/generator/eclipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import shlex
import xml.etree.cElementTree as ET

PY3 = bytes != str

generator_wants_static_library_dependencies_adjusted = False

generator_default_variables = {
Expand Down Expand Up @@ -97,6 +99,8 @@ def GetAllIncludeDirectories(target_list, target_dicts,
proc = subprocess.Popen(args=command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = proc.communicate()[1]
if PY3:
output = output.decode('utf-8')
# Extract the list of include dirs from the output, which has this format:
# ...
# #include "..." search starts here:
Expand Down Expand Up @@ -234,6 +238,8 @@ def GetAllDefines(target_list, target_dicts, data, config_name, params,
cpp_proc = subprocess.Popen(args=command, cwd='.',
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
cpp_output = cpp_proc.communicate()[0]
if PY3:
cpp_output = cpp_output.decode('utf-8')
cpp_lines = cpp_output.split('\n')
for cpp_line in cpp_lines:
if not cpp_line.strip():
Expand Down
4 changes: 4 additions & 0 deletions gyp/pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from gyp.common import GypError
from gyp.common import OrderedSet

PY3 = bytes != str

# TODO: Remove once bots are on 2.7, http://crbug.com/241769
def _import_OrderedDict():
import collections
Expand Down Expand Up @@ -124,6 +126,8 @@ def _GetDomainAndUserName():
call = subprocess.Popen(['net', 'config', 'Workstation'],
stdout=subprocess.PIPE)
config = call.communicate()[0]
if PY3:
config = config.decode('utf-8')
username_re = re.compile(r'^User name\s+(\S+)', re.MULTILINE)
username_match = username_re.search(config)
if username_match:
Expand Down
4 changes: 4 additions & 0 deletions gyp/pylib/gyp/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from gyp.common import GypError
from gyp.common import OrderedSet

PY3 = bytes != str

# A list of types that are treated as linkable.
linkable_types = [
Expand Down Expand Up @@ -909,6 +910,9 @@ def ExpandVariables(input, phase, variables, build_file):
(e, contents, build_file))

p_stdout, p_stderr = p.communicate('')
if PY3:
p_stdout = p_stdout.decode('utf-8')
p_stderr = p_stderr.decode('utf-8')

if p.wait() != 0 or p_stderr:
sys.stderr.write(p_stderr)
Expand Down
4 changes: 4 additions & 0 deletions gyp/pylib/gyp/mac_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import sys
import tempfile

PY3 = bytes != str


def main(args):
executor = MacTool()
Expand Down Expand Up @@ -243,6 +245,8 @@ def ExecFilterLibtool(self, *cmd_list):
env['ZERO_AR_DATE'] = '1'
libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env)
_, err = libtoolout.communicate()
if PY3:
err = err.decode('utf-8')
for line in err.splitlines():
if not libtool_re.match(line) and not libtool_re5.match(line):
print(line, file=sys.stderr)
Expand Down
10 changes: 9 additions & 1 deletion gyp/pylib/gyp/msvs_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import gyp.MSVSUtil
import gyp.MSVSVersion

PY3 = bytes != str

windows_quoter_regex = re.compile(r'(\\*)"')

Expand Down Expand Up @@ -126,7 +127,10 @@ def _FindDirectXInstallation():
# Setup params to pass to and attempt to launch reg.exe.
cmd = ['reg.exe', 'query', r'HKLM\Software\Microsoft\DirectX', '/s']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in p.communicate()[0].splitlines():
stdout = p.communicate()[0]
if PY3:
stdout = stdout.decode('utf-8')
for line in stdout.splitlines():
if 'InstallPath' in line:
dxsdk_dir = line.split(' ')[3] + "\\"

Expand Down Expand Up @@ -1038,6 +1042,8 @@ def GenerateEnvironmentFiles(toplevel_build_dir, generator_flags,
popen = subprocess.Popen(
args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
variables, _ = popen.communicate()
if PY3:
variables = variables.decode('utf-8')
env = _ExtractImportantEnvironment(variables)

# Inject system includes from gyp files into INCLUDE.
Expand All @@ -1057,6 +1063,8 @@ def GenerateEnvironmentFiles(toplevel_build_dir, generator_flags,
'for', '%i', 'in', '(cl.exe)', 'do', '@echo', 'LOC:%~$PATH:i'))
popen = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE)
output, _ = popen.communicate()
if PY3:
output = output.decode('utf-8')
cl_paths[arch] = _ExtractCLPath(output)
return cl_paths

Expand Down
11 changes: 11 additions & 0 deletions gyp/pylib/gyp/win_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import sys

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
PY3 = bytes != str

# A regex matching an argument corresponding to the output filename passed to
# link.exe.
Expand Down Expand Up @@ -124,6 +125,8 @@ def ExecLinkWrapper(self, arch, use_separate_mspdbsrv, *args):
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out, _ = link.communicate()
if PY3:
out = out.decode('utf-8')
for line in out.splitlines():
if (not line.startswith(' Creating library ') and
not line.startswith('Generating code') and
Expand Down Expand Up @@ -215,6 +218,8 @@ def ExecManifestWrapper(self, arch, *args):
popen = subprocess.Popen(args, shell=True, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
if PY3:
out = out.decode('utf-8')
for line in out.splitlines():
if line and 'manifest authoring warning 81010002' not in line:
print(line)
Expand Down Expand Up @@ -247,6 +252,8 @@ def ExecMidlWrapper(self, arch, outdir, tlb, h, dlldata, iid, proxy, idl,
popen = subprocess.Popen(args, shell=True, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
if PY3:
out = out.decode('utf-8')
# Filter junk out of stdout, and write filtered versions. Output we want
# to filter is pairs of lines that look like this:
# Processing C:\Program Files (x86)\Microsoft SDKs\...\include\objidl.idl
Expand All @@ -266,6 +273,8 @@ def ExecAsmWrapper(self, arch, *args):
popen = subprocess.Popen(args, shell=True, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
if PY3:
out = out.decode('utf-8')
for line in out.splitlines():
if (not line.startswith('Copyright (C) Microsoft Corporation') and
not line.startswith('Microsoft (R) Macro Assembler') and
Expand All @@ -281,6 +290,8 @@ def ExecRcWrapper(self, arch, *args):
popen = subprocess.Popen(args, shell=True, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
if PY3:
out = out.decode('utf-8')
for line in out.splitlines():
if (not line.startswith('Microsoft (R) Windows (R) Resource Compiler') and
not line.startswith('Copyright (C) Microsoft Corporation') and
Expand Down
41 changes: 20 additions & 21 deletions gyp/pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@ def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
# These flags reflect the compilation options used by xcode to compile
# extensions.
ldflags.append('-lpkstart')
if XcodeVersion() < '0900':
xcode_version, _ = XcodeVersion()
if xcode_version < '0900':
ldflags.append(sdk_root +
'/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit')
ldflags.append('-fapplication-extension')
Expand Down Expand Up @@ -1088,15 +1089,15 @@ def GetExtraPlistItems(self, configname=None):
cache = {}
cache['BuildMachineOSBuild'] = self._BuildMachineOSBuild()

xcode, xcode_build = XcodeVersion()
cache['DTXcode'] = xcode
xcode_version, xcode_build = XcodeVersion()
cache['DTXcode'] = xcode_version
cache['DTXcodeBuild'] = xcode_build

sdk_root = self._SdkRoot(configname)
if not sdk_root:
sdk_root = self._DefaultSdkRoot()
cache['DTSDKName'] = sdk_root
if xcode >= '0430':
if xcode_version >= '0430':
cache['DTSDKBuild'] = self._GetSdkVersionInfoItem(
sdk_root, 'ProductBuildVersion')
else:
Expand Down Expand Up @@ -1126,7 +1127,7 @@ def _DefaultSdkRoot(self):
project, then the environment variable was empty. Starting with this
version, Xcode uses the name of the newest SDK installed.
"""
xcode_version, xcode_build = XcodeVersion()
xcode_version, _ = XcodeVersion()
if xcode_version < '0500':
return ''
default_sdk_path = self._XcodeSdkPath('')
Expand Down Expand Up @@ -1263,10 +1264,12 @@ def XcodeVersion():
# Xcode 3.2.6
# Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
# BuildVersion: 10M2518
# Convert that to '0463', '4H1503'.
# Convert that to ('0463', '4H1503') or ('0326', '10M2518').
global XCODE_VERSION_CACHE
if XCODE_VERSION_CACHE:
return XCODE_VERSION_CACHE
version = ""
build = ""
try:
version_list = GetStdoutQuiet(['xcodebuild', '-version']).splitlines()
# In some circumstances xcodebuild exits 0 but doesn't return
Expand All @@ -1276,21 +1279,16 @@ def XcodeVersion():
# checking that version.
if len(version_list) < 2:
raise GypError("xcodebuild returned unexpected results")
except GypError:
version = CLTVersion()
if version:
version = ".".join(version.split(".")[:3])
else:
version = version_list[0].split()[-1] # Last word on first line
build = version_list[-1].split()[-1] # Last word on last line
except GypError: # Xcode not installed so look for XCode Command Line Tools
version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
if not version:
raise GypError("No Xcode or CLT version detected!")
# The CLT has no build information, so we return an empty string.
version_list = [version, '']
version = version_list[0]
build = version_list[-1]
# Be careful to convert "4.2" to "0420" and "10.0" to "1000":
version = format(''.join((version.split()[-1].split('.') + ['0', '0'])[:3]),
'>04s')
if build:
build = build.split()[-1]
# Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100":
version = version.split(".")[:3] # Just major, minor, micro
version[0] = version[0].zfill(2) # Add a leading zero if major is one digit
version = ("".join(version) + "00")[:4] # Limit to exactly four characters
XCODE_VERSION_CACHE = (version, build)
return XCODE_VERSION_CACHE

Expand Down Expand Up @@ -1524,7 +1522,8 @@ def _GetXcodeEnv(xcode_settings, built_products_dir, srcroot, configuration,
install_name_base = xcode_settings.GetInstallNameBase()
if install_name_base:
env['DYLIB_INSTALL_NAME_BASE'] = install_name_base
if XcodeVersion() >= '0500' and not env.get('SDKROOT'):
xcode_version, _ = XcodeVersion()
if xcode_version >= '0500' and not env.get('SDKROOT'):
sdk_root = xcode_settings._SdkRoot(configuration)
if not sdk_root:
sdk_root = xcode_settings._XcodeSdkPath('')
Expand Down
2 changes: 1 addition & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function install (fs, gyp, argv, callback) {

req.on('error', done)
req.on('response', function (res) {
if (res.statusCode === 404) {
if (res.statusCode === 403 || res.statusCode === 404) {
if (arch === 'arm64') {
// Arm64 is a newer platform on Windows and not all node distributions provide it.
log.verbose(`${name} was not found in ${libUrl}`)
Expand Down