docs/requirements/output-env-derived-flags.md
Compilers read part of their effective configuration from the
environment rather than from argv. The GCC/Clang family treats
CPATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, and
OBJC_INCLUDE_PATH as additional header search paths; MSVC reads
CL and _CL_ as implicit leading and trailing options. A build
that relies on these variables compiles correctly, but a tool reading
compile_commands.json sees only the literal argv and misses the
search paths the compiler actually used.
To keep entries self-contained, Bear translates these environment
variables into the equivalent explicit flags and folds them into each
entry's arguments. This is on by default, matching what the compiler
did. Some users prefer entries that reflect argv alone; a single
configuration option turns the translation off.
This behaviour is observable in compile_commands.json only. The
intercepted event record already captures the full environment (see
interception-events-format); this requirement does not change it.
arguments contain only the flags that came from argv
(after any response-file inlining; see
output-response-file-inlining).arguments.compile_commands.json.
The interception layer and the recorded event environment are not
affected.Given a build that runs cc -c src.c -o src.o with CPATH set to
/opt/first:/opt/second in the environment:
When the user runs Bear with environment flags enabled (the default), then the entry for
src.chasargumentsthat include an explicit include flag for/opt/firstfollowed by an explicit include flag for/opt/second, in the orderCPATHlists them.
Given the same build and environment:
When the user runs Bear with environment flags disabled, then the entry for
src.chasargumentsthat contain neither/opt/firstnor/opt/second, and the arguments are exactly those that appeared on the command line.
output-compilation-entries -- the per-source
transformation these flags participate in.output-response-file-inlining -- the sibling option.interception-cc-env-var-flags -- wrapper-mode splitting
of a CC="gcc -std=c11" value, a separate mechanism.