Joel Rosdahl [Tue, 9 Apr 2024 17:47:44 +0000 (19:47 +0200)]
feat: Clear manifest on recache
If there are bad entries in the manifest it doesn't help to run with
recache if the new entry (resulting from the recached compilation)
already exists as an older entry in the manifest.
Improve this by not populating the manifest in recache mode.
Kreijstal [Sat, 23 Mar 2024 15:07:49 +0000 (16:07 +0100)]
fix: Adapt util::LockFile to MSYS2 (#1416)
MSYS2 will not let you create a symlink to a nonexistent file, only to
an already existing file. To overcome this issue we use files, and write
content on it.
For Cygwin/MSYS2, the patch leverages POSIX `open` with the flags
`O_WRONLY | O_CREAT | O_EXCL`, effectively creating an exclusive lock
file. As suggested by @jrosdahl , thank you so much for the suggestion.
This still does not pass the test suite, but makes ccache usable.
Joel Rosdahl [Sat, 16 Mar 2024 13:42:00 +0000 (14:42 +0100)]
fix: Reduce the risk of false positive direct mode hits
To reduce the risk of getting a false positive hit when a directory
early in the include path now exists, record whether include directories
and similar input paths exist. Note that this is not 100% waterproof
since it only detects newly appearing directories and not newly
appearing header files.
Joel Rosdahl [Wed, 21 Feb 2024 21:03:43 +0000 (22:03 +0100)]
chore: Improve source tree structure
In preparation for adding support for using dependencies from the system
in addition to bundled or downloaded dependencies, restructure the
source tree so that:
- Third party headers are included without a third_party/ prefix, e.g.
#include <xxhash.h> instead of #include <third_party/xxhash.h>.
- Ccache headers are included with a ccache/ prefix, e.g. #include
<ccache/util/string.hpp> instead of #include <util/string.hpp>.
This keeps ccache and other headers separated but in another way than
before.
Joel Rosdahl [Wed, 21 Feb 2024 20:20:58 +0000 (21:20 +0100)]
chore: Remove internal tracing framework
The internal tracing calls enabled by ENABLE_TRACING work fine, but I
have found that I never use them or add tracepoints to new code, so in
reality they mostly contribute with dead weight. In an effort to reduce
the amount of dependencies, I have therefore decided to remove the trace
calls, including the bundled minitrace sources.
Joel Rosdahl [Wed, 21 Feb 2024 19:25:03 +0000 (20:25 +0100)]
fix: Allow nonexistent include files in preprocessor mode
After 43c3a44aadcb nonexistent include files found in the preprocessed
output would increment "Could not read or parse input file" and fall
back to just running the compiler. This made ccache not attempt
preprocessor mode for generated code with #line header referencing files
that can't be found, e.g. in an out-of-source build scenario.
Fix this by just disabling direct mode, restoring the pre-43c3a44aadcb
behavior in such cases.
Thomas Ferrand [Sun, 11 Feb 2024 15:11:47 +0000 (16:11 +0100)]
feat: Port the inode cache to Windows (#1388)
This PR ports the existing InodeCache to make it work under Windows.
This speeds up ccache a lot, both in the hit and miss cases, when a lot
of headers files are included in several compilation units. In our case
this makes the difference between ccache being worth using or not.
The logic of the InodeCache itself is unchanged. I introduced a
MemoryMap helper class that does the platform specific calls to
mmap/MapViewOfFile. Despite its generic name, I've implemented what was
needed for the InodeCache, it only supports mapping a file (no anonymous
mmap) in a shared fashion with read/write access.
Due to differences in behavior between unix and Windows regarding
unlinking a file that is opened, I am not convinced that it will work
correctly in every situation (for example if a process hold a bucket
lock for more than 5 seconds, the cache is dropped and recreated, under
Windows that won't work as the unlink will fail). That being said it
seems to work well enough when nothing unexpected happens.
I made a small change to the unit test because under Windows, we can't
open() a directory so instead I try to open a temp file in that
directory. After that change the unit tests pass unmodified.
For the bash based test, only the symbolic link test fails. This is
quite strange, when I try to run the test, the call to `ln -fs test1.c
test2.c` fails, but when run manually the same command succeeds. I tried
to run the test manually and it fails anyway but I haven't done anything
to fix it, this looks like more an issue from the DirEntry side than the
InodeCache side. Because of that I've left the bash based test disabled
for Windows, maybe we want to change that to only disable the symbolic
link test?
Joel Rosdahl [Sat, 10 Feb 2024 08:54:19 +0000 (09:54 +0100)]
fix: Fix reading of files larger than 2^31 bytes
For some kernels read(2) makes a short read for counts larger than 2^31,
even for files on 64-bit architectures. Other kernels seem to not like
large counts at all, returning a failure.
Fix this by limiting the read buffer to a smaller value. This also
removes a short read optimization which should have been removed in cff3bf417420ea88fe53e7267ae2a356898ae326.
Joel Rosdahl [Wed, 7 Feb 2024 20:09:02 +0000 (21:09 +0100)]
chore: Further improve /Tc and /Tp handling
- Remember if /Tc or /Tp was used and prepend it to the source file sent
to the preprocessor and compiler.
- Mark non-concatenated versions of /Tc and /Tp as too hard for now.
Joel Rosdahl [Mon, 5 Feb 2024 18:51:49 +0000 (19:51 +0100)]
fix: Fix MSVC crash when using /Zi /Fddebug.pdb
With /Zi, MSVC starts a long-lived mspdbsrv.exe background process. The
implementation of #1274 kills all processes created by ccache including
mspdbsrv.exe, which can make cl.exe crash with this error message:
Joel Rosdahl [Sun, 14 Jan 2024 09:46:54 +0000 (10:46 +0100)]
fix: Disable caching for modified source/include files
On a cache miss, ccache opts out of the direct mode when a "too new"
include file is found. This is done to avoid a race condition in the
direct mode when a header file if modified after ccache is invoked but
before the compiler is executed. Modifying the main source code file is
not a race condition when "run_second_cpp = false", which was the case
at the time the direct mode was introduced. However, the default of
run_second_cpp was changed to true in ccache 3.3, and the potiential
race condition then exists for both the source and the include files.
Fix this by disabling caching completely (not only the direct mode) when
modification of a source/include file is detected.