mirror of
https://github.com/rizsotto/Bear.git
synced 2026-05-28 00:20:45 +02:00
d7305bac20
Wrapper mode previously stored whatever `which(gcc)` returned as the "real compiler" for each wrapper. On distributions with a ccache masquerade in PATH (Fedora/Arch/Gentoo by default), that is the ccache symlink, so the wrapper's child process was ccache. ccache then searched PATH for gcc, skipping only symlinks to itself; Bear's hard-linked wrapper in `.bear/` passed the self-check and was re-executed, producing an infinite loop. environment.rs now detects masquerade wrappers at discovery time by canonicalising candidate paths and checking the target's basename against a fixed set (ccache, distcc, icecc, colorgcc, buildcache). The containing directory is stripped from the lookup PATH and resolution retries, so the wrapper config always names the real compiler. Both the CC-env and PATH-scan discovery paths are covered. Other changes in the same fix: - Requirement reworked around "resolve past masquerade wrappers at discovery time"; the original CCACHE_COMPILER proposal is documented as rejected, verified empirically to reproduce the hang via CCACHE_COMPILER pointing at the ccache symlink. - Nine new unit tests cover detection, filtering, and the no-real-compiler fallback. - New integration test wrapper_mode_survives_masquerade_wrapper_in_path prepends the masquerade dir to its own child PATH so the recursion scenario is exercised regardless of host PATH, while keeping other tests ccache-free. - build.rs scans well-known masquerade locations (/usr/lib/ccache, /usr/lib64/ccache, /usr/libexec/ccache), exposes the found dir via CCACHE_MASQUERADE_DIR, and sets cfg(host_has_ccache_masquerade) to gate the new test. - The manual ccache_free_path_and_compiler workaround in the wrapper-mode tests is gone; the tests now run against the host's real PATH and also protect this requirement. - CI: Ubuntu job runs apt-get install ccache so the masquerade dir exists on every PR. The job PATH is deliberately not modified -- ccache first on PATH would inflate event counts for preload-mode tests that assert exact compiler-event counts. Side effect: ccache is bypassed while Bear is observing. That matches Bear's observe-don't-optimise stance and keeps compile_commands.json recording the real compiler. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>