See also <<_location_of_the_primary_configuration_file,LOCATION OF THE
PRIMARY CONFIGURATION FILE>>.
-[[config_cache_dir_levels]] *cache_dir_levels* (*CCACHE_NLEVELS*)::
-
- This setting allows you to choose the number of directory levels in the
- cache directory. The default is 2. The minimum is 1 and the maximum is 8.
-
[[config_compiler]] *compiler* (*CCACHE_COMPILER* or (deprecated) *CCACHE_CC*)::
This setting can be used to force the name of the compiler to use. If set
absolute_paths_in_stderr,
base_dir,
cache_dir,
- cache_dir_levels,
compiler,
compiler_check,
compression,
{"absolute_paths_in_stderr", ConfigItem::absolute_paths_in_stderr},
{"base_dir", ConfigItem::base_dir},
{"cache_dir", ConfigItem::cache_dir},
- {"cache_dir_levels", ConfigItem::cache_dir_levels},
{"compiler", ConfigItem::compiler},
{"compiler_check", ConfigItem::compiler_check},
{"compression", ConfigItem::compression},
{"LOGFILE", "log_file"},
{"MAXFILES", "max_files"},
{"MAXSIZE", "max_size"},
- {"NLEVELS", "cache_dir_levels"},
{"PATH", "path"},
{"PCH_EXTSUM", "pch_external_checksum"},
{"PREFIX", "prefix_command"},
case ConfigItem::cache_dir:
return m_cache_dir;
- case ConfigItem::cache_dir_levels:
- return fmt::format("{}", m_cache_dir_levels);
-
case ConfigItem::compiler:
return m_compiler;
set_cache_dir(Util::expand_environment_variables(value));
break;
- case ConfigItem::cache_dir_levels:
- m_cache_dir_levels = Util::parse_unsigned(value, 1, 8, "cache_dir_levels");
- break;
-
case ConfigItem::compiler:
m_compiler = value;
break;
bool absolute_paths_in_stderr() const;
const std::string& base_dir() const;
const std::string& cache_dir() const;
- uint32_t cache_dir_levels() const;
const std::string& compiler() const;
const std::string& compiler_check() const;
bool compression() const;
bool m_absolute_paths_in_stderr = false;
std::string m_base_dir = "";
std::string m_cache_dir;
- uint32_t m_cache_dir_levels = 2;
std::string m_compiler = "";
std::string m_compiler_check = "mtime";
bool m_compression = true;
return m_cache_dir;
}
-inline uint32_t
-Config::cache_dir_levels() const
-{
- return m_cache_dir_levels;
-}
-
inline const std::string&
Config::compiler() const
{
std::string& stats_file_var) const
{
std::string name_string = name.to_string();
- path_var = Util::get_path_in_cache(
- config.cache_dir(), config.cache_dir_levels(), name_string, suffix);
+ path_var =
+ Util::get_path_in_cache(config.cache_dir(), 2, name_string, suffix);
stats_file_var =
fmt::format("{}/{}/stats", config.cache_dir(), name_string[0]);
}
std::string
get_path_in_cache(string_view cache_dir,
- uint32_t levels,
+ uint8_t level,
string_view name,
string_view suffix)
{
- assert(levels >= 1 && levels <= 8);
- assert(levels < name.length());
+ assert(level >= 1 && level <= 8);
+ assert(name.length() >= level);
std::string path(cache_dir);
- path.reserve(path.size() + levels * 2 + 1 + name.length() - levels
+ path.reserve(path.size() + level * 2 + 1 + name.length() - level
+ suffix.length());
- uint32_t level = 0;
- for (; level < levels; ++level) {
+ for (uint8_t i = 0; i < level; ++i) {
path.push_back('/');
- path.push_back(name.at(level));
+ path.push_back(name.at(i));
}
path.push_back('/');
std::string get_relative_path(nonstd::string_view dir,
nonstd::string_view path);
-// Join `cache_dir`, a '/', `name`, and `suffix` into a single path and return
-// it. Additionally `levels` single-character, '/'-separated subpaths are split
+// Join `cache_dir`, a '/', `name` and `suffix` into a single path and return
+// it. Additionally, `level` single-character, '/'-separated subpaths are split
// from the beginning of `name` before joining them all.
-//
-// `levels` must be less than the length of `name` and in the interval [1,8].
-//
-// E.g. "ABCDEF" and ".foo" will become "/ccache/A/B/CDEF.foo" when the cache
-// directory is "/ccache" and cache dir levels is 2.
std::string get_path_in_cache(nonstd::string_view cache_dir,
- uint32_t levels,
+ uint8_t level,
nonstd::string_view name,
nonstd::string_view suffix);
expect_stat 'cache hit (preprocessed)' 2
expect_stat 'cache miss' 1
- # -------------------------------------------------------------------------
- TEST "CCACHE_NLEVELS"
-
- CCACHE_NLEVELS=4 $CCACHE_COMPILE -c test1.c
- expect_stat 'cache hit (preprocessed)' 0
- expect_stat 'cache miss' 1
- expect_stat 'files in cache' 1
-
- CCACHE_NLEVELS=4 $CCACHE_COMPILE -c test1.c
- expect_stat 'cache hit (preprocessed)' 1
- expect_stat 'cache miss' 1
- expect_stat 'files in cache' 1
-
- # Directories in $CCACHE_DIR:
- # - .
- # - tmp
- # - a
- # - a/b
- # - a/b/c
- # - a/b/c/d
- actual_dirs=$(find $CCACHE_DIR -type d | wc -l)
- if [ -d /run/user/$(id -u) ]; then
- expected_dirs=5
- else
- expected_dirs=6
- fi
- if [ $actual_dirs -ne $expected_dirs ]; then
- test_failed "Expected $expected_dirs directories, found $actual_dirs"
- fi
-
# -------------------------------------------------------------------------
TEST "CCACHE_EXTRAFILES"
CHECK(config.base_dir().empty());
CHECK(config.cache_dir().empty()); // Set later
- CHECK(config.cache_dir_levels() == 2);
CHECK(config.compiler().empty());
CHECK(config.compiler_check() == "mtime");
CHECK(config.compression());
"\n"
"\n"
" #A comment\n"
- " cache_dir_levels = 4\n"
"\t compiler = foo\n"
"compiler_check = none\n"
"compression=false\n"
REQUIRE(config.update_from_file("ccache.conf"));
CHECK(config.base_dir() == base_dir);
CHECK(config.cache_dir() == fmt::format("{0}$/{0}/.ccache", user));
- CHECK(config.cache_dir_levels() == 4);
CHECK(config.compiler() == "foo");
CHECK(config.compiler_check() == "none");
CHECK_FALSE(config.compression());
Util::write_file("ccache.conf", "base_dir =");
CHECK(config.update_from_file("ccache.conf"));
}
-
- SUBCASE("bad dir levels")
- {
- Util::write_file("ccache.conf", "cache_dir_levels = 0");
- try {
- config.update_from_file("ccache.conf");
- CHECK(false);
- } catch (const Error& e) {
- CHECK(std::string(e.what())
- == "ccache.conf:1: cache_dir_levels must be between 1 and 8");
- }
-
- Util::write_file("ccache.conf", "cache_dir_levels = 9");
- try {
- config.update_from_file("ccache.conf");
- CHECK(false);
- } catch (const Error& e) {
- CHECK(std::string(e.what())
- == "ccache.conf:1: cache_dir_levels must be between 1 and 8");
- }
- }
}
TEST_CASE("Config::update_from_environment")
"base_dir = C:/bd\n"
#endif
"cache_dir = cd\n"
- "cache_dir_levels = 7\n"
"compiler = c\n"
"compiler_check = cc\n"
"compression = true\n"
"(test.conf) base_dir = C:/bd",
#endif
"(test.conf) cache_dir = cd",
- "(test.conf) cache_dir_levels = 7",
"(test.conf) compiler = c",
"(test.conf) compiler_check = cc",
"(test.conf) compression = true",