Joel Rosdahl [Tue, 20 Oct 2020 18:49:50 +0000 (20:49 +0200)]
Detect errors in log strings at compile time
fmtlib can detect format string errors at compile time if (1) applying
FMT_STRING to the format string literal and (2) compiling for C++14 or
higher.
Requirement 1 is implemented by introducing a LOG macro which applies
FMT_STRING to the first argument and calls Logging::log (if logging is
enabled). Also added are a companion LOG_RAW macro (since C++11 requires
at least one argument for the “...” part in variadic macros) and a
BULK_LOG macro which calls Logging::bulk_log (if logging is enabled).
Requirement 2 is implemented by setting CMAKE_CXX_STANDARD to 14 for one
CI build with a known C++14-capable compiler. We can’t set it to 14 by
default since we still want the code to be buildable with C++11
compilers.
This will catch errors such as the one fixed by PR #691.
Olle Liljenzin [Mon, 12 Oct 2020 18:53:02 +0000 (20:53 +0200)]
Fix expect_perm to work with SELinux (#681)
Test case CCACHE_UMASK fails when running it in an SELinux context because
/bin/ls adds a trailing dot to the output. Thus truncate the output to expected
length.
Joel Rosdahl [Tue, 6 Oct 2020 13:01:01 +0000 (15:01 +0200)]
Fix broken dependency file when using base_dir
If a path in the dependency file matches base_dir, the dependency file
will be completely broken since newlines won’t be not retained by
use_relative_paths_in_depfile. Fix this by tokenizing lines instead of
the full file content once again.
Joel Rosdahl [Mon, 5 Oct 2020 17:03:19 +0000 (19:03 +0200)]
Improve consistency of terms in the manual
* configuration setting -> configuration option
* option -> command line option, configuration option, compiler option,
value or sloppiness (unless it’s obvious from the context what
“option” refers to)
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.