docs/requirements/output-arguments-from-environment.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).compile_commands.json.
The interception layer and the recorded event environment are not
affected.interception-compiler-env-with-flags, which handles a compiler
named with trailing flags (CC="gcc -std=c11") in wrapper mode.
That feature is unaffected by this option.Given a build that runs cc -c src.c -o src.o with CPATH set to a
directory in the environment:
When the user runs Bear with environment flags enabled (the default), then the entry for
src.chasargumentsthat include the directory fromCPATHas an explicit include flag.
Given the same build and environment:
When the user runs Bear with environment flags disabled, then the entry for
src.chasargumentsthat do not contain the directory fromCPATH, and the arguments are exactly those that appeared on the command line.
output-response-file-inlining (feature request #701),
which introduced the sibling configuration group.output-compilation-entries -- the per-source
transformation these flags participate in.output-response-file-inlining -- the sibling option in
the same configuration group.interception-compiler-env-with-flags -- a separate
environment mechanism, not governed here.