Create a thin archive from object files. Thin archives store references to object files instead of copying them, resulting in faster archive creation and smaller archive size. Args: emar: Archiver command (e.g., 'clang-tool-chain-emar') object_files: List of .o fil
(
emar: str,
object_files: list[Path],
output_path: Path,
verbose: bool = False,
)
| 390 | |
| 391 | |
| 392 | def create_thin_archive( |
| 393 | emar: str, |
| 394 | object_files: list[Path], |
| 395 | output_path: Path, |
| 396 | verbose: bool = False, |
| 397 | ) -> int: |
| 398 | """ |
| 399 | Create a thin archive from object files. |
| 400 | |
| 401 | Thin archives store references to object files instead of copying them, |
| 402 | resulting in faster archive creation and smaller archive size. |
| 403 | |
| 404 | Args: |
| 405 | emar: Archiver command (e.g., 'clang-tool-chain-emar') |
| 406 | object_files: List of .o files to include |
| 407 | output_path: Output .a archive path |
| 408 | verbose: Enable verbose output |
| 409 | |
| 410 | Returns: |
| 411 | Exit code (0 = success) |
| 412 | """ |
| 413 | print(f"Creating thin archive: {output_path.name}...") |
| 414 | |
| 415 | if not object_files: |
| 416 | print("✗ No object files to archive") |
| 417 | return 1 |
| 418 | |
| 419 | # Ensure output directory exists |
| 420 | output_path.parent.mkdir(parents=True, exist_ok=True) |
| 421 | |
| 422 | # Remove existing archive to prevent stale objects from persisting. |
| 423 | # The 'r' flag in emar inserts/replaces, so old entries would remain. |
| 424 | if output_path.exists(): |
| 425 | output_path.unlink() |
| 426 | |
| 427 | # Create response file for object list (avoid command line length limits) |
| 428 | response_file = BUILD_DIR / "archive_objects.rsp" |
| 429 | with open(response_file, "w") as f: |
| 430 | for obj in object_files: |
| 431 | f.write(f"{obj}\n") |
| 432 | |
| 433 | # Build archive command |
| 434 | # rcsT flags: |
| 435 | # r = insert/replace files in archive |
| 436 | # c = create archive if it doesn't exist |
| 437 | # s = write an index (required for linking) |
| 438 | # T = create thin archive (references instead of copies) |
| 439 | cmd = [ |
| 440 | emar, |
| 441 | "rcsT", |
| 442 | str(output_path), |
| 443 | f"@{response_file}", |
| 444 | ] |
| 445 | |
| 446 | if verbose: |
| 447 | print(f"Command: {' '.join(cmd)}") |
| 448 | |
| 449 | result = subprocess.run(cmd, cwd=PROJECT_ROOT) |
no test coverage detected