Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit f486885

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge changes I47b4756d,I0564369e
* changes: Let the test mapping updater make commits and upload changes. Allow passing globs to update_crate_tests.py.
2 parents 097e8c0 + 4a2a3a8 commit f486885

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

scripts/update_crate_tests.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@
2727
This script is automatically called by external_updater.
2828
"""
2929

30+
import argparse
31+
import glob
3032
import json
3133
import os
3234
import platform
3335
import subprocess
3436
import sys
37+
from datetime import datetime
38+
from pathlib import Path
3539

3640
# Some tests requires specific options. Consider fixing the upstream crate
3741
# before updating this dictionary.
@@ -245,19 +249,47 @@ def write_test_mapping(self, test_mapping):
245249
print("TEST_MAPPING successfully updated for %s!" % self.package.dir_rel)
246250

247251

252+
def parse_args():
253+
parser = argparse.ArgumentParser('update_crate_tests')
254+
parser.add_argument('paths',
255+
nargs='*',
256+
help='Absolute or relative paths of the projects as globs.')
257+
parser.add_argument('--branch_and_commit',
258+
action='store_true',
259+
help='Starts a new branch and commit changes.')
260+
parser.add_argument('--push_change',
261+
action='store_true',
262+
help='Pushes change to Gerrit.')
263+
return parser.parse_args()
264+
265+
248266
def main():
249-
if len(sys.argv) > 1:
250-
paths = sys.argv[1:]
251-
else:
252-
paths = [os.getcwd()]
267+
args = parse_args()
268+
paths = args.paths if len(args.paths) > 0 else [os.getcwd()]
269+
# We want to use glob to get all the paths, so we first convert to absolute.
270+
paths = [Path(path).resolve() for path in paths]
271+
paths = sorted([path for abs_path in paths
272+
for path in glob.glob(str(abs_path))])
273+
253274
env = Env()
254275
bazel = Bazel(env)
255276
for path in paths:
256277
try:
257278
test_mapping = TestMapping(env, bazel, path)
258-
except UpdaterException as err:
279+
test_mapping.create()
280+
changed = (subprocess.call(['git', 'diff', '--quiet']) == 1)
281+
if changed and args.branch_and_commit:
282+
subprocess.check_output(['repo', 'start',
283+
'tmp_auto_test_mapping', '.'])
284+
subprocess.check_output(['git', 'add', 'TEST_MAPPING'])
285+
subprocess.check_output(['git', 'commit', '-m',
286+
'Update TEST_MAPPING\n\nTest: None'])
287+
if changed and args.push_change:
288+
date = datetime.today().strftime('%m-%d')
289+
subprocess.check_output(['git', 'push', 'aosp', 'HEAD:refs/for/master',
290+
'-o', 'topic=test-mapping-%s' % date])
291+
except (UpdaterException, subprocess.CalledProcessError) as err:
259292
sys.exit("Error: " + str(err))
260-
test_mapping.create()
261293

262294
if __name__ == '__main__':
263295
main()

0 commit comments

Comments
 (0)