Joel Rosdahl [Mon, 22 May 2023 17:58:41 +0000 (19:58 +0200)]
fix: Fix undefined behavior in util::read_file_part for zero count
If util::read_file_part's count argument is 0 (which can currently only
happen in unit tests), we'll do &result[0] where result is
default-initialized std::unique_ptr<uint8_t[]>. This is not allowed even
though we won't actually dereference the pointer. Found by compiling
with -D_GLIBCXX_ASSERTIONS.
With the depend mode enabled, ccache executes the original command line
verbatim, potentially with the addition of a few extra options. However,
for clang or clang-cl it is not possible to simply append the additional
options to the end of the original command line since there may be a
"--" option to indicate the end of options.
Fix this by inserting the additional options directly after the compiler
instead of at the end.
Joel Rosdahl [Mon, 17 Apr 2023 16:08:24 +0000 (18:08 +0200)]
fix: Find Ccache version from lightweight Git tag
Ccache calculates its version from a matching Git tag by using the "git
describe" command, which only considers annotated tags. All ccache tags
are annotated. However, when running a GitHub action job for a tag the
local Git repository is (at least by default) a shallow clone with the
tag being converted to a lightweight tag. This makes "git describe" not
see the tag.
Fix this by adding --tags to "git describe" to make it consider
lightweight tags as well.
Joel Rosdahl [Mon, 17 Apr 2023 06:26:13 +0000 (08:26 +0200)]
ci: Disable Windows 64-bit MSBuild jobs for now
The Windows VS2019 64-bit MSBuild and Windows VS2022 64-bit MSBuild
GitHub actions jobs have started failing on master due to some changes
in the CI environment. See issue #1278.
Tobias Hieta [Tue, 28 Mar 2023 19:45:37 +0000 (21:45 +0200)]
feat: Don't treat /Zi as unsupported for clang-cl (#1266)
For MSVC /Zi is unsupported since it writes a additional
.pdb file per each .obj file and it creates some messy
interaction with ccache. But for clang-cl /Zi is actually
treated as /Z7 and only embeds the debug info in the .obj
file so it makes sense to allow this flag when compiling
with clang-cl.
Joel Rosdahl [Wed, 8 Mar 2023 07:10:27 +0000 (08:10 +0100)]
feat: Support overriding MSVC /Z* options
MSVC options /Zi and /ZI are too hard since they produce separate PDB
files. /Z7 is OK, but if the command line contains /Zi or /ZI followed
by /Z7, MSVC will use the latter (with a warning) but ccache will still
consider the command line too hard.
This commit makes ccache understand that only the last /Z* option will
be used and thus accepts the command line if the last /Z* option is /Z7.
Joel Rosdahl [Thu, 2 Mar 2023 17:14:49 +0000 (18:14 +0100)]
feat: Improve cache size presentation and specification
Aligned how cache size is presented (in "ccache --show-stats", "ccache
--show-compression", "ccache --recompress", debug logs, etc.) and
specified (in configuration files, "ccache --max-size" and "ccache
--trim-max-size"). The size units are now formatted according to the
type of size unit prefix used for the max_size/CCACHE_MAXSIZE setting: a
decimal size unit prefix (k/M/G/T with or without B for bytes) in
max_size means using decimal size unit prefix for presented sizes, and
similar for binary size unit prefixes (Ki/Mi/Gi/Ti with or without B for
bytes). If no unit is specified, GiB is assumed, . For example, "ccache -M
10" means 10 GiB.
Also aligned how cache sizes are calculated. Now all sizes are computed
as "apparent size", i.e., rounded up to the disk block size. This means
that the cache size in "--show-stats" and the sizes presented in
"--show-compression" and "--recompress" now match.
Joel Rosdahl [Wed, 8 Feb 2023 21:24:01 +0000 (22:24 +0100)]
fix: Log config and command line before finding compiler
If the compiler can't be found then ccache exits early and doesn't print
the config and command line to the log. This makes it harder to debug
problems with finding the compiler, like issue #1249.
Improve this by logging "safe things" before searching for the compiler.
Joel Rosdahl [Fri, 3 Feb 2023 12:11:57 +0000 (13:11 +0100)]
fix: Handle Unix-style paths as non-options to MSVC
For MSVC, ccache treats all arguments starting with a slash as an
option, which makes it fail to detect the source code file if it's
passed as a Unix-style absolute path.
Fix this by not treating an argument as an option if it's (a) an unknown
option, and (b) the argument exists as a file in the file system.
Joel Rosdahl [Mon, 30 Jan 2023 20:23:43 +0000 (21:23 +0100)]
build: Fix Zstd and Hiredis downloads for unstable GitHub archives
The content of the Zstd and Hiredis GitHub source achive URLs like
<https://github.com/$X/$Y/archive/$tag.tar.gz> apparently change from
time to time. Color me surprised. [1] says that this is intentional
(although, at the time of writing, reverted temporarily). Let's use
another URL for Zstd and not verify the checksum for Hiredis (since
there is no release source archive).
Joel Rosdahl [Sun, 29 Jan 2023 12:12:30 +0000 (13:12 +0100)]
fix: Cache path relativization in preprocessed output
After PR #1033 and [1], a stat call is made each time a note about an
include file is found in the preprocessed output. Such calls are very
performant on Linux (and therefore unnoticed until now), but apparently
costly on Windows.
Fix this by caching the calculation of relative paths in
process_preprocessed_file.
Joel Rosdahl [Mon, 23 Jan 2023 21:14:54 +0000 (22:14 +0100)]
fix: Disable inode cache if filesystem risks getting full soon
Some filesystems, for instance btrfs with compression enabled,
apparently make a posix_fallocate call succeed without actually
allocating the requested space for the file. This means that if the file
is mapped into memory, like done by the inode cache, the process can
crash when accessing the memory if the filesystem is full.
This commit implements a workaround: the inode cache is disabled if the
filesystem reports that it has less than 100 MiB free space. The free
space check is valid for one second before it is done again. This should
hopefully make crashes very rare in practice.
Joel Rosdahl [Fri, 27 Jan 2023 12:09:25 +0000 (13:09 +0100)]
feat: Allow forcing download of zstd and hiredis again
Before it was possible to force downloading of the Zstandard library
using "-D ZSTD_FROM_INTERNET=ON" and similar for Hiredis. That ability
was lost in 2c742c2c7ca9, so if you for some reason want to not use a
locally installed library you're out of luck.
Improve this by letting ZSTD_FROM_INTERNET and HIREDIS_FROM_INTERNET be
tristate variables:
ON: Always download
AUTO (default): Download if local installation not found
OFF: Never download
Joel Rosdahl [Thu, 5 Jan 2023 18:14:27 +0000 (19:14 +0100)]
feat: Improve automatic cache cleanup mechanism
The cache cleanup mechanism has worked essentially the same ever since
ccache was initially created in 2002:
- The total number and size of all files in one of the 16 subdirectories
(AKA level 1) are kept in the stats file in said subdirectory.
- On a cache miss, the new compilation result file is written (based on
the first digits of the hash) to a subdirectory of one of those 16
subdirectories, and the stats file is updated accordingly.
- Automatic cleanup is triggered if the size of the level 1 subdirectory
becomes larger than max_size / 16.
- ccache then lists all files in the subdirectory recursively, stats
them to check their size and mtime, sorts the file list on mtime and
deletes the 20% oldest files.
Some problems with the approach described above:
- (A) If several concurrent ccache invocations result in a cache miss
and write their results to the same subdirectory then all of them will
start cleaning up the same subdirectory simultaneously, doing
unnecessary work.
- (B) The ccache invocation that resulted in a cache miss will perform
cleanup and then exit, which means that an arbitrary ccache process
that happens to trigger cleanup will take a long time to finish.
- (C) Listing all files in a subdirectory of a large cache can be quite
slow.
- (D) stat-ing all files in a subdirectory of a large cache can be quite
slow.
- (E) Deleting many files can be quite slow.
- (F) Since a cleanup by default removes 20% of the files in a
subdirectory, the actual cache size will (once the cache limit is
reached) on average hover around 90% of the configured maximum size,
which can be confusing.
This commit solves or improves on all of the listed problems:
- Before starting automatic cleanup, a global "auto cleanup" lock is
acquired (non-blocking) so that at most one process is performing
cleanup at a time. This solves the potential "cache cleanup stampede"
described in (A).
- Automatic cleanup is now performed in just one of the 256 level 2
directories. This means that a single cleanup on average will be 16
times faster than before. This improves on (B), (C), (D) and (E) since
the cleanup made by a single compilation will not have to access a
large part of the cache. On the other hand, cleanups will be triggered
16 times more often, but the cleanup duty will be more evenly spread
out during a build.
- The total cache size is calculated and compared with the configured
maximum size before starting automatic cleanup. This, in combination
with performing cleanup on level 2, means that the actual cache size
will stay very close to the maximum size instead of about 90%. This
solves (F).
The limit_multiple configuration option has been removed since it is no
longer used.
Joel Rosdahl [Thu, 5 Jan 2023 10:07:06 +0000 (11:07 +0100)]
enhance: Make it possible for LockFile::try_acquire to break the lock
If a long-lived lock is stale and has no alive file,
LockFile::try_acquire will never succeed to acquire the lock. Fix this
by creating the alive file for all lock types and making
LockFile::try_acquire exit when lock activity is seen instead of
immediately after failing to acquire the lock.
Another advantage is that a stale lock can now always be broken right
away if the alive file exists.
Joel Rosdahl [Fri, 30 Dec 2022 20:49:23 +0000 (21:49 +0100)]
fix: Avoid sometimes too wide percent figure in --show-stats
If the nominator is 99999 and the denominator is 100000, the percent
function in Statistics.cpp would return "(100.00%)" instead of the
wanted "(100.0%)". Fix this by using the alternate format string if the
result string overflows its target size.
Joel Rosdahl [Tue, 29 Nov 2022 20:54:08 +0000 (21:54 +0100)]
feat: Do clean/clear/evict-style operations per level 2 directory
Progress bars will now be smoother since the operations are now divided
into 256 instead of 16 "read files + act on files" steps. This is also
in preparation for future improvements related to cache cleanup.