| 358 | |
| 359 | |
| 360 | def process_rust_coverage( |
| 361 | session: nox.Session, |
| 362 | rust_binaries: list[str], |
| 363 | prof_raw_location: pathlib.Path, |
| 364 | ) -> None: |
| 365 | target_libdir = session.run( |
| 366 | class="st">"rustc", class="st">"--print", class="st">"target-libdir", external=True, silent=True |
| 367 | ) |
| 368 | if target_libdir is not None: |
| 369 | target_bindir = pathlib.Path(target_libdir).parent / class="st">"bin" |
| 370 | |
| 371 | profraws = [ |
| 372 | str(prof_raw_location / p) |
| 373 | for p in prof_raw_location.glob(class="st">"*.profraw") |
| 374 | ] |
| 375 | session.run( |
| 376 | str(target_bindir / (class="st">"llvm-profdata" + BIN_EXT)), |
| 377 | class="st">"merge", |
| 378 | class="st">"-sparse", |
| 379 | *profraws, |
| 380 | class="st">"-o", |
| 381 | class="st">"rust-cov.profdata", |
| 382 | external=True, |
| 383 | ) |
| 384 | |
| 385 | lcov_data = session.run( |
| 386 | str(target_bindir / (class="st">"llvm-cov" + BIN_EXT)), |
| 387 | class="st">"export", |
| 388 | rust_binaries[0], |
| 389 | *itertools.chain.from_iterable( |
| 390 | [class="st">"-object", b] for b in rust_binaries[1:] |
| 391 | ), |
| 392 | class="st">"-instr-profile=rust-cov.profdata", |
| 393 | class="st">"--ignore-filename-regex=[/\\].cargo[/\\]", |
| 394 | class="st">"--ignore-filename-regex=[/\\]rustc[/\\]", |
| 395 | class="st">"--ignore-filename-regex=[/\\].rustup[/\\]toolchains[/\\]", |
| 396 | class="st">"--ignore-filename-regex=[/\\]target[/\\]", |
| 397 | class="st">"--format=lcov", |
| 398 | silent=True, |
| 399 | external=True, |
| 400 | ) |
| 401 | assert isinstance(lcov_data, str) |
| 402 | lcov_data = LCOV_SOURCEFILE_RE.sub( |
| 403 | lambda m: class="st">"SF:src/rust/" + m.group(1).replace(class="st">"\\", class="st">"/"), |
| 404 | lcov_data.replace(class="st">"\r\n", class="st">"\n"), |
| 405 | ) |
| 406 | with open(fclass="st">"{uuid.uuid4()}.lcov", class="st">"w") as f: |
| 407 | f.write(lcov_data) |