Commit e296b1a4 authored by Dirk Pranke's avatar Dirk Pranke Committed by Commit Bot

Various small Python 3 build fixes for Mac, iOS.

This fixes various Python3 incompatibilities and updates the
plist files to the new Python3 APIs.

Bug: 1112471
Change-Id: Ie6239ab4454b39e7e65d02d3a2da4b3a1967a6d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522676
Commit-Queue: Dirk Pranke <dpranke@google.com>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829058}
parent 96979774
......@@ -301,10 +301,14 @@ def Main(argv):
# Read the plist into its parsed format. Convert the file to 'xml1' as
# plistlib only supports that format in Python 2.7.
with tempfile.NamedTemporaryFile() as temp_info_plist:
retcode = _ConvertPlist(options.plist_path, temp_info_plist.name, 'xml1')
if retcode != 0:
return retcode
plist = plistlib.readPlist(temp_info_plist.name)
if sys.version_info.major == 2:
retcode = _ConvertPlist(options.plist_path, temp_info_plist.name, 'xml1')
if retcode != 0:
return retcode
plist = plistlib.readPlist(temp_info_plist.name)
else:
with open(options.plist_path, 'rb') as f:
plist = plistlib.load(f)
# Convert overrides.
overrides = {}
......@@ -398,7 +402,11 @@ def Main(argv):
# Now that all keys have been mutated, rewrite the file.
with tempfile.NamedTemporaryFile() as temp_info_plist:
plistlib.writePlist(plist, temp_info_plist.name)
if sys.version_info.major == 2:
plistlib.writePlist(plist, temp_info_plist.name)
else:
with open(temp_info_plist.name, 'wb') as f:
plist = plistlib.dump(plist, f)
# Convert Info.plist to the format requested by the --format flag. Any
# format would work on Mac but iOS requires specific format.
......
......@@ -58,9 +58,13 @@ def LoadPlistFile(plist_path):
Returns:
The content of the property list file as a python object.
"""
return ReadPlistFromString(
subprocess.check_output(
['xcrun', 'plutil', '-convert', 'xml1', '-o', '-', plist_path]))
if sys.version_info.major == 2:
return plistlib.readPlistFromString(
subprocess.check_output(
['xcrun', 'plutil', '-convert', 'xml1', '-o', '-', plist_path]))
else:
with open(plist_path) as fp:
return plistlib.load(fp)
def CreateSymlink(value, location):
......@@ -262,7 +266,11 @@ class Entitlements(object):
self._data[key] = value
def WriteTo(self, target_path):
plistlib.writePlist(self._data, target_path)
with open(target_path, 'wb') as fp:
if sys.version_info.major == 2:
plistlib.writePlist(self._data, fp)
else:
plistlib.dump(self._data, fp)
def FindProvisioningProfile(bundle_identifier, required):
......@@ -317,9 +325,11 @@ def FindProvisioningProfile(bundle_identifier, required):
def CodeSignBundle(bundle_path, identity, extra_args):
process = subprocess.Popen(['xcrun', 'codesign', '--force', '--sign',
identity, '--timestamp=none'] + list(extra_args) + [bundle_path],
stderr=subprocess.PIPE)
process = subprocess.Popen(
['xcrun', 'codesign', '--force', '--sign', identity, '--timestamp=none'] +
list(extra_args) + [bundle_path],
stderr=subprocess.PIPE,
universal_newlines=True)
_, stderr = process.communicate()
if process.returncode:
sys.stderr.write(stderr)
......
......@@ -94,13 +94,17 @@ def Interpolate(value, substitutions):
def LoadPList(path):
"""Loads Plist at |path| and returns it as a dictionary."""
fd, name = tempfile.mkstemp()
try:
subprocess.check_call(['plutil', '-convert', 'xml1', '-o', name, path])
with os.fdopen(fd, 'rb') as f:
return plistlib.readPlist(f)
finally:
os.unlink(name)
if sys.version_info.major == 2:
fd, name = tempfile.mkstemp()
try:
subprocess.check_call(['plutil', '-convert', 'xml1', '-o', name, path])
with os.fdopen(fd, 'rb') as f:
return plistlib.readPlist(f)
finally:
os.unlink(name)
else:
with open(path, 'rb') as f:
return plistlib.load(f)
def SavePList(path, format, data):
......@@ -114,7 +118,10 @@ def SavePList(path, format, data):
if os.path.exists(path):
os.unlink(path)
with os.fdopen(fd, 'wb') as f:
plistlib.writePlist(data, f)
if sys.version_info.major == 2:
plistlib.writePlist(data, f)
else:
plistlib.dump(data, f)
subprocess.check_call(['plutil', '-convert', format, '-o', path, name])
finally:
os.unlink(name)
......
......@@ -121,8 +121,7 @@ source_set("updater_setup_sources") {
]
}
# TODO(crbug.com/1112471): Get this to run cleanly under Python 3.
python2_action("updater_install_script") {
action("updater_install_script") {
script = "embed_variables.py"
inputs = [
......@@ -142,8 +141,7 @@ python2_action("updater_install_script") {
]
}
# TODO(crbug.com/1112471): Get this to run cleanly under Python 3.
python2_action("browser_install_script") {
action("browser_install_script") {
script = "embed_variables.py"
inputs = [
......
......@@ -2,12 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import ConfigParser
import glob
import optparse
import os
import shutil
import subprocess
import sys
......@@ -28,7 +24,7 @@ def embed_version(input_file, output_file, version, product_full_name):
fin.close()
fout.close()
os.chmod(output_file, 0755)
os.chmod(output_file, 0o755)
def parse_options():
......
......@@ -13,6 +13,8 @@
# * assumes that there is only one relevant element with the
# IDS_ACCEPT_LANGUAGES attribute
from __future__ import print_function
import os
import re
import sys
......@@ -40,10 +42,10 @@ FOOTER = "};"
def main():
with open(sys.argv[1] + "/accept_languages_table.h", "w+") as f:
print >>f, HEADER
print(HEADER, file=f)
for (locale, accept_langs) in gen_accept_langs_table().items():
print >>f, LINE(locale, accept_langs)
print >>f, FOOTER
print(LINE(locale, accept_langs), file=f)
print(FOOTER, file=f)
if __name__ == "__main__":
main()
......@@ -12,10 +12,13 @@
# This way, we can reduce risk of symbol conflict when linking it into apps
# by exposing internal symbols, especially in third-party libraries.
from __future__ import print_function
import glob
import optparse
import os
import subprocess
import sys
# Mapping from GN's target_cpu attribute to ld's -arch parameter.
......@@ -59,12 +62,12 @@ def main():
assert not args
developer_dir = subprocess.check_output(
['xcode-select', '--print-path']).strip()
['xcode-select', '--print-path'], universal_newlines=True).strip()
xctoolchain_libs = glob.glob(developer_dir
+ '/Toolchains/XcodeDefault.xctoolchain/usr/lib'
+ '/clang/*/lib/darwin/*.ios.a')
print "Adding xctoolchain_libs: ", xctoolchain_libs
print("Adding xctoolchain_libs: ", xctoolchain_libs)
# ld -r concatenates multiple .o files and .a files into a single .o file,
# while "hiding" symbols not marked as visible.
......@@ -131,9 +134,9 @@ def main():
ret = os.system('xcrun nm -u "' + options.output_obj +
'" | grep ___cxa_pure_virtual')
if ret == 0:
print "ERROR: Found undefined libc++ symbols, " + \
"is libc++ indcluded in dependencies?"
exit(2)
print("ERROR: Found undefined libc++ symbols, "
"is libc++ included in dependencies?")
sys.exit(2)
if __name__ == "__main__":
......
......@@ -4,8 +4,7 @@
import("//build/config/python.gni")
# TODO(crbug.com/1112471): Get this to run cleanly under Python 3.
python2_action_foreach("package_sb_files") {
action_foreach("package_sb_files") {
script = "package_sb_file.py"
sources = [
"audio.sb",
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import print_function
import os
import sys
......@@ -37,14 +39,14 @@ def pack_file(argv):
output_h_file = output_directory + '/' + input_basename + '.h'
output_cc_file = output_directory + '/' + input_basename + '.cc'
try:
with open(input_filename, 'rb') as infile:
with open(output_h_file, 'wb') as outfile:
with open(input_filename, 'r') as infile:
with open(output_h_file, 'w') as outfile:
outfile.write(header)
outfile.write(h_include)
outfile.write(namespace)
outfile.write(h_definition % module_name)
outfile.write(namespace_end)
with open(output_cc_file, 'wb') as outfile:
with open(output_cc_file, 'w') as outfile:
outfile.write(header)
outfile.write(cc_include % module_name)
outfile.write(namespace)
......@@ -56,7 +58,7 @@ def pack_file(argv):
outfile.write(cc_definition_end)
outfile.write(namespace_end)
except IOError:
print >> sys.stderr, 'Failed to process %s' % input_filename
print('Failed to process %s' % input_filename, file=sys.stderr)
return 1
return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment