From a3914b9099a4ad11dabd6dc7349106a431177561 Mon Sep 17 00:00:00 2001 From: "Randy J. Spaulding" Date: Fri, 30 Jan 2026 02:58:41 +0000 Subject: [PATCH] Adapt parser to monorepo --- .../src/enhanced_ninja_parser.py | 13 +++++++++ .../src/selective_test_filter.py | 29 +++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/script/dependency-parser/src/enhanced_ninja_parser.py b/script/dependency-parser/src/enhanced_ninja_parser.py index ebcd8789158..5d17f88c2d0 100644 --- a/script/dependency-parser/src/enhanced_ninja_parser.py +++ b/script/dependency-parser/src/enhanced_ninja_parser.py @@ -163,11 +163,20 @@ def _build_file_to_executable_mapping(self): """Build the final mapping from files to executables.""" print("Building file-to-executable mapping...") + # For monorepo, truncate the path before and including projects/ + self.project = None + rl_regex = rf"rocm-libraries[\\/]+projects[\\/]+([^\\/]+)[\\/]+(.*)" for exe, object_files in self.executable_to_objects.items(): for obj_file in object_files: # Add all dependencies of this object file if obj_file in self.object_to_all_deps: for dep_file in self.object_to_all_deps[obj_file]: + match = re.search(rl_regex, dep_file, re.IGNORECASE) + if match: + dep_file = match.group(2) + if not self.project: + print(f"Found rocm-libraries project: '{match.group(1)}'") + self.project = match.group(1) # Filter out system files and focus on project files if self._is_project_file(dep_file): self.file_to_executables[dep_file].add(exe) @@ -244,6 +253,10 @@ def export_to_json(self, output_file): exe_to_files[exe].add(file_path) mapping_data = { + "repo": { + "type": "monorepo" if self.project else "component", + "project": self.project + }, "file_to_executables": { file_path: list(exes) for file_path, exes in self.file_to_executables.items() diff --git a/script/dependency-parser/src/selective_test_filter.py b/script/dependency-parser/src/selective_test_filter.py index 83f7f7eebee..0073d190bd6 100644 --- a/script/dependency-parser/src/selective_test_filter.py +++ b/script/dependency-parser/src/selective_test_filter.py @@ -31,7 +31,7 @@ import os -def get_changed_files(ref1, ref2): +def get_changed_files(ref1, ref2, project: str = None): """Return a set of files changed between two git refs.""" try: result = subprocess.run( @@ -40,7 +40,21 @@ def get_changed_files(ref1, ref2): text=True, check=True, ) - files = set(line.strip() for line in result.stdout.splitlines() if line.strip()) + + raw_files = set(line.strip() for line in result.stdout.splitlines() if line.strip()) + + if project is None: + files = raw_files + print(f"Identified {len(files)} modified files") + else: + root = f"projects/{project}/" + root_len = len(root) + files = set() + for f in raw_files: + if f.startswith(root): + files.add(f[root_len:]) + print(f"Identified {len(files)} files modified in project '{project}'") + return files except subprocess.CalledProcessError as e: print(f"Error running git diff: {e}") @@ -52,9 +66,12 @@ def load_depmap(depmap_json): with open(depmap_json, "r") as f: data = json.load(f) # Support both old and new formats + json_project = None + if "repo" in data and data["repo"]["type"] == "monorepo": + json_project = data["repo"]["project"] if "file_to_executables" in data: - return data["file_to_executables"] - return data + return data["file_to_executables"], json_project + return data, json_project def select_tests(file_to_executables, changed_files, filter_mode): @@ -132,12 +149,12 @@ def main(): print(f"Dependency map JSON not found: {depmap_json}") sys.exit(1) - changed_files = get_changed_files(ref1, ref2) + file_to_executables, json_project = load_depmap(depmap_json) + changed_files = get_changed_files(ref1, ref2, json_project) if not changed_files: print("No changed files detected.") tests = [] else: - file_to_executables = load_depmap(depmap_json) tests = select_tests(file_to_executables, changed_files, filter_mode) with open(output_json, "w") as f: