gyp: finish decode stdout on Python 3 · nodejs/node-gyp@9f4f0fa · GitHub
Skip to content

Commit 9f4f0fa

Browse files
cclaussrvagg
authored andcommitted
gyp: finish decode stdout on Python 3
PR-URL: #1937 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
1 parent 7cf5079 commit 9f4f0fa

7 files changed

Lines changed: 44 additions & 1 deletion

File tree

gyp/pylib/gyp/MSVSVersion.py

Lines changed: 6 additions & 0 deletions

gyp/pylib/gyp/generator/eclipse.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import shlex
2727
import xml.etree.cElementTree as ET
2828

29+
PY3 = bytes != str
30+
2931
generator_wants_static_library_dependencies_adjusted = False
3032

3133
generator_default_variables = {
@@ -97,6 +99,8 @@ def GetAllIncludeDirectories(target_list, target_dicts,
9799
proc = subprocess.Popen(args=command, stdin=subprocess.PIPE,
98100
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
99101
output = proc.communicate()[1]
102+
if PY3:
103+
output = output.decode('utf-8')
100104
# Extract the list of include dirs from the output, which has this format:
101105
# ...
102106
# #include "..." search starts here:
@@ -234,6 +238,8 @@ def GetAllDefines(target_list, target_dicts, data, config_name, params,
234238
cpp_proc = subprocess.Popen(args=command, cwd='.',
235239
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
236240
cpp_output = cpp_proc.communicate()[0]
241+
if PY3:
242+
cpp_output = cpp_output.decode('utf-8')
237243
cpp_lines = cpp_output.split('\n')
238244
for cpp_line in cpp_lines:
239245
if not cpp_line.strip():

gyp/pylib/gyp/generator/msvs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
from gyp.common import GypError
2626
from gyp.common import OrderedSet
2727

28+
PY3 = bytes != str
29+
2830
# TODO: Remove once bots are on 2.7, http://crbug.com/241769
2931
def _import_OrderedDict():
3032
import collections
@@ -124,6 +126,8 @@ def _GetDomainAndUserName():
124126
call = subprocess.Popen(['net', 'config', 'Workstation'],
125127
stdout=subprocess.PIPE)
126128
config = call.communicate()[0]
129+
if PY3:
130+
config = config.decode('utf-8')
127131
username_re = re.compile(r'^User name\s+(\S+)', re.MULTILINE)
128132
username_match = username_re.search(config)
129133
if username_match:

gyp/pylib/gyp/input.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from gyp.common import GypError
2323
from gyp.common import OrderedSet
2424

25+
PY3 = bytes != str
2526

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

911912
p_stdout, p_stderr = p.communicate('')
913+
if PY3:
914+
p_stdout = p_stdout.decode('utf-8')
915+
p_stderr = p_stderr.decode('utf-8')
912916

913917
if p.wait() != 0 or p_stderr:
914918
sys.stderr.write(p_stderr)

gyp/pylib/gyp/mac_tool.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import sys
2424
import tempfile
2525

26+
PY3 = bytes != str
27+
2628

2729
def main(args):
2830
executor = MacTool()
@@ -243,6 +245,8 @@ def ExecFilterLibtool(self, *cmd_list):
243245
env['ZERO_AR_DATE'] = '1'
244246
libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env)
245247
_, err = libtoolout.communicate()
248+
if PY3:
249+
err = err.decode('utf-8')
246250
for line in err.splitlines():
247251
if not libtool_re.match(line) and not libtool_re5.match(line):
248252
print(line, file=sys.stderr)

gyp/pylib/gyp/msvs_emulation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import gyp.MSVSUtil
1717
import gyp.MSVSVersion
1818

19+
PY3 = bytes != str
1920

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

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

@@ -1038,6 +1042,8 @@ def GenerateEnvironmentFiles(toplevel_build_dir, generator_flags,
10381042
popen = subprocess.Popen(
10391043
args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
10401044
variables, _ = popen.communicate()
1045+
if PY3:
1046+
variables = variables.decode('utf-8')
10411047
env = _ExtractImportantEnvironment(variables)
10421048

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

gyp/pylib/gyp/win_tool.py

Lines changed: 11 additions & 0 deletions

0 commit comments

Comments
 (0)