Skip to content

Commit 9889e91

Browse files
committed
Add test and fix test harness
1 parent b7453d6 commit 9889e91

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

mypyc/build.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def mypyc_build(
490490
*,
491491
separate: bool | list[tuple[list[str], str | None]] = False,
492492
only_compile_paths: Iterable[str] | None = None,
493-
skip_cgen_input: Any | None = None,
493+
skip_cgen_input: tuple[list[list[tuple[str, str]]], list[str]] | None = None,
494494
always_use_shared_lib: bool = False,
495495
) -> tuple[emitmodule.Groups, list[tuple[list[str], list[str]]], list[SourceDep]]:
496496
"""Do the front and middle end of mypyc building, producing and writing out C source."""
@@ -523,7 +523,8 @@ def mypyc_build(
523523
# TODO: unique names?
524524
write_file(os.path.join(compiler_options.target_dir, "ops.txt"), ops_text)
525525
else:
526-
group_cfiles = skip_cgen_input
526+
group_cfiles = skip_cgen_input[0]
527+
source_deps = [SourceDep(d) for d in skip_cgen_input[1]]
527528

528529
# Write out the generated C and collect the files for each group
529530
# Should this be here??
@@ -553,7 +554,7 @@ def mypycify(
553554
strip_asserts: bool = False,
554555
multi_file: bool = False,
555556
separate: bool | list[tuple[list[str], str | None]] = False,
556-
skip_cgen_input: Any | None = None,
557+
skip_cgen_input: tuple[list[list[tuple[str, str]]], list[str]] | None = None,
557558
target_dir: str | None = None,
558559
include_runtime_files: bool | None = None,
559560
strict_dunder_typing: bool = False,

mypyc/test-data/run-multimodule.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,3 +950,15 @@ import native
950950
15
951951
NT(x=4)
952952
{'x': 5}
953+
954+
[case testExtraLibRtSourceFileDep]
955+
table_list = list(range(256))
956+
table_list[ord('A')] = ord('B')
957+
table = bytes(table_list)
958+
959+
def translate(b: bytes) -> bytes:
960+
# The primimitive for bytes.translate requires an optional C file from lib-rt
961+
return b.translate(table)
962+
[file driver.py]
963+
import native
964+
assert native.translate(b'ABCD') == b'BBCD'

mypyc/test/test_run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from mypy.test.helpers import assert_module_equivalence, perform_file_operations
2323
from mypyc.build import construct_groups
2424
from mypyc.codegen import emitmodule
25+
from mypyc.codegen.emitmodule import collect_source_dependencies
2526
from mypyc.errors import Errors
2627
from mypyc.options import CompilerOptions
2728
from mypyc.test.config import test_data_prefix
@@ -266,6 +267,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
266267
ir, cfiles, _ = emitmodule.compile_modules_to_c(
267268
result, compiler_options=compiler_options, errors=errors, groups=groups
268269
)
270+
deps = sorted(dep.path for dep in collect_source_dependencies(ir))
269271
if errors.num_errors:
270272
errors.flush_errors()
271273
assert False, "Compile error"
@@ -288,7 +290,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
288290
setup_format.format(
289291
module_paths,
290292
separate,
291-
cfiles,
293+
(cfiles, deps),
292294
self.multi_file,
293295
opt_level,
294296
librt,

0 commit comments

Comments
 (0)