Allow passing multiple crates to update_crate_tests.py

Currently the script can only run on a single crate at a time, and
each time it runs it re-initializes Bazel. By passing multiple crates
we can save time by only initializing Bazel once.

Test: Call with zero, one, and multiple crate arguments.
Change-Id: Ic83c16d87066a8555b736b35bc7971586ee26e16
This commit is contained in:
Joel Galenson
2021-06-17 14:59:15 -07:00
parent 6105088a62
commit 177910448c

View File

@@ -181,9 +181,6 @@ class Package(object):
UpdaterException: the package does not appear to belong to the UpdaterException: the package does not appear to belong to the
current repository. current repository.
""" """
if path == None:
self.dir = os.getcwd()
else:
self.dir = path self.dir = path
try: try:
self.dir_rel = self.dir.split(env.ANDROID_BUILD_TOP)[1] self.dir_rel = self.dir.split(env.ANDROID_BUILD_TOP)[1]
@@ -191,7 +188,7 @@ class Package(object):
raise UpdaterException('The path ' + self.dir + ' is not under ' + raise UpdaterException('The path ' + self.dir + ' is not under ' +
env.ANDROID_BUILD_TOP + '; You must be in the ' env.ANDROID_BUILD_TOP + '; You must be in the '
'directory of a crate or pass its absolute path ' 'directory of a crate or pass its absolute path '
'as first argument.') 'as the argument.')
# Move to the package_directory. # Move to the package_directory.
os.chdir(self.dir) os.chdir(self.dir)
@@ -208,14 +205,14 @@ class TestMapping(object):
Attributes: Attributes:
package: The package associated with this TEST_MAPPING file. package: The package associated with this TEST_MAPPING file.
""" """
def __init__(self, path): def __init__(self, env, bazel, path):
"""Constructor. """Constructor.
Args: Args:
env: An instance of Env.
bazel: An instance of Bazel.
path: The absolute path to the package. path: The absolute path to the package.
""" """
env = Env()
bazel = Bazel(env)
self.package = Package(path, env, bazel) self.package = Package(path, env, bazel)
def create(self): def create(self):
@@ -245,16 +242,19 @@ class TestMapping(object):
json_file.write("// Generated by update_crate_tests.py for tests that depend on this crate.\n") json_file.write("// Generated by update_crate_tests.py for tests that depend on this crate.\n")
json.dump(test_mapping, json_file, indent=2, separators=(',', ': '), sort_keys=True) json.dump(test_mapping, json_file, indent=2, separators=(',', ': '), sort_keys=True)
json_file.write("\n") json_file.write("\n")
print("TEST_MAPPING successfully updated!") print("TEST_MAPPING successfully updated for %s!" % self.package.dir_rel)
def main(): def main():
if len(sys.argv) == 2: if len(sys.argv) > 1:
path = sys.argv[1] paths = sys.argv[1:]
else: else:
path = None paths = [os.getcwd()]
env = Env()
bazel = Bazel(env)
for path in paths:
try: try:
test_mapping = TestMapping(path) test_mapping = TestMapping(env, bazel, path)
except UpdaterException as err: except UpdaterException as err:
sys.exit("Error: " + str(err)) sys.exit("Error: " + str(err))
test_mapping.create() test_mapping.create()