Skip to content

Commit

Permalink
Fixes needed for Python3 on Win32.
Browse files Browse the repository at this point in the history
This CL contains the remaining fixes needed for the tests to
pass when running under Python 3.7 on Win10. Mostly these
are just changes to convert the output of subprocesses to
strings, but there are a few other minor compatibility fixes
as well.

With this CL, Python 3 should work everywhere we support it.
Python 2 continues to work as well.

Bug: gyp:36
Change-Id: Ie696a1845fb2dba4d86929be886becc5d300ef7a
Reviewed-on: https://chromium-review.googlesource.com/c/1365010
Reviewed-by: Mark Mentovai <[email protected]>
  • Loading branch information
dpranke committed Dec 8, 2018
1 parent 732bde6 commit e22714e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
6 changes: 4 additions & 2 deletions test/generator-output/gyptest-symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

import TestGyp
import os
import sys

test = TestGyp.TestGyp()
if not hasattr(os, 'symlink'):
test.skip_test('Missing os.symlink -- skipping test.\n')
if not hasattr(os, 'symlink') or sys.platform == 'win32':
# Python3 on windows has symlink but it doesn't work reliably.
test.skip_test('Missing or bad os.symlink -- skipping test.\n')

test.writable(test.workpath('src'), False)

Expand Down
13 changes: 8 additions & 5 deletions test/lib/TestGyp.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ def GetDefaultKeychainPath():
# Format is:
# $ security default-keychain
# "/Some/Path/To/default.keychain"
path = subprocess.check_output(['security', 'default-keychain']).strip()
path = subprocess.check_output(['security', 'default-keychain']).decode(
'utf-8', 'ignore').strip()
return path[1:-1]

def FindMSBuildInstallation(msvs_version = 'auto'):
Expand Down Expand Up @@ -743,13 +744,15 @@ def FindVisualStudioInstallation():
args1 = ['reg', 'query',
'HKLM\Software\Microsoft\VisualStudio\SxS\VS7',
'/v', '15.0', '/reg:32']
build_tool = subprocess.check_output(args1)\
.strip().split('\r\n').pop().split(' ').pop()
build_tool = subprocess.check_output(args1).decode(
'utf-8', 'ignore').strip().split(b'\r\n').pop().split(b' ').pop()
build_tool = build_tool.decode('utf-8')
if build_tool:
args2 = ['cmd.exe', '/d', '/c',
'cd', '/d', build_tool,
'&', 'dir', '/b', '/s', 'msbuild.exe']
msbuild_exes = subprocess.check_output(args2).strip().split('\r\n')
msbuild_exes = subprocess.check_output(args2).strip().split(b'\r\n')
msbuild_exes = [m.decode('utf-8') for m in msbuild_exes]
if len(msbuild_exes):
msbuild_Path = os.path.join(build_tool, msbuild_exes[0])
if os.path.exists(msbuild_Path):
Expand Down Expand Up @@ -819,7 +822,7 @@ def run_dumpbin(self, *dumpbin_args):
arguments = [cmd, '/c', self.vsvars_path, '&&', 'dumpbin']
arguments.extend(dumpbin_args)
proc = subprocess.Popen(arguments, stdout=subprocess.PIPE)
output = proc.communicate()[0]
output = proc.communicate()[0].decode('utf-8', 'ignore')
assert not proc.returncode
return output

Expand Down
2 changes: 1 addition & 1 deletion test/lib/TestWin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _QueryBase(self, sysdir, key, value):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Get 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]
text = p.communicate()[0].decode('utf-8', 'ignore')
# Check return code from reg.exe; officially 0==success and 1==error
if p.returncode:
return None
Expand Down
2 changes: 1 addition & 1 deletion test/relative/gyptest-default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Run from down in foo.
test.run_gyp('a.gyp', chdir='foo/a')
sln = test.workpath('foo/a/a.sln')
sln_data = open(sln, 'rb').read()
sln_data = open(sln, 'rb').read().decode('utf-8', 'ignore')
vcproj = sln_data.count('b.vcproj')
vcxproj = sln_data.count('b.vcxproj')
if (vcproj, vcxproj) not in [(1, 0), (0, 1)]:
Expand Down
3 changes: 2 additions & 1 deletion test/win/gyptest-link-embed-manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def extract_manifest(path, resource_name):
Returns None is there is no such manifest."""
with LoadLibrary(path) as handle:
try:
return win32api.LoadResource(handle, RT_MANIFEST, resource_name)
return win32api.LoadResource(
handle, RT_MANIFEST, resource_name).decode('utf-8', 'ignore')
except pywintypes.error as error:
if error.args[0] == winerror.ERROR_RESOURCE_DATA_NOT_FOUND:
return None
Expand Down
17 changes: 13 additions & 4 deletions test/win/gyptest-link-enable-uac.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ def extract_manifest(path, resource_name):
execution_level = manifest.getElementsByTagName('requestedExecutionLevel')
test.fail_test(len(execution_level) != 1)
execution_level = execution_level[0].attributes

def _has_key(node, key):
# 'in' doesn't work with the NamedNodeMap interface in Python2,
# but 'has_key' was removed from it in Python3, so we need to
# shim things :(.
if hasattr(node, 'has_key'):
return node.has_key(key)
return key in node

test.fail_test(not (
execution_level.has_key('level') and
execution_level.has_key('uiAccess') and
_has_key(execution_level, 'level') and
_has_key(execution_level, 'uiAccess') and
execution_level['level'].nodeValue == 'asInvoker' and
execution_level['uiAccess'].nodeValue == 'false'))

Expand All @@ -87,8 +96,8 @@ def extract_manifest(path, resource_name):
test.fail_test(len(execution_level) != 1)
execution_level = execution_level[0].attributes
test.fail_test(not (
execution_level.has_key('level') and
execution_level.has_key('uiAccess') and
_has_key(execution_level, 'level') and
_has_key(execution_level, 'uiAccess') and
execution_level['level'].nodeValue == 'requireAdministrator' and
execution_level['uiAccess'].nodeValue == 'true'))

Expand Down
3 changes: 2 additions & 1 deletion test/win/gyptest-link-update-manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def extract_manifest(path, resource_name):
Returns None is there is no such manifest."""
with LoadLibrary(path) as handle:
try:
return win32api.LoadResource(handle, RT_MANIFEST, resource_name)
return win32api.LoadResource(
handle, RT_MANIFEST, resource_name).decode('utf-8', 'ignore')
except pywintypes.error as error:
if error.args[0] == winerror.ERROR_RESOURCE_DATA_NOT_FOUND:
return None
Expand Down

0 comments on commit e22714e

Please sign in to comment.