Skip to content

Commit

Permalink
build: Convert build/config/nacl/rules.gni to py3
Browse files Browse the repository at this point in the history
Bug: 1205627
Change-Id: If1dc022cf0d3e670fb6deb9c3a453bbc2e171166
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2909886
Commit-Queue: Nico Weber <thakis@chromium.org>
Auto-Submit: Nico Weber <thakis@chromium.org>
Reviewed-by: Sam Clegg <sbc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#886318}
  • Loading branch information
nico authored and Chromium LUCI CQ committed May 25, 2021
1 parent bf8038b commit 9b0ef8c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
4 changes: 1 addition & 3 deletions build/config/nacl/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# found in the LICENSE file.

import("//build/config/nacl/config.gni")
import("//build/config/python.gni")

# Generate a nmf file
#
Expand All @@ -20,8 +19,7 @@ template("generate_nmf") {
assert(defined(invoker.executables), "Must define executables")
assert(defined(invoker.nmf), "Must define nmf")

# TODO(crbug.com/1112471): Get this to run cleanly under Python 3.
python2_action(target_name) {
action(target_name) {
forward_variables_from(invoker,
[
"deps",
Expand Down
14 changes: 7 additions & 7 deletions native_client_sdk/src/tools/create_nmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def ParseElfHeader(path):
"""Wrap elf.ParseElfHeader to return raise this module's Error on failure."""
try:
return elf.ParseElfHeader(path)
except elf.Error, e:
except elf.Error as e:
raise Error(str(e))


Expand Down Expand Up @@ -248,14 +248,14 @@ def GetNeeded(self):
self.lib_path)
except get_shared_deps.NoObjdumpError:
raise Error('No objdump executable found (see --help for more info)')
except get_shared_deps.Error, e:
except get_shared_deps.Error as e:
raise Error(str(e))

self.needed = {}

# all_files is a dictionary mapping filename to architecture. self.needed
# should be a dictionary of filename to ArchFile.
for filename, arch in all_files.iteritems():
for filename, arch in all_files.items():
name = os.path.basename(filename)
self.needed[filename] = ArchFile(name=name, path=filename, arch=arch)

Expand Down Expand Up @@ -286,7 +286,7 @@ def _SetArchFileUrls(self):
main_dir = ''
arch_to_main_dir[arch] = main_dir

for arch_file in self.needed.itervalues():
for arch_file in self.needed.values():
prefix = ''
if DirectoryTreeContainsFile(self.nmf_root, arch_file.path):
# This file is already in the nmf_root tree, so it does not need to be
Expand Down Expand Up @@ -317,7 +317,7 @@ def StageDependencies(self, destination_dir):
destination_dir: The destination directory for staging the dependencies
"""
assert self.needed is not None
for arch_file in self.needed.itervalues():
for arch_file in self.needed.values():
source = arch_file.path
destination = os.path.join(destination_dir, arch_file.url)

Expand Down Expand Up @@ -377,7 +377,7 @@ def _GenerateManifest(self):
url=url))
for key, arch, url in self.extra_files]

manifest_items = needed.items() + extra_files_kv
manifest_items = list(needed.items()) + extra_files_kv

# Add dynamic loader to the program section.
for need, archinfo in manifest_items:
Expand Down Expand Up @@ -703,7 +703,7 @@ def main(args):
if __name__ == '__main__':
try:
rtn = main(sys.argv[1:])
except Error, e:
except Error as e:
sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
rtn = 1
except KeyboardInterrupt:
Expand Down
4 changes: 3 additions & 1 deletion native_client_sdk/src/tools/getos.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
Toolchain to invoke.
"""

from __future__ import print_function

import argparse
import os
import re
Expand Down Expand Up @@ -263,7 +265,7 @@ def main(args):
out = platform

if out:
print out
print(out)
return 0


Expand Down
2 changes: 1 addition & 1 deletion native_client_sdk/src/tools/lib/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def ParseElfHeader(path):
raise Error("error parsing elf header: %s" % path)
e_ident, _, e_machine = header[:3]

elf_magic = '\x7fELF'
elf_magic = b'\x7fELF'
if e_ident[:4] != elf_magic:
raise Error('Not a valid NaCl executable: %s' % path)

Expand Down
7 changes: 4 additions & 3 deletions native_client_sdk/src/tools/lib/get_shared_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def GetNeeded(main_files, objdump, lib_path):
def _GetNeededDynamic(main_files, objdump, lib_path):
examined = set()
all_files, unexamined = GleanFromObjdump(main_files, None, objdump, lib_path)
for arch in all_files.itervalues():
for arch in all_files.values():
if unexamined:
if arch == 'arm':
unexamined.add((LOADER_ARM, arch))
Expand All @@ -106,7 +106,7 @@ def _GetNeededDynamic(main_files, objdump, lib_path):

# Call GleanFromObjdump() for each architecture.
needed = set()
for arch, files in files_to_examine.iteritems():
for arch, files in files_to_examine.items():
new_files, new_needed = GleanFromObjdump(files, arch, objdump, lib_path)
all_files.update(new_files)
needed |= new_needed
Expand All @@ -117,7 +117,7 @@ def _GetNeededDynamic(main_files, objdump, lib_path):
# With the runnable-ld.so scheme we have today, the proper name of
# the dynamic linker should be excluded from the list of files.
ldso = [LD_NACL_MAP[arch] for arch in set(OBJDUMP_ARCH_MAP.values())]
for filename, arch in all_files.items():
for filename, arch in list(all_files.items()):
name = os.path.basename(filename)
if name in ldso:
del all_files[filename]
Expand Down Expand Up @@ -160,6 +160,7 @@ def GleanFromObjdump(files, arch, objdump, lib_path):
env = {'LANG': 'en_US.UTF-8'}
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, bufsize=-1,
universal_newlines=True,
env=env)

input_info = {}
Expand Down
2 changes: 1 addition & 1 deletion native_client_sdk/src/tools/oshelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def Zip(args):
zip_info.date_time = time.localtime(st.st_mtime)[0:6]
zip_info.compress_type = zip_stream.compression
zip_info.flag_bits = 0x00
zip_info.external_attr = (st[0] & 0xFFFF) << 16L
zip_info.external_attr = (st[0] & 0xFFFF) << 16
zip_info.CRC = 0
zip_info.compress_size = 0
zip_info.file_size = 0
Expand Down

0 comments on commit 9b0ef8c

Please sign in to comment.