|
56 | 56 | short_id_from_name, |
57 | 57 | ) |
58 | 58 | from mypyc.errors import Errors |
59 | | -from mypyc.ir.deps import LIBRT_BASE64, LIBRT_STRINGS, LIBRT_TIME, LIBRT_VECS, SourceDep |
| 59 | +from mypyc.ir.deps import ( |
| 60 | + LIBRT_BASE64, |
| 61 | + LIBRT_STRINGS, |
| 62 | + LIBRT_TIME, |
| 63 | + LIBRT_VECS, |
| 64 | + Capsule, |
| 65 | + HeaderDep, |
| 66 | + SourceDep, |
| 67 | +) |
60 | 68 | from mypyc.ir.func_ir import FuncIR |
61 | 69 | from mypyc.ir.module_ir import ModuleIR, ModuleIRs, deserialize_modules |
62 | 70 | from mypyc.ir.ops import DeserMaps, LoadLiteral |
@@ -436,24 +444,31 @@ def load_scc_from_cache( |
436 | 444 | return modules |
437 | 445 |
|
438 | 446 |
|
439 | | -def collect_source_dependencies( |
440 | | - modules: dict[str, ModuleIR], *, internal: bool = True |
441 | | -) -> set[SourceDep]: |
442 | | - """Collect all SourceDep dependencies from all modules. |
443 | | -
|
444 | | - If internal is set to False, returns only the dependencies that can be exported to C extensions |
445 | | - dependent on the one currently being compiled. |
446 | | - """ |
| 447 | +def collect_source_dependencies(modules: dict[str, ModuleIR]) -> set[SourceDep]: |
| 448 | + """Collect all SourceDep dependencies from all modules.""" |
447 | 449 | source_deps: set[SourceDep] = set() |
448 | 450 | for module in modules.values(): |
449 | 451 | for dep in module.dependencies: |
450 | 452 | if isinstance(dep, SourceDep): |
451 | | - if internal == dep.internal: |
| 453 | + if dep.internal: |
452 | 454 | source_deps.add(dep) |
| 455 | + elif isinstance(dep, Capsule): |
| 456 | + source_deps.add(dep.internal_dep()) |
| 457 | + return source_deps |
| 458 | + |
| 459 | + |
| 460 | +def collect_header_dependencies(modules: dict[str, ModuleIR], *, internal: bool) -> set[str]: |
| 461 | + """Collect all header dependencies from all modules.""" |
| 462 | + header_deps: set[str] = set() |
| 463 | + for module in modules.values(): |
| 464 | + for dep in module.dependencies: |
| 465 | + if isinstance(dep, (SourceDep, HeaderDep)): |
| 466 | + if dep.internal == internal: |
| 467 | + header_deps.add(dep.get_header()) |
453 | 468 | else: |
454 | 469 | capsule_dep = dep.internal_dep() if internal else dep.external_dep() |
455 | | - source_deps.add(capsule_dep) |
456 | | - return source_deps |
| 470 | + header_deps.add(capsule_dep.get_header()) |
| 471 | + return header_deps |
457 | 472 |
|
458 | 473 |
|
459 | 474 | def compile_modules_to_c( |
@@ -652,9 +667,9 @@ def emit_dep_headers(decls: Emitter, internal: bool) -> None: |
652 | 667 | if self.compiler_options.depends_on_librt_internal: |
653 | 668 | decls.emit_line(f'#include "internal/librt_internal{suffix}.h"') |
654 | 669 | # Include headers for conditional source files |
655 | | - source_deps = collect_source_dependencies(self.modules, internal=internal) |
656 | | - for source_dep in sorted(source_deps, key=lambda d: d.path): |
657 | | - decls.emit_line(f'#include "{source_dep.get_header()}"') |
| 670 | + header_deps = collect_header_dependencies(self.modules, internal=internal) |
| 671 | + for header_dep in sorted(header_deps): |
| 672 | + decls.emit_line(f'#include "{header_dep}"') |
658 | 673 |
|
659 | 674 | emit_dep_headers(ext_declarations, False) |
660 | 675 |
|
|
0 commit comments