Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions script/dependency-parser/src/enhanced_ninja_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<project_name>
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)
Expand Down Expand Up @@ -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()
Expand Down
29 changes: 23 additions & 6 deletions script/dependency-parser/src/selective_test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}")
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
Loading