cli: refuse an entry whose header would leave --out-dir - #47
Merged
Conversation
VeaaC
force-pushed
the
outdir-escape-2.29
branch
2 times, most recently
from
August 15, 2026 08:56
94e0355 to
be76a06
Compare
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
force-pushed
the
outdir-escape-2.29
branch
from
August 15, 2026 10:30
be76a06 to
b80373e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.