Skip to content

fix(scanner): skip raw-string-literal bodies when detecting imports#138

Merged
Sunrisepeak merged 1 commit into
mainfrom
fix/scanner-skip-string-literals
Jun 21, 2026
Merged

fix(scanner): skip raw-string-literal bodies when detecting imports#138
Sunrisepeak merged 1 commit into
mainfrom
fix/scanner-skip-string-literals

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Problem

Every mcpp build prints:

warning: src/scaffold/create.cppm: module 'imgui.core' imported but not provided in this build
warning: src/scaffold/create.cppm: module 'imgui.app' imported but not provided in this build

mcpp itself doesn't depend on imgui. The import imgui.core; / import imgui.app;
lines live inside a raw-string literal — the mcpp new --template gui
skeleton, stored as R"GUI( ... )GUI" in scaffold/create.cppm:221-224.

Root cause

The default regex scanner scan_file (src/modgraph/scanner.cppm) scans each
line as raw text and strips only line comments. It has no lexical state for
string/raw-string literals, so a line whose trimmed text starts with import
is matched as a real import even inside a raw string. The warning is then
emitted by resolve_graph and printed from prepare.cppm.

(The opt-in MCPP_SCANNER=p1689 compiler-driven path is not fooled; the
default regex path is.)

Fix

Track raw-string state across lines (strip_raw_strings) and blank out raw
bodies before import/module matching. Ordinary "..." strings are left as-is:
the matcher only fires on lines that start with the keyword, which a string
body can only do when it spans lines (a raw string).

Tests

  • Scanner.IgnoresImportsInsideRawStringLiteral — multi-line R"GUI(...)GUI"
    with embedded import imgui.core; → only the genuine top-level imports
    recorded.
  • Scanner.IgnoresImportInsideSingleLineRawString.
  • Verified the real create.cppm no longer warns when built with the patched
    binary (mcpp test: all green).

The existing Scanner.ProvidesAndRequires test even carried a NOTE to avoid
raw strings because of this false positive — now unnecessary.

First of 5 follow-up PRs; plan in .agents/docs/2026-06-22-mcpp-followups-design.md.

The default regex module scanner (scan_file in modgraph/scanner.cppm)
scanned each line as raw text, stripping only line comments. A line whose
trimmed text began with 'import' was treated as a real module import even
when it lived inside a multi-line raw-string literal — e.g. the
'mcpp new --template gui' skeleton stored as R"GUI( ... import imgui.core;
... )GUI" in scaffold/create.cppm. That produced spurious
'module imgui.core imported but not provided in this build' warnings on
every mcpp build.

Track raw-string state across lines (strip_raw_strings) and blank out raw
bodies before import/module matching. Ordinary "..." strings are left as
is: the matcher only fires on lines that *start with* the keyword, which a
string body can only do across lines (a raw string).

Adds two regression tests; verified the real create.cppm no longer warns.

Also lands the follow-ups design doc (.agents/docs/2026-06-22).
@Sunrisepeak Sunrisepeak merged commit c7be19e into main Jun 21, 2026
3 checks passed
@Sunrisepeak Sunrisepeak deleted the fix/scanner-skip-string-literals branch June 21, 2026 20:04
Sunrisepeak added a commit that referenced this pull request Jun 21, 2026
* fix(build): self-heal stale build.ninja on 'missing and no known rule'

When a dependency package under the registry is reinstalled/moved but keeps
the same version string, the build fingerprint (which does not yet cover
registry dep state) is unchanged, so the cached build.ninja is reused.
Ninja then aborts with 'missing and no known rule to make it' and the build
hard-fails, forcing the user to run `mcpp clean` by hand.

Add that signature to is_stale_ninja_failure so try_fast_build drops to a
full graph regeneration (same invocation) instead of failing — the stale
graph is rewritten against the current dep state and the build proceeds.

(Folding registry dep state into the fingerprint to avoid the regen entirely
is a larger follow-up; see .agents/docs/2026-06-22 §T-j.)

* chore: bump version 0.0.57 -> 0.0.58

Release carrying the follow-up batch: scanner raw-string fix (#138),
first-run progress (#139), toolchain effective-resolution (#140),
doctor runtime-dep check (#141), and the build.ninja self-heal above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant