From 08352445c89c4e99fe396868b918c9871e398cdf Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Fri, 20 Aug 2021 11:39:48 -0700 Subject: [PATCH 1/2] Allow passing globs to update_crate_tests.py. This makes it easier to run it on multiple directories. Test: Call with various globs. Change-Id: I0564369e4e8b9d62482fb2162a16d0e588f94e57 --- scripts/update_crate_tests.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/update_crate_tests.py b/scripts/update_crate_tests.py index 7e13f624e..c74a37a55 100755 --- a/scripts/update_crate_tests.py +++ b/scripts/update_crate_tests.py @@ -27,11 +27,14 @@ argument is provided, it assumes the crate is the current directory. This script is automatically called by external_updater. """ +import argparse +import glob import json import os import platform import subprocess import sys +from pathlib import Path # Some tests requires specific options. Consider fixing the upstream crate # before updating this dictionary. @@ -245,11 +248,23 @@ class TestMapping(object): print("TEST_MAPPING successfully updated for %s!" % self.package.dir_rel) +def parse_args(): + parser = argparse.ArgumentParser('update_crate_tests') + parser.add_argument( + 'paths', + nargs='*', + help='Absolute or relative paths of the projects as globs.') + return parser.parse_args() + + def main(): - if len(sys.argv) > 1: - paths = sys.argv[1:] - else: - paths = [os.getcwd()] + args = parse_args() + paths = args.paths if len(args.paths) > 0 else [os.getcwd()] + # We want to use glob to get all the paths, so we first convert to absolute. + paths = [Path(path).resolve() for path in paths] + paths = sorted([path for abs_path in paths + for path in glob.glob(str(abs_path))]) + env = Env() bazel = Bazel(env) for path in paths: From 4a2a3a8211cc645b088e74dab171b5b4d01eb779 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Fri, 20 Aug 2021 12:26:37 -0700 Subject: [PATCH 2/2] Let the test mapping updater make commits and upload changes. This will make it easier to run it on many crates and upload all of the changes. It puts the uploaded CLs in a topic to save resources. If the script does not change a TEST_MAPPING, it does not upload anything. Test: Run on a subset of crates. Change-Id: I47b4756d968c54d7d810c8a19a8a7419aebc6e15 --- scripts/update_crate_tests.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/scripts/update_crate_tests.py b/scripts/update_crate_tests.py index c74a37a55..1f04c1399 100755 --- a/scripts/update_crate_tests.py +++ b/scripts/update_crate_tests.py @@ -34,6 +34,7 @@ import os import platform import subprocess import sys +from datetime import datetime from pathlib import Path # Some tests requires specific options. Consider fixing the upstream crate @@ -250,10 +251,15 @@ class TestMapping(object): def parse_args(): parser = argparse.ArgumentParser('update_crate_tests') - parser.add_argument( - 'paths', - nargs='*', - help='Absolute or relative paths of the projects as globs.') + parser.add_argument('paths', + nargs='*', + help='Absolute or relative paths of the projects as globs.') + parser.add_argument('--branch_and_commit', + action='store_true', + help='Starts a new branch and commit changes.') + parser.add_argument('--push_change', + action='store_true', + help='Pushes change to Gerrit.') return parser.parse_args() @@ -270,9 +276,20 @@ def main(): for path in paths: try: test_mapping = TestMapping(env, bazel, path) - except UpdaterException as err: + test_mapping.create() + changed = (subprocess.call(['git', 'diff', '--quiet']) == 1) + if changed and args.branch_and_commit: + subprocess.check_output(['repo', 'start', + 'tmp_auto_test_mapping', '.']) + subprocess.check_output(['git', 'add', 'TEST_MAPPING']) + subprocess.check_output(['git', 'commit', '-m', + 'Update TEST_MAPPING\n\nTest: None']) + if changed and args.push_change: + date = datetime.today().strftime('%m-%d') + subprocess.check_output(['git', 'push', 'aosp', 'HEAD:refs/for/master', + '-o', 'topic=test-mapping-%s' % date]) + except (UpdaterException, subprocess.CalledProcessError) as err: sys.exit("Error: " + str(err)) - test_mapping.create() if __name__ == '__main__': main()