diff --git a/scripts/core_compile_inputs.py b/scripts/core_compile_inputs.py index 8692aa24a..b6856a607 100644 --- a/scripts/core_compile_inputs.py +++ b/scripts/core_compile_inputs.py @@ -10,10 +10,14 @@ import re import tomllib from dataclasses import dataclass from pathlib import Path -from typing import Any, Literal +from typing import Any ROOT_PACKAGE = "solstone-core" INCLUDE_MACROS = frozenset({"include_str", "include_bytes"}) +_INCLUDE_MACRO_ALTERNATION = "|".join( + re.escape(macro) for macro in sorted(INCLUDE_MACROS) +) +INCLUDE_MACRO_RE = re.compile(rf"\b(?P{_INCLUDE_MACRO_ALTERNATION})\s*!\s*\(") class CoreCompileInputError(RuntimeError): @@ -23,7 +27,7 @@ class CoreCompileInputError(RuntimeError): @dataclass(frozen=True) class CoreCompileInputAsset: source_file: Path - macro: Literal["include_str", "include_bytes"] + macro: str line: int column: int raw_argument: str @@ -34,7 +38,6 @@ class CoreCompileInputAsset: @dataclass(frozen=True) class _Package: name: str - member: str manifest: Path data: dict[str, Any] @@ -95,7 +98,7 @@ def _workspace_packages(root: Path) -> dict[str, _Package]: ) if name in packages: raise CoreCompileInputError(f"package-name-duplicate: {name}") - packages[name] = _Package(name, member, manifest, member_data) + packages[name] = _Package(name, manifest, member_data) if ROOT_PACKAGE not in packages: raise CoreCompileInputError(f"root-package-missing: {ROOT_PACKAGE}") return packages @@ -298,8 +301,7 @@ def _include_records( ) -> tuple[CoreCompileInputAsset, ...]: masked = _masked_rust(source, text) records: list[CoreCompileInputAsset] = [] - pattern = re.compile(r"\b(?Pinclude_str|include_bytes)\s*!\s*\(") - for match in pattern.finditer(masked): + for match in INCLUDE_MACRO_RE.finditer(masked): macro = match.group("macro") close = _matching_delimiter(masked, match.end() - 1, "(", ")") raw_argument = text[match.end() : close].strip() @@ -318,7 +320,7 @@ def _include_records( records.append( CoreCompileInputAsset( source_file=source.resolve(), - macro=macro, # type: ignore[arg-type] + macro=macro, line=line, column=column, raw_argument=raw_argument, diff --git a/tests/test_core_sdist_compile_inputs_integration.py b/tests/test_core_sdist_compile_inputs_integration.py index b5287ce9e..99e6d6432 100644 --- a/tests/test_core_sdist_compile_inputs_integration.py +++ b/tests/test_core_sdist_compile_inputs_integration.py @@ -162,6 +162,10 @@ def _build_wheel(tmp_path: Path, name: str, sdist: Path) -> _BuildResult: def _build_env(root: Path, target_dir: Path, maturin_args: str) -> dict[str, str]: env = _scrubbed_build_env(root, maturin_args) + # The rail builds inside the checkout and inherits rust-toolchain.toml; + # this isolated harness does not. Pin that toolchain explicitly, keep Cargo + # offline, and use a fresh non-incremental target dir so no cached artifact + # can satisfy a mutated sdist build. env["CARGO_TARGET_DIR"] = str(target_dir) env["CARGO_INCREMENTAL"] = "0" env["CARGO_NET_OFFLINE"] = "true"