Joel Rosdahl [Thu, 1 Oct 2020 11:00:30 +0000 (13:00 +0200)]
Handle missing .gcno file gracefully
GCC ≥9 has changed behavior for -ftest-coverage and --coverage in
combination with -fprofile-dir=dir:
- Without -fprofile-dir=dir the file is placed next to the object file
but with a “.gcno” extension.
- With -fprofile-dir=dir the file is also place next to the object file
(i.e. not in the specified profile directory) but the same style of
name as used for “.gcda” files (full pathname with slashes replaced
with hash characters).
Fix this by:
- Checking if the expected (GCC <9) .gcno file is present. If not, fall
back to running the compiler and increment the “unsupported option”
counter.
- Making sure to perform the above check before copying the object file
to the cache so that a later ccache invocation won’t believe that
there is a result in the cache.
- Improving the copy_file routine to not create the destination file
until it knows that there is a source file to copy from.
Joel Rosdahl [Wed, 30 Sep 2020 20:18:09 +0000 (22:18 +0200)]
Simplify source package generation
Since it now works to build from “git archive” archives, use such an
archive as the official source code release archive instead of using
CPack with a custom install script for modifying the source code. We can
revisit this in the future when and if we want a source code release
archive that is not simply an export of the version-controlled source
code.
Joel Rosdahl [Wed, 30 Sep 2020 15:13:48 +0000 (17:13 +0200)]
Make it possible to build from “git archive” source archives
The ccache CMake scripts currently support building from an official
release archive or in a Git repository but not from a source archive
created by “git archive”.
Improve this by adding directives so that “git archive” substitutes
needed information when exporting the source tree.
Joel Rosdahl [Mon, 28 Sep 2020 12:56:43 +0000 (14:56 +0200)]
Use ubuntu-18.04 instead of ubuntu-20.04 for Clang-Tidy
The ubuntu-20.04 VM has intermittent build errors that look like this:
sudo apt-get install libzstd-dev clang-tidy
[...]
The following packages have unmet dependencies:
clang-tidy : Depends: clang-tidy-10 (>= 10~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
Clang-Tidy 9 also found “function ... has a definition with different
parameter names” warnings that needed to be fixed as part of this.
Joel Rosdahl [Sun, 27 Sep 2020 14:53:09 +0000 (16:53 +0200)]
Handle short read when writing result files
Result::Write::write_embedded_file_entry assumes that read(2) never
performs a “short read” (fewer bytes than the supplied count) for files.
A short read can however happen if the process is interrupted by a
signal, for instance on NFS with the “intr” mount option.
Fix this by properly reducing the remaining bytes counter by the amount
of actually read bytes.
Joel Rosdahl [Thu, 24 Sep 2020 19:14:11 +0000 (21:14 +0200)]
Improve CMake targets related to documentation
- Rename the documentation target to doc-html.
- Rename the manpage target to doc-man-page.
- Make the doc-html target not recreate documentation files each time it
is run by using the OUTPUT form of add_custom_command.
- Similar for the doc-man-page target.
- Add doc target which builds both HTML documentation and man page.
Reducing file lengths should be beneficial since it reduces the number
of needed system calls when scanning many files in the cache. The effect
is very small but there is no real downside. See also b16001a67f4389956ef6e7ccf7d8023684b57119.
Base32 is chosen since the encoding algorithm is very simple compared to
e.g. base36. Base64 cannot be used since the encoded digest string is
used in filenames and the cache directory may be located on a case
insensitive filesystem. The base32hex variant is chosen instead of the
other base32 variants since it feels more natural and there are no
visual ambiguity issues.
The first two bytes are encoded as base16 to maintain compatibility with
the cleanup algorithm in older ccache versions and to allow for up to
four uniform cache levels.
Joel Rosdahl [Tue, 22 Sep 2020 06:13:13 +0000 (08:13 +0200)]
Fix base32hex code
- Const-ified input parameter.
- Use non-reserved macro for the include guard.
- Use unsigned int buffer to avoid “left shift of 1236923897 by 8 places
cannot be represented in type int” reported by Clang’s
UndefinedBehaviorSanitizer.
Joel Rosdahl [Mon, 21 Sep 2020 05:59:50 +0000 (07:59 +0200)]
Use short type suffix for cache files
x.result -> xR
x.manifest -> xM
x_n.raw -> xnW
Reducing file lengths should be beneficial since it reduces the number
of needed system calls when scanning many files in the cache. The effect
is very small but there is no real downside.
A one letter suffix is kept to allow for making decisions based on file
type without having to open the file. The suffix is uppercase so that is
doesn’t clash with pre-4.0 *.stderr files stored in the cache.
Joel Rosdahl [Sat, 19 Sep 2020 19:07:22 +0000 (21:07 +0200)]
Store cache statistics on level 2 and cache bookkeeping still on level 1
In a “mostly cache hits” scenario, many parallel ccache invocations may
want to update statistics at the same time. Spreading out counter
updates over 256 instead of 16 stats files reduces lock contention
significantly.
Keeping cache bookkeeping (i.e. cache size and files counters) on level
1 preserves backward compatibility with the cleanup algorithm in older
ccache versions.
Some counters displayed by “ccache -s” won’t be accurate when an older
ccache version is run on a cache directory that is also used by ccache
4.x, but that shouldn’t be much of a problem in practice. Also, the
cache statistics isn’t backward compatible anyway since new counters may
be introduced and they will be invisible to older versions.
Closes #168 (only statistics are moved to the second level, though).
Joel Rosdahl [Fri, 18 Sep 2020 07:28:48 +0000 (09:28 +0200)]
Implement support for automatic cache levels
This makes ccache choose an appropriate cache level structure
automatically based on a maximum number of files per directory,
currently hardcoded to 2000.
Joel Rosdahl [Fri, 18 Sep 2020 06:36:08 +0000 (08:36 +0200)]
Add ASSERT and DEBUG_ASSERT macros
CMake always defines NDEBUG in release builds, so assertions are only
enabled in debug builds. Assertions were however always enabled before
switching to CMake. I prefer keeping assertions enabled in release
builds as well unless they are part of a tight loop.
Fix this by introducing two custom assertion macors:
- ASSERT(condition): Like assert(condition) but always enabled.
- DEBUG_ASSERT(condition): Like assert(condition), i.e. only enabled in
debug builds.
All usage of assert(condition) is converted to ASSERT(condition) since
none of the assertions are made in performance-critical code.
Joel Rosdahl [Thu, 10 Sep 2020 08:48:49 +0000 (10:48 +0200)]
Remove cache_dir_levels (CCACHE_NLEVELS) setting
This is in preparation for two things:
1. Storing cache statistics (except size/files bookkeeping) on level 2
instead of level 1, thus making “cache_dir_levels = 1” invalid.
2. Implementing automatic choice of cache levels based on the number of
files in the cache.
Joel Rosdahl [Sat, 12 Sep 2020 09:15:27 +0000 (11:15 +0200)]
Remove upgrade code for populating config with legacy cache size values
Version 3.2, which introduced the configuration file, was released over
six years ago so it seems reasonable to remove upgrade code for older
versions now.
Joel Rosdahl [Fri, 11 Sep 2020 14:55:25 +0000 (16:55 +0200)]
Refactor flushing of stats and logs at ccache exit
Perform flushing of statistics counters (potentially triggering cache
cleanup) and log files in a finalizer inside cache_compilation instead
of in Conxtext’s destructor. This moves somewhat complex logic from
Context into the main ccache code.
As a side effect of this, stats_flush and stats_flush_to_file are
superfluous.
The primary motivation for this is that it’s now possible to detect and
block underflow when incrementing a value in the unlikely but possible
event that a, say, cache_size_kibibyte is decremented below zero.
Joel Rosdahl [Sat, 5 Sep 2020 18:31:36 +0000 (20:31 +0200)]
Introduce Util::parse_{unsigned,signed} functions
parse_unsigned replaces parse_uint32 while parse_signed replaces
parse_int. For simplicity, both return 64-bit values; I see no need to
be able to return narrower types since they are used for parsing
configuration values where a valid range is more important. Therefore
the functions optionally verify minimum and maximum allowed values.