summaryrefslogtreecommitdiff
path: root/src/Context.cpp
Commit message (Collapse)AuthorAgeFilesLines
* feat: Add support for setting per-compilation config on command lineJoel Rosdahl2023-02-201-4/+5
| | | | Closes #1035.
* refactor: Use util::TimePoint for timestampsJoel Rosdahl2022-09-211-4/+2
|
* feat: Include timestamp in per-object debug filenamesJoel Rosdahl2022-06-111-0/+5
| | | | | | | Including a timestamp in the filenames makes it easier to compare two builds without having to save previous debug files before the second build. It also makes sure debug files won't be overwritten if an object file is compiled several times during one build.
* fix: Add and use Util::{get,set}_umask functionsJoel Rosdahl2022-06-081-1/+1
| | | | | | | | | | | | | Using mode_t mask = umask(0); umask(mask); to retrieve the current umask isn't thread-safe. This messed up file permissions when recompressing the cache. Fix this by caching the last set value and always using Util::{get,set}_umask to get and set the umask.
* chore: Replace nonstd::string_view with std::string_viewJoel Rosdahl2022-05-231-3/+1
|
* fix: Don’t read let Context read user configuration in unit testsJoel Rosdahl2021-08-071-0/+5
| | | | | | | | | accd21e4 inadvertently made unit tests populate Context::config from the environment and the user configuration. Fix this by moving code for reading config, setting of logging, etc. into a separate method only to be called by non-test code. As noted by Michael Kruse in #815.
* Move/split statistics functionality into core and storage::primaryJoel Rosdahl2021-07-221-1/+0
| | | | | | | | | | | - The Counters class has been moved to core::StatisticsCounters. - Functionality in the Statistics namespace has been split into: - core::StatsLog: Knows about “stats log” format. - core::Statistics: Knows about properties of statistics fields and how to present them. - storage::primary::PrimaryStorage: Knows how to store and update statistics in the primary storage backend. - storage::primary::StatsFile: Knows about the “stats file” format.
* Remove redundant _utils suffix for util headersJoel Rosdahl2021-07-191-1/+1
|
* Remove system.hpp, including what’s needed insteadJoel Rosdahl2021-07-071-0/+5
| | | | This is the next step after a57f70eda32e99221de56f5499079b4f00dc2bc5.
* Add util::split_path_list function and remove PATH_DELIM macroJoel Rosdahl2021-07-061-1/+3
|
* Improve parsing of umask valuesJoel Rosdahl2021-06-271-2/+2
|
* Refactor main primary storage backend code into storage/primaryJoel Rosdahl2021-06-271-2/+3
| | | | This is the code that deals with retrieving and storing cache entries.
* Refactor config and context setupJoel Rosdahl2021-06-271-0/+16
|
* Add preprocessed file extension to cpp stdout earlyJoel Rosdahl2020-12-261-4/+6
| | | | | | | | | | | | | | | | Unless when compiling a preprocessed file directly, ccache creates a temporary file to store the output of the preprocessor, registers the file for removal at program exit, renames the file to one with a .i/.ii extension and then registers that file for removal as well. This works by chance in practice as long as mkstemp() returns something with low probability of being reused, but as discussed in #736 it risks failing when mkstemp() doesn’t behave that way. Fix this by creating the new name (with the needed extension) using a hard link so that the original file will outlive the new file, thus blocking another ccache process from creating a file with the same name again. To make the new temporary file outlive the old file, also delete pending temporary files in LIFO order.
* Detect errors in log strings at compile timeJoel Rosdahl2020-10-231-2/+1
| | | | | | | | | | | | | | | | | | | 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.
* Implement support for automatic cache levelsJoel Rosdahl2020-09-231-40/+0
| | | | | | This makes ccache choose an appropriate cache level structure automatically based on a maximum number of files per directory, currently hardcoded to 2000.
* Remove unnecessary suffix parameter from Util::get_path_in_cacheJoel Rosdahl2020-09-171-3/+2
|
* Remove cache_dir_levels (CCACHE_NLEVELS) settingJoel Rosdahl2020-09-171-2/+2
| | | | | | | | | 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.
* Refactor remaining stats_* functions into StatisticsJoel Rosdahl2020-09-141-1/+0
|
* Refactor flushing of stats and logs at ccache exitJoel Rosdahl2020-09-141-7/+0
| | | | | | | | | | 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.
* Don’t create <objectfile>.ccache-log when there is no object fileJoel Rosdahl2020-09-081-1/+1
| | | | Fixes #656.
* Convert cc_log calls to Logging::logJoel Rosdahl2020-08-031-2/+3
|
* C++-ify logging routinesJoel Rosdahl2020-08-031-2/+2
| | | | | | | | | | | | | | | - Simplified and C++-ified logging code. - Added Logging::log and Logging::bulk_log functions corresponding to the old cc_log and cc_bulklog functions. The new functions pass their arguments to fmt::format. - Replacements: * init_log → Logging::init * cc_log → Logging::log * cc_bulklog → Logging::bulk_log * cc_log_argv → Logging::log plus Util::format_argv_for_logging * cc_dump_debug_log_buffer -> Logging::dump_log - A legacy cc_log implementation is still available so that logging can be converted gradually to the new functionality.
* Remove superfluous hash_from_int functionJoel Rosdahl2020-07-291-2/+2
|
* C++-ify stats functionsJoel Rosdahl2020-07-261-1/+1
|
* Simplify code somewhatJoel Rosdahl2020-07-091-1/+1
|
* Add ability to ignore specified compiler options when hashing (#620)Ryan Egesdahl2020-07-091-0/+18
| | | | Closes #578.
* Implement some suggestions from clang-tidy 10Joel Rosdahl2020-06-231-1/+1
|
* Add Digest class, replacing struct digestJoel Rosdahl2020-06-141-5/+4
|
* Add inode cache for file hashes (#577)Olle Liljenzin2020-05-311-0/+4
| | | | | | | | | | | | | The inode cache is a process shared cache that maps from device, inode, size, mtime and ctime to saved hash results. The cache is stored persistently in a single file that is mapped into shared memory by running processes, allowing computed hash values to be reused both within and between builds. The chosen technical solution works for Linux and might work on other POSIX platforms, but is not meant to be supported on non-POSIX platforms such as Windows. Use 'ccache -o inode_cache=true/false' to activate/deactivate the cache.
* Refactor signal handling and process exit codeJoel Rosdahl2020-05-201-0/+44
| | | | | | | | | | * Added a SignalHandler class which encapsulates parts related to signal handling. * Moved data referenced by the exit functions to Context (compiler PID, pending temporary files and pending debug log files). * Let the Context destructor do what the exitfn functionality used to do. * Removed the now superfluous exitfn functionality.
* Move calculation of “result/manifest globals” into ContextJoel Rosdahl2020-04-191-0/+45
|
* C++-ify Context::result_nameJoel Rosdahl2020-04-191-5/+0
|
* C++-ify Context::ignore_headersJoel Rosdahl2020-04-181-5/+0
|
* Add an Args class with backward compatibility for the old args API (#575)Joel Rosdahl2020-04-071-3/+0
| | | | | | | | | | | | | | | | | | | | | | | The idea of this is to make a proper C++ API while at the same time implementing most of the old legacy args API. This makes it possible to refactor call sites gradually instead of in a series of large refactoring steps. Given that “struct args* args” is replaced with “Args args”, the following types of legacy API usage can be kept without source changes: 1. The args_* functions can be used as is. 2. args->argv[i] still works for read access. Things that aren’t emulated: 1. args->argc (use args.size() instead). 2. args->argv to access the underlying char* array (use args.to_argv().data() instead). 3. Mutating the args->argv[i] string in place (don’t do that). In other words, code that uses args_foo(args, ...) and args->argv[i] can easily be converted to args.bar(...) and args[i] (with std::string arguments instead of char*) at will and in arbitrarily small steps.
* Convert counters to a class (#548)Thomas Otto2020-03-011-3/+1
| | | | Also remove file writing logic from `stats_update_size()` and delete unused declaration of `stats_timestamp()`.
* Context: move countersThomas Otto2020-02-171-0/+3
|
* Context: move ignore_headers_len, remove cc_reset()Thomas Otto2020-02-171-0/+5
|
* Context: move (cached_)result_name/result_pathThomas Otto2020-02-171-0/+2
| | | | Also convert result_path to std::string.
* Improve functions related to CWDJoel Rosdahl2020-02-161-0/+7
| | | | | | | | | | | | | | | | | | | | The different functions related to current working directory (CWD) have become messy during the years: - gnu_getcwd is a simple wrapper around getcwd(3), thus returning the actual canonical path. - get_cwd returns $PWD, falling back to getcwd(3) if $PWD is not sane. - get_current_working_dir (local function in ccache.cpp) memoizes x_realpath(get_cwd()) (i.e., getcwd(3) in essence...) in the global current_working_dir variable. Unit tests may manipulate current_working_dir. Improve this by: - Replacing gnu_getcwd with Util::get_actual_cwd. - Replacing get_cwd with Util::get_apparent_cwd. - Removing get_current_working_dir and placing both actual and apparent CWD in the context object.
* Simplify (non-)freeing of orig_args on failureJoel Rosdahl2020-02-161-3/+1
|
* Context: move orig_argsThomas Otto2020-02-161-0/+5
|
* Context: convert stats_file to an std::stringThomas Otto2020-02-161-1/+0
| | | | Also adapted downstream stats functions.
* Context: move stats_fileThomas Otto2020-02-161-0/+1
|
* Context struct added, returned by initialize()Thomas Otto2020-02-101-0/+23
The goal is to eventually move almost all global state into Context.