Merge "Allow passing multiple crates to update_crate_tests.py"
diff --git a/scripts/update_crate_tests.py b/scripts/update_crate_tests.py
index 192f50e..7e13f62 100755
--- a/scripts/update_crate_tests.py
+++ b/scripts/update_crate_tests.py
@@ -181,17 +181,14 @@
UpdaterException: the package does not appear to belong to the
current repository.
"""
- if path == None:
- self.dir = os.getcwd()
- else:
- self.dir = path
+ self.dir = path
try:
self.dir_rel = self.dir.split(env.ANDROID_BUILD_TOP)[1]
except IndexError:
raise UpdaterException('The path ' + self.dir + ' is not under ' +
env.ANDROID_BUILD_TOP + '; You must be in the '
'directory of a crate or pass its absolute path '
- 'as first argument.')
+ 'as the argument.')
# Move to the package_directory.
os.chdir(self.dir)
@@ -208,14 +205,14 @@
Attributes:
package: The package associated with this TEST_MAPPING file.
"""
- def __init__(self, path):
+ def __init__(self, env, bazel, path):
"""Constructor.
Args:
+ env: An instance of Env.
+ bazel: An instance of Bazel.
path: The absolute path to the package.
"""
- env = Env()
- bazel = Bazel(env)
self.package = Package(path, env, bazel)
def create(self):
@@ -245,19 +242,22 @@
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_file.write("\n")
- print("TEST_MAPPING successfully updated!")
+ print("TEST_MAPPING successfully updated for %s!" % self.package.dir_rel)
def main():
- if len(sys.argv) == 2:
- path = sys.argv[1]
+ if len(sys.argv) > 1:
+ paths = sys.argv[1:]
else:
- path = None
- try:
- test_mapping = TestMapping(path)
- except UpdaterException as err:
- sys.exit("Error: " + str(err))
- test_mapping.create()
+ paths = [os.getcwd()]
+ env = Env()
+ bazel = Bazel(env)
+ for path in paths:
+ try:
+ test_mapping = TestMapping(env, bazel, path)
+ except UpdaterException as err:
+ sys.exit("Error: " + str(err))
+ test_mapping.create()
if __name__ == '__main__':
main()