|
27 | 27 | This script is automatically called by external_updater.
|
28 | 28 | """
|
29 | 29 |
|
| 30 | +import argparse |
| 31 | +import glob |
30 | 32 | import json
|
31 | 33 | import os
|
32 | 34 | import platform
|
33 | 35 | import subprocess
|
34 | 36 | import sys
|
| 37 | +from datetime import datetime |
| 38 | +from pathlib import Path |
35 | 39 |
|
36 | 40 | # Some tests requires specific options. Consider fixing the upstream crate
|
37 | 41 | # before updating this dictionary.
|
@@ -245,19 +249,47 @@ def write_test_mapping(self, test_mapping):
|
245 | 249 | print("TEST_MAPPING successfully updated for %s!" % self.package.dir_rel)
|
246 | 250 |
|
247 | 251 |
|
| 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 | + |
248 | 266 | 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 | + |
253 | 274 | env = Env()
|
254 | 275 | bazel = Bazel(env)
|
255 | 276 | for path in paths:
|
256 | 277 | try:
|
257 | 278 | 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: |
259 | 292 | sys.exit("Error: " + str(err))
|
260 |
| - test_mapping.create() |
261 | 293 |
|
262 | 294 | if __name__ == '__main__':
|
263 | 295 | main()
|
0 commit comments