Compile a collection of ModuleIRs to C source text. Returns a dictionary mapping group names to a list of (file name, file text) pairs.
(
groups: Groups,
modules: ModuleIRs,
result: BuildResult,
mapper: Mapper,
compiler_options: CompilerOptions,
)
| 331 | |
| 332 | |
| 333 | def compile_ir_to_c( |
| 334 | groups: Groups, |
| 335 | modules: ModuleIRs, |
| 336 | result: BuildResult, |
| 337 | mapper: Mapper, |
| 338 | compiler_options: CompilerOptions, |
| 339 | ) -> dict[str | None, list[tuple[str, str]]]: |
| 340 | """Compile a collection of ModuleIRs to C source text. |
| 341 | |
| 342 | Returns a dictionary mapping group names to a list of (file name, |
| 343 | file text) pairs. |
| 344 | """ |
| 345 | source_paths = { |
| 346 | source.module: result.graph[source.module].xpath |
| 347 | for sources, _ in groups |
| 348 | for source in sources |
| 349 | } |
| 350 | |
| 351 | names = NameGenerator( |
| 352 | [[source.module for source in sources] for sources, _ in groups], |
| 353 | separate=compiler_options.separate, |
| 354 | ) |
| 355 | |
| 356 | # Generate C code for each compilation group. Each group will be |
| 357 | # compiled into a separate extension module. |
| 358 | ctext: dict[str | None, list[tuple[str, str]]] = {} |
| 359 | for group_sources, group_name in groups: |
| 360 | group_modules = { |
| 361 | source.module: modules[source.module] |
| 362 | for source in group_sources |
| 363 | if source.module in modules |
| 364 | } |
| 365 | if not group_modules: |
| 366 | # Fully-cached group (e.g. pip's second setup.py invoke for |
| 367 | # the wheel phase): no fresh IR was produced. Reuse the file |
| 368 | # list recorded in any module's IR cache so the linker still |
| 369 | # sees the previous run's outputs; empty content is a "do |
| 370 | # not rewrite" sentinel for mypyc_build. |
| 371 | ctext[group_name] = _load_cached_group_files(group_sources, result) |
| 372 | continue |
| 373 | generator = GroupGenerator( |
| 374 | group_modules, source_paths, group_name, mapper.group_map, names, compiler_options |
| 375 | ) |
| 376 | ctext[group_name] = generator.generate_c_for_modules() |
| 377 | |
| 378 | return ctext |
| 379 | |
| 380 | |
| 381 | def _load_cached_group_files( |
no test coverage detected
searching dependent graphs…