Skip to content

Commit 932ce74

Browse files
committed
refactor script: improve LLVM coverage handling with detailed file checks, enhanced debug outputs, and refined command logic
1 parent 8c74eea commit 932ce74

1 file changed

Lines changed: 48 additions & 9 deletions

File tree

scripts/generate_llvm_coverage.py

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ def find_profile_files(build_dir):
1818
profile_files = list(Path(build_dir).rglob("*.profraw"))
1919
if not profile_files:
2020
print("No profile files found!", file=sys.stderr)
21+
print(f"Searched in: {Path(build_dir).absolute()}", file=sys.stderr)
22+
# List all files to debug
23+
print("Files in build directory:", file=sys.stderr)
24+
for f in Path(build_dir).iterdir():
25+
if f.is_file():
26+
print(f" {f.name}", file=sys.stderr)
2127
sys.exit(1)
28+
print(f"Found {len(profile_files)} profile files:")
29+
for f in profile_files:
30+
print(f" {f}")
2231
return profile_files
2332

2433

@@ -58,12 +67,21 @@ def generate_coverage_reports(
5867

5968
# Build the executable list
6069
exec_paths = []
70+
print(f"\nLooking for executables in {Path(build_dir).absolute()}:")
6171
for exe in executables:
6272
exe_path = Path(build_dir) / exe
6373
if exe_path.exists():
6474
exec_paths.append(str(exe_path))
75+
print(f" Found: {exe_path}")
6576
else:
66-
print(f"Warning: Executable not found: {exe_path}", file=sys.stderr)
77+
print(f" Warning: Executable not found: {exe_path}", file=sys.stderr)
78+
# Try to find similar executables
79+
bin_dir = Path(build_dir) / "bin"
80+
if bin_dir.exists():
81+
print(f" Available executables in bin/:", file=sys.stderr)
82+
for f in bin_dir.iterdir():
83+
if f.is_file() and f.stat().st_mode & 0o111: # executable
84+
print(f" {f.name}", file=sys.stderr)
6785

6886
if not exec_paths:
6987
print("No executables found!", file=sys.stderr)
@@ -76,34 +94,55 @@ def generate_coverage_reports(
7694

7795
# Generate coverage summary (to console)
7896
print("\nGenerating coverage summary...")
79-
cmd = [llvm_cov, "report", "-instr-profile", profdata_file] + exec_paths + ignore_args
97+
cmd = [llvm_cov, "report"]
98+
if exec_paths:
99+
cmd.append(exec_paths[0]) # First executable
100+
for exe in exec_paths[1:]:
101+
cmd.extend(["-object", exe]) # Additional executables
102+
cmd.extend(["-instr-profile", profdata_file] + ignore_args)
80103
subprocess.run(cmd, check=True)
81104

82105
# Generate LCOV report
83106
# Place coverage.lcov in the current working directory (build dir)
84107
lcov_file = Path("coverage.lcov")
85108
print(f"\nGenerating LCOV report: {lcov_file}")
86-
cmd = [
87-
llvm_cov, "export",
109+
110+
# For llvm-cov export, we need to specify the object files differently
111+
# The first executable is the main object, others are specified with -object
112+
cmd = [llvm_cov, "export"]
113+
if exec_paths:
114+
cmd.append(exec_paths[0]) # First executable
115+
for exe in exec_paths[1:]:
116+
cmd.extend(["-object", exe]) # Additional executables
117+
cmd.extend([
88118
"-instr-profile", profdata_file,
89119
"-format=lcov"
90-
] + exec_paths + ignore_args
120+
] + ignore_args)
121+
122+
print(f"Running: {' '.join(cmd[:10])}...") # Print first part of command for debugging
91123

92124
with open(lcov_file, 'w', encoding='utf-8') as f:
93-
subprocess.run(cmd, stdout=f, check=True)
125+
result = subprocess.run(cmd, stdout=f, stderr=subprocess.PIPE, text=True)
126+
if result.returncode != 0:
127+
print(f"Error generating LCOV: {result.stderr}", file=sys.stderr)
128+
raise subprocess.CalledProcessError(result.returncode, cmd)
94129

95130
# Generate HTML report
96131
html_dir = Path(output_dir)
97132
html_dir.mkdir(parents=True, exist_ok=True)
98133
print(f"\nGenerating HTML report: {html_dir}")
99-
cmd = [
100-
llvm_cov, "show",
134+
cmd = [llvm_cov, "show"]
135+
if exec_paths:
136+
cmd.append(exec_paths[0]) # First executable
137+
for exe in exec_paths[1:]:
138+
cmd.extend(["-object", exe]) # Additional executables
139+
cmd.extend([
101140
"-instr-profile", profdata_file,
102141
"-format=html",
103142
"-output-dir", str(html_dir),
104143
"-show-line-counts-or-regions",
105144
"-show-instantiations"
106-
] + exec_paths + ignore_args
145+
] + ignore_args)
107146

108147
subprocess.run(cmd, check=True)
109148
print("\nCoverage reports generated successfully!")

0 commit comments

Comments
 (0)