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.
Joel Rosdahl [Tue, 1 Sep 2020 17:48:24 +0000 (19:48 +0200)]
Improve test cases that use objdump
- Added expect_objdump_contains and expect_objdump_not_contains utility
functions to the main test framework, making objdump_cmd and grep_cmd
(renamed to objdump_grep_cmd) internal utility functions.
- Removed strange support for the $HOST_OS_WINDOWS || $HOST_OS_CYGWIN
case in objdump_grep_cmd. Let’s re-add it later if and when it becomes
a problem.
- objdump_grep_cmd now greps for literal strings, thus no longer
interpreting $PWD as a regex.
- Made test cases use expect_objdump_(not_)contains instead of
“objdump_grep_cmd | grep_cmd”.
Joel Rosdahl [Tue, 1 Sep 2020 14:51:32 +0000 (16:51 +0200)]
Fix debug_prefix_map failure with old objdump versions
“objdump -g” does not list debug info like the “Multiple
-fdebug-prefix-map” test expects when using objdump 2.20, e.g. on CentOS
6. “objdump -W” does however work, and it seems to work for object files
with compressed .debug_str section as well.
Joel Rosdahl [Mon, 31 Aug 2020 08:30:38 +0000 (10:30 +0200)]
Improve handling of ccache version in the source release archive
The version.cpp file is currently generated in the source directory.
This is a bit unclean since generated files are supposed to be put in
the build directory.
Also, when building from a source release archive outside a Git
repository the CMake scripts still try to get the version from Git and
then emit an ugly warning message:
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
CMake Warning at cmake/GenerateVersionFile.cmake:42 (message):
Running git failed
Call Stack (most recent call first):
cmake/GenerateVersionFile.cmake:50 (get_version_from_git)
CMakeLists.txt:32 (include)
Fix this by including a VERSION file in the source release archive. If
the VERSION file exists, GenerateVersionFile.cmake just uses the version
from the file and doesn’t try to get a version from Git. If the file
doesn’t exist, the version is looked up from Git like before, but it’s a
fatal error if the version cannot be determined.
Rafael Kitover [Thu, 27 Aug 2020 19:23:26 +0000 (19:23 +0000)]
Support building on MSVC (#632)
With these changes, the project builds with Visual Studio 2019, unit
tests pass and it works correctly with mingw gcc.
NOTE: The very latest version of Visual Studio 2019 is required, because
there was just a necessary fix for template arguments.
Tested building and running unit tests on Windows+MSVC, Windows+MinGW,
Linux and macOS.
- Enable `ZSTD_FROM_INTERNET` by default for MSVC when not using vcpkg
or conan.
- Add include tests for some standard UNIX headers not available on
MSVC.
- Add necessary MSVC compiler flags.
- In `Args::from_gcc_atfile()` iterate over the string via `c_str()`
instead of `cbegin()`, the MSVC string character iterator does not
include the ending null byte.
- Misc. minor cmake fix-ups.
- Add some headers that are not implicitly included from other headers
like `<algorithm>`, `<ios>`, `<cstdint>` and `<cstdarg>` in some
places, gcc does this but MSVC does not.
- Add `std::filesystem` version of `Util::traverse()` when dirent.h is
not available, which is preferred for performance reasons.
- Add implementations of the following functions that are not available
in MSVC in Win32Util.cpp: `gettimeofday()`, `localtime_r()`,
`asprintf()`.
- Add Windows implementation of `getopt_long()` from
https://www.codeproject.com/Articles/157001/Full-getopt-Port-for-Unicode-and-Multibyte-Microso
to third_party/win32.
- Add some compatibility typedefs, constants and macros to the `_WIN32`
section of system.hpp, as well as the prototypes for the functions
added to Win32Util.cpp.
- Fix up unit tests expecting '/' separated paths to expect paths
delimited by `DIR_DELIM_CH`.
- Invoke test/run with bash from cmake, necessary on msys2+mingw64, many
fail, there is more work to do here.
- Set the warning level to `/W4` and silence all the uninteresting
warning types. Compiles with no warnings now.
- Switch to using standard C++ attributes `[[nodiscard]]` and
`[[maybe_unused]]` and define macros for gcc for their equivalents.
- `#define DOCTEST_CONFIG_USE_STD_HEADERS` for MSVC only, because it
requires explicitly including `<ostream>`.
- Add vim files to .gitignore.
Signed-off-by: Rafael Kitover <rkitover@gmail.com>
Alexander Lanin [Thu, 27 Aug 2020 19:18:56 +0000 (21:18 +0200)]
Fix asm compiler detection (#644)
CMake requires ASM to be the last parameter so it can try whether the C compiler can compile asm.
See https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1560/diffs
Joel Rosdahl [Sun, 23 Aug 2020 18:11:30 +0000 (20:11 +0200)]
build.yaml: Use build type CI by default
I think that it makes sense to use a ccache binary built in release mode
in CI tests by default since that is what the end user will actually
run. At the same time we want to test assertions in CI, so use the CI
build type which is RelWithDebInfo but without -DNDEBUG. I here assume
that the difference between -O3 (from build type Release) and -O2 (from
build type RelWithDebInfo) is small.
Changed OS to Ubuntu 20.04 for “Linux MinGW 64-bit” since the cross
compiler in Ubuntu 18.04 is buggy.