Merge changes I47b4756d,I0564369e
* changes: Let the test mapping updater make commits and upload changes. Allow passing globs to update_crate_tests.py.
This commit is contained in:
@@ -27,11 +27,15 @@ 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 datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
# Some tests requires specific options. Consider fixing the upstream crate
|
||||
# before updating this dictionary.
|
||||
@@ -245,19 +249,47 @@ 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.')
|
||||
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()
|
||||
|
||||
|
||||
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:
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user