| 217 | |
| 218 | |
| 219 | def process_rust_coverage( |
| 220 | session: nox.Session, |
| 221 | rust_binaries: typing.List[str], |
| 222 | prof_raw_location: pathlib.Path, |
| 223 | ) -> None: |
| 224 | # Hitting weird issues merging Windows and Linux Rust coverage, so just |
| 225 | # say the hell with it. |
| 226 | if sys.platform == "win32": |
| 227 | return |
| 228 | |
| 229 | target_libdir = session.run( |
| 230 | "rustc", "--print", "target-libdir", external=True, silent=True |
| 231 | ) |
| 232 | if target_libdir is not None: |
| 233 | target_bindir = pathlib.Path(target_libdir).parent / "bin" |
| 234 | |
| 235 | profraws = [ |
| 236 | str(prof_raw_location / p) |
| 237 | for p in prof_raw_location.glob("*.profraw") |
| 238 | ] |
| 239 | session.run( |
| 240 | str(target_bindir / ("llvm-profdata" + BIN_EXT)), |
| 241 | "merge", |
| 242 | "-sparse", |
| 243 | *profraws, |
| 244 | "-o", |
| 245 | "rust-cov.profdata", |
| 246 | external=True, |
| 247 | ) |
| 248 | |
| 249 | lcov_data = session.run( |
| 250 | str(target_bindir / ("llvm-cov" + BIN_EXT)), |
| 251 | "export", |
| 252 | rust_binaries[0], |
| 253 | *itertools.chain.from_iterable( |
| 254 | ["-object", b] for b in rust_binaries[1:] |
| 255 | ), |
| 256 | "-instr-profile=rust-cov.profdata", |
| 257 | "--ignore-filename-regex=[/\\].cargo[/\\]", |
| 258 | "--ignore-filename-regex=[/\\]rustc[/\\]", |
| 259 | "--ignore-filename-regex=[/\\].rustup[/\\]toolchains[/\\]", |
| 260 | "--ignore-filename-regex=[/\\]target[/\\]", |
| 261 | "--format=lcov", |
| 262 | silent=True, |
| 263 | external=True, |
| 264 | ) |
| 265 | assert isinstance(lcov_data, str) |
| 266 | lcov_data = LCOV_SOURCEFILE_RE.sub( |
| 267 | lambda m: "SF:src/rust/" + m.group(1).replace("\\", "/"), |
| 268 | lcov_data.replace("\r\n", "\n"), |
| 269 | ) |
| 270 | with open(f"{uuid.uuid4()}.lcov", "w") as f: |
| 271 | f.write(lcov_data) |