Skip to content

flatc -M: escape make-special characters in depfiles - #9207

Open
vee1e wants to merge 1 commit into
google:masterfrom
vee1e:escape-make-dep
Open

flatc -M: escape make-special characters in depfiles#9207
vee1e wants to merge 1 commit into
google:masterfrom
vee1e:escape-make-dep

Conversation

@vee1e

@vee1e vee1e commented Aug 26, 2026

Copy link
Copy Markdown

flatc -M writes dependency rules with filenames unescaped. Make treats $, #, :, space, and backslash as syntax, so a schema whose include path contains any of them produces a depfile that make or Ninja parses wrong. For example an include named my schema#1.fbs yields a rule that make splits at the space and truncates at the #.

GCC and Clang already escape these characters in their -M/-MD output, and glslang does the same with its writeEscapedDepString helper. This change matches that behavior.

What it does:

  • Adds EscapeMakeDep to util.h/util.cpp, escaping backslash first, then space, #, :, and $ (as $$).
  • Applies it to every active GenerateMakeRule implementation: Java/C#, C++, Rust, Dart, binary, text, and TypeScript.
  • Emits each rule as one line instead of word-wrapping. Wrapping split escaped filenames on their spaces, undoing the escape.

Brackets are intentionally not escaped: Ninja's depfile parser does not unescape [, so escaping them would corrupt filenames for that consumer.

Adds a unit test covering the five characters, combined input, a trailing backslash, and empty and plain filenames.

flatc -M emits dependency rules containing filenames as-is. Characters
that are special to make ($ # : space \) are not escaped, so a schema
whose include path contains any of them produces a depfile that make or
Ninja mis-parses. GCC and Clang escape these in -M/-MD output, and glslang
does the same via writeEscapedDepString.

Add EscapeMakeDep and apply it to every active GenerateMakeRule site, and
emit the rule as a single line instead of word-wrapping (wrapping splits
escaped filenames on their spaces).
@vee1e
vee1e requested a review from dbaileychess as a code owner August 26, 2026 06:03
@github-actions github-actions Bot added c++ javascript rust typescript codegen Involving generating code from schema dart labels Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant