Skip to content

cli: refuse an entry whose header would leave --out-dir - #47

Merged
VeaaC merged 1 commit into
mainfrom
outdir-escape-2.29
Aug 15, 2026
Merged

cli: refuse an entry whose header would leave --out-dir#47
VeaaC merged 1 commit into
mainfrom
outdir-escape-2.29

Conversation

@VeaaC

@VeaaC VeaaC commented Aug 15, 2026

Copy link
Copy Markdown
Owner

No description provided.

@VeaaC
VeaaC force-pushed the outdir-escape-2.29 branch 2 times, most recently from 94e0355 to be76a06 Compare August 15, 2026 08:56
A generated header goes at the schema's path relative to the first -I that contains
it, else at its basename. The CMake helper documents that rule and implements it; the
CLI deviated for relative arguments, because canonical_entry_name returns the spelling
it was given when nothing rebases it and header_path used that as the stem. So

  rapidprotoc --arena --out-dir gen ../schemas/x.proto

reported `wrote gen/../schemas/x.rp.hpp` and created it OUTSIDE gen, exiting 0.

The CLI now absolutises its entries as they are parsed, which is what the helper does
before invoking the generator -- and why builds driven by CMake never saw this. An
entry under an -I rebases exactly as before, since canonical_entry_name absolutises
internally before relativizing; one under none falls back to an absolute path, which
header_path reduces to a basename. That makes the two implementations agree by
construction rather than by review.

Absolutising must not normalize. Collapsing `..` is a textual rewrite, while the
kernel resolves `lnk/..` to the parent of the link's target, so a normalized entry
can name a file the OS would not -- and generate from it without saying anything.
Imports keep their names untouched: the emitted #include directives are built from
the import string, so basenaming one would break them.

Three inputs are refused rather than resolved, since either answer silently loses a
schema. All are checked before the first write, so a refused run leaves nothing.

  - two entries generating the same header (`/a/x.proto` and `/b/x.proto` both wrote
    x.rp.hpp, the second over the first, exit 0)
  - two sharing a canonical name via different -I dirs, which deduplicates them into
    ONE file, so only one of the two was ever generated
  - an import whose path escapes the out-dir, which no -I can move; the error names
    the file that imports it, since that is the one to edit (protoc rejects it too)

tests/check_generate_names.sh compares the helper's prediction against what the CLI
writes across thirteen entry shapes, and pins the three refusals. Two of the shapes
are spelled RELATIVE: the rest are absolute, because that is what CMake passes, so
only those two exercise the fallback this rule turns on. Each guard has a case that
fails when it alone is removed.
@VeaaC
VeaaC force-pushed the outdir-escape-2.29 branch from be76a06 to b80373e Compare August 15, 2026 10:30
@VeaaC
VeaaC merged commit 8e4dfef into main Aug 15, 2026
9 checks passed
@VeaaC
VeaaC deleted the outdir-escape-2.29 branch August 15, 2026 13:00
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