diff options
author | Rob Seymour <rseymour@google.com> | 2022-02-11 06:19:15 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-02-11 06:19:15 +0000 |
commit | 653c1e8acab962484309bb4474ea296e7aff8c90 (patch) | |
tree | b40a6c66035946857aabc841c7d1e27427c3aa3e | |
parent | 66e1a0d784076c7af3d29a84f6cd14a2ef3cdbd8 (diff) | |
parent | 750ce69810e509c4a0a93b4e5cb29abadfbc0935 (diff) | |
download | treble-653c1e8acab962484309bb4474ea296e7aff8c90.tar.gz |
Merge "Add configuration parameter to ignore paths from module-info file" am: 750ce69810
Original change: https://android-review.googlesource.com/c/platform/tools/treble/+/1979866
Change-Id: If721b69e1dc4a5e783c61672e78a3e55cf6f836f
-rw-r--r-- | split/manifest_split.py | 25 | ||||
-rw-r--r-- | split/manifest_split_test.py | 7 |
2 files changed, 24 insertions, 8 deletions
diff --git a/split/manifest_split.py b/split/manifest_split.py index d5f9b95..5114f24 100644 --- a/split/manifest_split.py +++ b/split/manifest_split.py @@ -121,10 +121,12 @@ class ManifestSplitConfig: this project, for projects that should be added to the resulting manifest. path_mappings: A list of PathMappingConfigs to modify a path in the build sandbox to the path in the manifest. + ignore_paths: Set of paths to ignore when parsing module_info_file """ remove_projects: Dict[str, str] add_projects: Dict[str, str] path_mappings: List[PathMappingConfig] + ignore_paths: Set[str] @classmethod def from_config_files(cls, config_files: List[str]): @@ -139,6 +141,8 @@ class ManifestSplitConfig: remove_projects: Dict[str, str] = {} add_projects: Dict[str, str] = {} path_mappings = [] + """ Always ignore paths in out/ directory. """ + ignore_paths = set(["out/"]) for config_file in config_files: root = ET.parse(config_file).getroot() @@ -155,7 +159,10 @@ class ManifestSplitConfig: for child in root.findall("path_mapping") ]) - return cls(remove_projects, add_projects, path_mappings) + ignore_paths.update( + {c.attrib["name"]: config_file for c in root.findall("ignore_path")}) + + return cls(remove_projects, add_projects, path_mappings, ignore_paths) def get_repo_projects(repo_list_file, manifest, path_mappings): @@ -195,7 +202,7 @@ def get_repo_projects(repo_list_file, manifest, path_mappings): class ModuleInfo: """Contains various mappings to/from module/project""" - def __init__(self, module_info_file, repo_projects): + def __init__(self, module_info_file, repo_projects, ignore_paths): """Initialize a module info instance. Builds various maps related to platform build system modules and how they @@ -204,6 +211,7 @@ class ModuleInfo: Args: module_info_file: The path to a module-info.json file from a build. repo_projects: The output of the get_repo_projects function. + ignore_paths: Set of paths to ignore from module_info_file data Raises: ValueError: A module from module-info.json belongs to a path not @@ -221,14 +229,18 @@ class ModuleInfo: with open(module_info_file) as module_info_file: module_info = json.load(module_info_file) + # Check that module contains a path and the path is not in set of + # ignore paths def module_has_valid_path(module): - return ("path" in module_info[module] and module_info[module]["path"] and - not module_info[module]["path"][0].startswith("out/")) + paths = module.get("path") + if not paths: + return False + return all(not paths[0].startswith(p) for p in ignore_paths) module_paths = { module: module_info[module]["path"][0] for module in module_info - if module_has_valid_path(module) + if module_has_valid_path(module_info[module]) } module_project_paths = { module: scan_repo_projects(repo_projects, module_paths[module]) @@ -519,7 +531,8 @@ def create_split_manifest(targets, manifest_file, split_manifest_file, # While we still have projects whose modules we haven't checked yet, if module_info_file: - module_info = ModuleInfo(module_info_file, repo_projects) + module_info = ModuleInfo(module_info_file, repo_projects, + config.ignore_paths) checked_projects = set() projects_to_check = input_projects.difference(checked_projects) logger.info("Checking module-info dependencies for direct and adjacent modules...") diff --git a/split/manifest_split_test.py b/split/manifest_split_test.py index 73976cc..d9c6f76 100644 --- a/split/manifest_split_test.py +++ b/split/manifest_split_test.py @@ -121,8 +121,9 @@ class ManifestSplitTest(unittest.TestCase): 'system/project4': 'platform/project4', 'vendor/google/project3': 'vendor/project3', } + ignore_paths = set(['out/']) module_info = manifest_split.ModuleInfo(module_info_file.name, - repo_projects) + repo_projects, ignore_paths) self.assertEqual( module_info.project_modules, { 'platform/project1': set(['target1a', 'target1b']), @@ -163,9 +164,11 @@ class ManifestSplitTest(unittest.TestCase): }""") module_info_file.flush() repo_projects = {} + ignore_paths = set() with self.assertRaisesRegex(ValueError, 'Unknown module path for module target1'): - manifest_split.ModuleInfo(module_info_file.name, repo_projects) + manifest_split.ModuleInfo(module_info_file.name, repo_projects, + ignore_paths) @unittest.mock.patch.object(subprocess, 'check_output', autospec=True) def test_get_ninja_inputs(self, mock_check_output): |