update_crate_tests: Clean up
Rename the Crate class to Package as this script may also be used to update TEST_MAPPING for the prebuilts/rust toolchain. Inline get_tests function as one branch was never used. Rename `create_test_mapping` to `create` as it is already a method of TestMapping. Test: update_crate_tests.py in external/rust/crates/libc Test: update_crate_tests.py in prebuilts/rust Change-Id: I06bd6d4f93223bb50fdb898980bd25fa3cea9019
This commit is contained in:
@@ -117,17 +117,17 @@ class Bazel(object):
|
|||||||
rdep_tests = set()
|
rdep_tests = set()
|
||||||
for module in modules:
|
for module in modules:
|
||||||
for rdep in self.query_rdeps(module):
|
for rdep in self.query_rdeps(module):
|
||||||
rule_type, tmp, mod = rdep.split(" ")
|
rule_type, _, mod = rdep.split(" ")
|
||||||
if rule_type == "rust_test_" or rule_type == "rust_test":
|
if rule_type == "rust_test_" or rule_type == "rust_test":
|
||||||
if self.exclude_module(mod) == False:
|
if self.exclude_module(mod) == False:
|
||||||
rdep_tests.add(mod.split(":")[1].split("--")[0])
|
rdep_tests.add(mod.split(":")[1].split("--")[0])
|
||||||
return rdep_tests
|
return rdep_tests
|
||||||
|
|
||||||
|
|
||||||
class Crate(object):
|
class Package(object):
|
||||||
def __init__(self, path, bazel):
|
def __init__(self, path, bazel):
|
||||||
self.modules = bazel.query_modules(path)
|
modules = bazel.query_modules(path)
|
||||||
self.rdep_tests = bazel.query_rdep_tests(self.modules)
|
self.rdep_tests = bazel.query_rdep_tests(modules)
|
||||||
|
|
||||||
def get_rdep_tests(self):
|
def get_rdep_tests(self):
|
||||||
return self.rdep_tests
|
return self.rdep_tests
|
||||||
@@ -138,20 +138,13 @@ class TestMapping(object):
|
|||||||
self.env = Env(path)
|
self.env = Env(path)
|
||||||
self.bazel = Bazel(self.env)
|
self.bazel = Bazel(self.env)
|
||||||
|
|
||||||
def create_test_mapping(self, path):
|
def create(self):
|
||||||
tests = self.get_tests(path)
|
tests = Package(self.env.cwd_relative, self.bazel).get_rdep_tests()
|
||||||
if not bool(tests):
|
if not bool(tests):
|
||||||
return
|
return
|
||||||
test_mapping = self.tests_to_mapping(tests)
|
test_mapping = self.tests_to_mapping(tests)
|
||||||
self.write_test_mapping(test_mapping)
|
self.write_test_mapping(test_mapping)
|
||||||
|
|
||||||
def get_tests(self, path):
|
|
||||||
# for each path collect local Rust modules.
|
|
||||||
if path is not None and path != "":
|
|
||||||
return Crate(self.env.cwd_relative + "/" + path, self.bazel).get_rdep_tests()
|
|
||||||
else:
|
|
||||||
return Crate(self.env.cwd_relative, self.bazel).get_rdep_tests()
|
|
||||||
|
|
||||||
def tests_to_mapping(self, tests):
|
def tests_to_mapping(self, tests):
|
||||||
test_mapping = {"presubmit": []}
|
test_mapping = {"presubmit": []}
|
||||||
for test in tests:
|
for test in tests:
|
||||||
@@ -180,7 +173,7 @@ def main():
|
|||||||
test_mapping = TestMapping(path)
|
test_mapping = TestMapping(path)
|
||||||
except UpdaterException as err:
|
except UpdaterException as err:
|
||||||
sys.exit("Error: " + str(err))
|
sys.exit("Error: " + str(err))
|
||||||
test_mapping.create_test_mapping(None)
|
test_mapping.create()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user