Compile source file with -ftime-trace. Returns path to generated .json trace file.
(
source_file: Path, compiler: str = "clang++", include_dir: Optional[Path] = None
)
| 533 | |
| 534 | |
| 535 | def compile_with_trace( |
| 536 | source_file: Path, compiler: str = "clang++", include_dir: Optional[Path] = None |
| 537 | ) -> Path: |
| 538 | """ |
| 539 | Compile source file with -ftime-trace. |
| 540 | |
| 541 | Returns path to generated .json trace file. |
| 542 | """ |
| 543 | output_file = source_file.with_suffix(".o") |
| 544 | trace_file = source_file.with_suffix(".json") |
| 545 | |
| 546 | # Remove old files |
| 547 | if output_file.exists(): |
| 548 | output_file.unlink() |
| 549 | if trace_file.exists(): |
| 550 | trace_file.unlink() |
| 551 | |
| 552 | # Build compile command |
| 553 | cmd = [ |
| 554 | compiler, |
| 555 | "-std=c++14", # C++14 required for MSVC headers |
| 556 | "-c", |
| 557 | str(source_file), |
| 558 | "-o", |
| 559 | str(output_file), |
| 560 | "-ftime-trace", |
| 561 | ] |
| 562 | |
| 563 | # Add include directory |
| 564 | if include_dir: |
| 565 | cmd.extend(["-I", str(include_dir)]) |
| 566 | else: |
| 567 | # Default to src/ directory |
| 568 | src_dir = source_file.parent.parent.parent / "src" |
| 569 | if src_dir.exists(): |
| 570 | cmd.extend(["-I", str(src_dir)]) |
| 571 | |
| 572 | # Add common defines for FastLED |
| 573 | cmd.extend( |
| 574 | [ |
| 575 | "-DFASTLED_INTERNAL", |
| 576 | "-DFASTLED_TESTING", # Use testing mode (simpler platform dependencies) |
| 577 | "-DFASTLED_STUB_IMPL", # Use stub platform (all pins valid) |
| 578 | "-Wno-everything", # Suppress all warnings for cleaner output |
| 579 | ] |
| 580 | ) |
| 581 | |
| 582 | print(f"Compiling with: {' '.join(cmd)}", file=sys.stderr) |
| 583 | |
| 584 | try: |
| 585 | result = RunningProcess.run(cmd, cwd=None, check=False, timeout=60) |
| 586 | |
| 587 | if result.returncode != 0: |
| 588 | print("Compilation failed:", file=sys.stderr) |
| 589 | print(result.stdout, file=sys.stderr) |
| 590 | sys.exit(1) |
| 591 | |
| 592 | if not trace_file.exists(): |