diff options
author | perl <perl@immunant.com> | 2021-08-17 19:37:20 -0700 |
---|---|---|
committer | perl <perl@immunant.com> | 2021-09-02 01:53:19 -0700 |
commit | 998d9889469c93c09d82c21fd63d4140ceecf1dc (patch) | |
tree | 0342cc447ddc5dfbac2f890c39923ad98b1bac81 | |
parent | e6121c2c78a1a32d1c2241b05d7514256f05916b (diff) | |
download | aosp-998d9889469c93c09d82c21fd63d4140ceecf1dc.tar.gz |
scripts: Initial Python3 support
Bug: 197031257
Change-Id: I9086beaefcff706fdfee684e4300c201f4b0ebd9
-rwxr-xr-x | scripts/build.py | 18 | ||||
-rwxr-xr-x | scripts/run_tests.py | 12 | ||||
-rwxr-xr-x | scripts/trusty_build_config.py | 54 |
3 files changed, 43 insertions, 41 deletions
diff --git a/scripts/build.py b/scripts/build.py index cd36193..bd8734b 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 # # Copyright (C) 2018 The Android Open Source Project # @@ -70,7 +70,7 @@ def copy_file(src, dest, optional=False): """ if not os.path.exists(src) and optional: return - print "Copy:", repr(src), "->", repr(dest) + print("Copy:", repr(src), "->", repr(dest)) shutil.copy(src, dest) @@ -109,7 +109,7 @@ def build(args): if args.buildid is None: args.buildid = get_new_build_id(args.build_root) - print "BuildID", args.buildid + print("BuildID", args.buildid) # build projects failed = [] @@ -124,14 +124,14 @@ def build(args): cmd = "source %s && (%s)" % (os.path.join(script_dir, "envsetup.sh"), cmd) status = subprocess.call(cmd, shell=True, executable="/bin/bash") - print "cmd: '" + cmd + "' returned", status + print("cmd: '" + cmd + "' returned", status) if status: failed.append(project) if failed: - print - print "some projects have failed to build:" - print str(failed) + print() + print("some projects have failed to build:") + print(str(failed)) exit(1) def archive(build_config, args): @@ -277,10 +277,10 @@ def main(default_config=None): built_projects) args.project = projects - print "Projects", str(projects) + print("Projects", str(projects)) if args.skip_build: - print "Skip build for", args.project + print("Skip build for", args.project) else: build(args) archive(build_config, args) diff --git a/scripts/run_tests.py b/scripts/run_tests.py index 7e214f4..a67e504 100755 --- a/scripts/run_tests.py +++ b/scripts/run_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 # # Copyright (C) 2018 The Android Open Source Project # @@ -127,15 +127,15 @@ def run_tests(build_config, root, project, run_disabled_tests=False, test_passed = [] def run_test(name, cmd): - print - print "Running", name, "on", project - print "Command line:", " ".join([s.replace(" ", "\\ ") for s in cmd]) + print() + print("Running", name, "on", project) + print("Command line:", " ".join([s.replace(" ", "\\ ") for s in cmd])) sys.stdout.flush() test_start_time = time.time() status = subprocess.call(cmd) test_run_time = time.time() - test_start_time - print "{:s} returned {:d} after {:.3f} seconds".format( - name, status, test_run_time) + print("{:s} returned {:d} after {:.3f} seconds".format( + name, status, test_run_time)) test_results.add_result(name, status == 0) (test_failed if status else test_passed).append(name) diff --git a/scripts/trusty_build_config.py b/scripts/trusty_build_config.py index 510ff89..72480e0 100755 --- a/scripts/trusty_build_config.py +++ b/scripts/trusty_build_config.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 # # Copyright (C) 2018 The Android Open Source Project # @@ -133,11 +133,11 @@ class TrustyBuildConfig(object): """Main parser function called constructor or recursively by itself.""" if optional and not os.path.exists(path): if self.debug: - print "Skipping optional config file:", path + print("Skipping optional config file:", path) return if self.debug: - print "Reading config file:", path + print("Reading config file:", path) config_dir = os.path.dirname(path) @@ -156,7 +156,7 @@ class TrustyBuildConfig(object): def include(path, optional=False): """Process include statement in config file.""" if self.debug: - print "include", path, "optional", optional + print("include", path, "optional", optional) if path.startswith("."): path = os.path.join(config_dir, path) return self.read_config_file(path=path, optional=optional) @@ -165,7 +165,7 @@ class TrustyBuildConfig(object): """Process build statement in config file.""" for project_name in projects: if self.debug: - print "build", project_name, "enabled", enabled + print("build", project_name, "enabled", enabled) project = self.get_project(project_name) project.build = bool(enabled) if dist: @@ -180,7 +180,7 @@ class TrustyBuildConfig(object): for project_dep_name in needs: project_dep = self.get_project(project_dep_name) if self.debug: - print "build", project_name, "needs", project_dep_name + print("build", project_name, "needs", project_dep_name) project.also_build[project_dep_name] = project_dep def archive(src, dest=None, optional=False): @@ -190,9 +190,9 @@ class TrustyBuildConfig(object): """Process testmap statement in config file.""" for project_name in projects: if self.debug: - print "testmap", project_name, "build", build + print("testmap", project_name, "build", build) for test in tests: - print test + print(test) project = self.get_project(project_name) project.tests += flatten_list(tests) @@ -337,33 +337,33 @@ def list_projects(args): """ config = TrustyBuildConfig(config_file=args.file, debug=args.debug) for project in sorted(config.get_projects(**dict(args.filter))): - print project + print(project) def list_config(args): """Read config file and print all project and tests.""" config = TrustyBuildConfig(config_file=args.file, debug=args.debug) - print "Projects:" + print("Projects:") for project_name, project in sorted(config.projects.items()): - print " " + project_name + ":" - print " Build:", project.build - print " Tests:" + print(" " + project_name + ":") + print(" Build:", project.build) + print(" Tests:") for test in project.tests: - print " " + test.name + ":" - print " " + str(test.command) + print(" " + test.name + ":") + print(" " + str(test.command)) for build in [True, False]: - print - print "Build:" if build else "Don't build:" + print() + print("Build:" if build else "Don't build:") for tested in [True, False]: projects = config.get_projects(build=build, have_tests=tested) for project in sorted(projects): - print " " + project + ":" + print(" " + project + ":") project_config = config.get_project(project) for test in project_config.tests: - print " " + test.name + print(" " + test.name) if projects and not tested: - print " No tests" + print(" No tests") def any_test_name(regex, tests): @@ -427,11 +427,11 @@ def test_config(args): projects = config.get_projects(build=build, have_tests=tested) projects_build[build][tested] = projects if args.debug: - print "Build", build, "tested", tested, "count", len(projects) + print("Build", build, "tested", tested, "count", len(projects)) assert projects for project in projects: if args.debug: - print "-", project + print("-", project) m = project_regex.match(project) assert m if build is not None: @@ -452,12 +452,12 @@ def test_config(args): sorted(projects_build[True][tested] + projects_build[False][tested])) - print "get_projects test passed" + print("get_projects test passed") for project_name in config.get_projects(): project = config.get_project(project_name) if args.debug: - print project_name, project + print(project_name, project) m = project_regex.match(project_name) assert m kind = m.group(2) @@ -482,12 +482,12 @@ def test_config(args): unit_m = re.match(r"boot-test:self_test.*\.(\d+)", test.name) if args.debug: - print project, i, test.name + print(project, i, test.name) m = host_m or unit_m assert m assert m.group(1) == str(i + 1) - print "get_tests test passed" + print("get_tests test passed") def main(): @@ -497,6 +497,8 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", action="store_true") parser.add_argument("--file") + # work around for https://bugs.python.org/issue16308 + parser.set_defaults(func=lambda args: parser.print_help()) subparsers = parser.add_subparsers() parser_projects = subparsers.add_parser("projects", |