Joel Rosdahl [Sat, 18 Jun 2022 18:08:10 +0000 (20:08 +0200)]
fix: Use a cleanup stamp instead of directory timestamp for cleanup
In order to know when to clean up the temporary directory, ccache checks
mtime of $CCACHE_DIR and updates it to "now" on cleanup. This doesn't
work well when the configuration file is modified often since that also
updates the same mtime.
Fix this by using a separate cleanup stamp file instead.
Joel Rosdahl [Sat, 18 Jun 2022 17:55:02 +0000 (19:55 +0200)]
fix: Clean up temporary dir if it's left the default
Cleanup of the temporary directory is done if it is $CCACHE_DIR/tmp,
which used to be the default until [1] where the default was changed to
/run/user/$UID/ccache-tmp. Improve this so that cleanup happens if the
temporary directory is equal to the default regardless of the default.
Joel Rosdahl [Sat, 11 Jun 2022 12:13:02 +0000 (14:13 +0200)]
feat: Include timestamp in per-object debug filenames
Including a timestamp in the filenames makes it easier to compare two
builds without having to save previous debug files before the second
build. It also makes sure debug files won't be overwritten if an object
file is compiled several times during one build.
Joel Rosdahl [Fri, 10 Jun 2022 14:17:03 +0000 (16:17 +0200)]
feat: Support masquerading as a compiler via copy or hard link
Setting up ccache to masquerade as a compiler has always meant using
symbolic links, but there is no technical reason why that has to be the
case. This commit adds support for masquerading via a copy or hard link
of the ccache executable as well. This is mostly useful on platforms or
file systems where symbolic links are not supported.
Joel Rosdahl [Fri, 10 Jun 2022 14:12:27 +0000 (16:12 +0200)]
feat: Set CCACHE_DISABLE when calling compiler
If ccache for some reason executes a compiler that in turn calls ccache
then ccache will be run twice (and will potentially store two different
result in the cache since the compiler identications differ), which is
not very useful. This could for instance happen if the compiler is a
wrapper script that in turn calls "ccache $compiler ...".
Improve this by setting CCACHE_DISABLE when executing the compiler. Any
subsequent ccache invocations will then fall back to running the real
compiler.
Joel Rosdahl [Tue, 7 Jun 2022 14:53:44 +0000 (16:53 +0200)]
fix: Use correct umask when populating primary cache from secondary
Util::get_umask retrieves the process's umask and caches it to avoid
some system calls. This doesn't interact well now when using UmaskScope
to change umask temporarily since Util::get_umask then only sometimes
returns the correct value. This leads to the incorrect umask being used
when writing cache entries to the primary storage for secondary storage
hits.
Joel Rosdahl [Tue, 7 Jun 2022 13:12:03 +0000 (15:12 +0200)]
fix: Create temporary file with cpp extension instead of hard linking
[1] added a suitable file extension to the temporary file used for
capturing the preprocessed output by creating a hard link. This fails
when the temporary directory is on a file system that doesn't support
hard links.
Fix this by making it possible to pass a suffix to TemporaryFile and
passing the proper cpp suffix for the tmp stdout file instead of
creating a hard link as an alias.
The hard link in question is used in get_result_key_from_cpp to create
an alias of file that captures stdout from the preprocessor, where the
alias has the correct cpp extension. It can't just be a copy since
do_execute writes to the original name. See #1079.
Joel Rosdahl [Mon, 6 Jun 2022 18:46:09 +0000 (20:46 +0200)]
fix: Work around problem with GCC in util::ends_with
The util::ends_with implementation is taken directly from the
implementation suggestion in the C++20 standard, but it produces a
stringop-overread warning with GCC 11.2. There's either some subtle
aspect to this that I don't understand or a compiler bug, but let's work
around it by tweaking the implementation.
Joel Rosdahl [Wed, 11 May 2022 17:57:50 +0000 (19:57 +0200)]
feat: Improve --show-stats
- Added percentage for most values.
- All indented values now have their total count equal to the parent
value.
- Moved presentation of {direct,preprocessed}_cache_{hit,miss}
counters to a separate "Successful lookups" section.
- Removed "Use the -v/--verbose option for more details." from
--show-stats output since it's a bit wordy.
Joel Rosdahl [Thu, 26 May 2022 08:25:11 +0000 (10:25 +0200)]
fix: Fall back to copying temporary preprocessed output file
[1] added a suitable file extension to the temporary file used for
capturing the preprocessed output by creating a hard link. This fails
when the temporary directory is on a file system that doesn't support
hard links.
Fix this by falling back to copying when hard-linking fails.
jacobly0 [Sun, 1 May 2022 16:10:56 +0000 (18:10 +0200)]
fix: Fix sporadic test.profiling failures (#1056)
Using cut, which is always line-based, to remove bytes from a binary file can
cause problems if the binary timestamp field happens to contain a newline
character, which causes test.profiling to fail <1% of the time. Instead use tail
which has a character mode that ignores newlines.
Joel Rosdahl [Sun, 1 May 2022 11:15:37 +0000 (13:15 +0200)]
fix: Isolate inode cache file in tests
All test suites use the default temporary directory location
/run/user/<UID>/ccache-tmp when possible, which means that the inode
cache file is shared between all test suites. This is problematic when
running test suites in parallel since one test suite may run “ccache -C”
(which removes the inode cache file) between two compilations in the
inode_cache suite, thus making the second compilation not behave as
expected, failing the test.
Fix this by putting the temporary directory inside the test-specific
ccache directory instead of using the default global location.
The Util::normalize_absolute_path function only works on the syntactic
level, i.e. the result may not actually resolve to the same filesystem
entry (nor to any file system entry for that matter). It was meant to be
used for paths that don’t necessarily exist yet, such as a future
directory in which to write debug files. It may fail in edge cases with
symlinks in the path in combination with .. segments. If the caller
wants to ensure that the resulting path actually makes sense, it needs
to check if the resulting path points to the same file entry as the
original.
To improve on this, Util::normalize_absolute_path has now been renamed
to Util::normalize_abstract_absolute_path and there is a new
Util::normalize_concrete_absolute_path function which returns the
original path if the normalized result doesn't resolve to the same file
system entry as the original path.
Joel Rosdahl [Wed, 6 Apr 2022 19:37:04 +0000 (21:37 +0200)]
fix: Fix process_preprocessed_file bug for distcc marker
2044fea84b86001b2976ecde946d3d6d0e88ec0a (included in ccache 4.6)
removed the special-casing of distcc’s pump in
process_preprocessed_file. That in turn revealed a bug that has been
present since 432d1ca6a6aa51f708124172169073c399fb68d2 (included in
ccache 3.4) but previously only affected compilations with distcc-pump
as the “compiler”: the detection and handling of distcc-pump’s
“__________” messages is broken in two ways:
1. It throws away everything between the last preprocessor directive and
the “__________” marker. Thus, changes to such sections will not be
included in the hash.
2. It detects “__________” markers in the middle of lines, not only at
the beginning of lines.