]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Use some generic lambda expressions
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 18 Jun 2021 19:09:12 +0000 (21:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 19 Jun 2021 17:58:58 +0000 (19:58 +0200)
14 files changed:
dockerfiles/ubuntu-14.04/Dockerfile [deleted file]
src/Args.cpp
src/Config.cpp
src/InodeCache.cpp
src/InodeCache.hpp
src/Statistics.cpp
src/Util.cpp
src/ccache.cpp
src/cleanup.cpp
src/compress.cpp
unittest/test_Config.cpp
unittest/test_Statistics.cpp
unittest/test_Util.cpp
unittest/test_ccache.cpp

diff --git a/dockerfiles/ubuntu-14.04/Dockerfile b/dockerfiles/ubuntu-14.04/Dockerfile
deleted file mode 100644 (file)
index 5b3d1db..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-FROM ubuntu:14.04
-
-RUN apt-get update \
- && apt-get install -y --no-install-recommends \
-        asciidoc \
-        bash \
-        build-essential \
-        ccache \
-        clang-3.4 \
-        curl \
-        docbook-xml \
-        docbook-xsl \
-        elfutils \
-        g++-multilib \
-        ninja-build \
-        wget \
-        xsltproc \
- && rm -rf /var/lib/apt/lists/*
-
-# Redirect all compilers to ccache.
-RUN for t in gcc g++ cc c++ clang clang++; do ln -vs /usr/bin/ccache /usr/local/bin/$t; done
-
-# The distribution's CMake it too old (2.8.12.2).
-RUN curl -sSL https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz | sudo tar -xzC /opt \
- && cp -a /opt/cmake-3.5.2-Linux-x86_64/bin /usr/local \
- && cp -a /opt/cmake-3.5.2-Linux-x86_64/share /usr/local
index 5270989d7dadf80ce94b01e867db432f0c092143..a1913299f6f57ed9b32b62634f1702559a8416b5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -169,7 +169,7 @@ Args::erase_with_prefix(string_view prefix)
 {
   m_args.erase(std::remove_if(m_args.begin(),
                               m_args.end(),
-                              [&prefix](const std::string& s) {
+                              [&prefix](const auto& s) {
                                 return Util::starts_with(s, prefix);
                               }),
                m_args.end());
index 06e35cabf1a24178df76110fe91438559fc0a06c..da26a24b5dcf670dc077d653cdec5d4c4b73eb91 100644 (file)
@@ -472,14 +472,12 @@ Config::set_secondary_config_path(std::string path)
 bool
 Config::update_from_file(const std::string& path)
 {
-  return parse_config_file(path,
-                           [&](const std::string& /*line*/,
-                               const std::string& key,
-                               const std::string& value) {
-                             if (!key.empty()) {
-                               set_item(key, value, nullopt, false, path);
-                             }
-                           });
+  return parse_config_file(
+    path, [&](const auto& /*line*/, const auto& key, const auto& value) {
+      if (!key.empty()) {
+        this->set_item(key, value, nullopt, false, path);
+      }
+    });
 }
 
 void
@@ -675,17 +673,16 @@ Config::set_value_in_file(const std::string& path,
   AtomicFile output(resolved_path, AtomicFile::Mode::text);
   bool found = false;
 
-  if (!parse_config_file(path,
-                         [&](const std::string& c_line,
-                             const std::string& c_key,
-                             const std::string& /*c_value*/) {
-                           if (c_key == key) {
-                             output.write(FMT("{} = {}\n", key, value));
-                             found = true;
-                           } else {
-                             output.write(FMT("{}\n", c_line));
-                           }
-                         })) {
+  if (!parse_config_file(
+        path,
+        [&](const auto& c_line, const auto& c_key, const auto& /*c_value*/) {
+          if (c_key == key) {
+            output.write(FMT("{} = {}\n", key, value));
+            found = true;
+          } else {
+            output.write(FMT("{}\n", c_line));
+          }
+        })) {
     throw Error("failed to open {}: {}", path, strerror(errno));
   }
 
index 5e473ec7e8464f7e2c208ae67fe3b9ef20ab872a..bcb11ce648802c1268692c79b10140543d4898a5 100644 (file)
@@ -369,7 +369,7 @@ InodeCache::get(const std::string& path,
   }
 
   bool found = false;
-  const bool success = with_bucket(key_digest, [&](Bucket* const bucket) {
+  const bool success = with_bucket(key_digest, [&](const auto bucket) {
     for (uint32_t i = 0; i < k_num_entries; ++i) {
       if (bucket->entries[i].key_digest == key_digest) {
         if (i > 0) {
@@ -422,7 +422,7 @@ InodeCache::put(const std::string& path,
     return false;
   }
 
-  const bool success = with_bucket(key_digest, [&](Bucket* const bucket) {
+  const bool success = with_bucket(key_digest, [&](const auto bucket) {
     memmove(&bucket->entries[1],
             &bucket->entries[0],
             sizeof(Entry) * (k_num_entries - 1));
index f2d049abdf5a5da20df78eeb08e930d39998e120..9ef330afad33acd428b4fe2c10ab31055bac2a5c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
index ba98a76c1817389b1d3ad52aa269a4d88a8d6308..a630857a1fb416e6b59586c2d9c6bd0dd0dc3241 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -102,14 +102,13 @@ Statistics::collect_counters(const Config& config)
   time_t last_updated = 0;
 
   // Add up the stats in each directory.
-  for_each_level_1_and_2_stats_file(
-    config.cache_dir(), [&](const std::string& path) {
-      counters.set(Statistic::stats_zeroed_timestamp, 0); // Don't add
-      counters.increment(Statistics::read(path));
-      zero_timestamp = std::max(counters.get(Statistic::stats_zeroed_timestamp),
-                                zero_timestamp);
-      last_updated = std::max(last_updated, Stat::stat(path).mtime());
-    });
+  for_each_level_1_and_2_stats_file(config.cache_dir(), [&](const auto& path) {
+    counters.set(Statistic::stats_zeroed_timestamp, 0); // Don't add
+    counters.increment(Statistics::read(path));
+    zero_timestamp =
+      std::max(counters.get(Statistic::stats_zeroed_timestamp), zero_timestamp);
+    last_updated = std::max(last_updated, Stat::stat(path).mtime());
+  });
 
   counters.set(Statistic::stats_zeroed_timestamp, zero_timestamp);
   return std::make_pair(counters, last_updated);
index 4a996e61168983cc3bff64f45b16f0234dfe23a1..ed6d78911286c216cff64cac8ef62c5995ce8072 100644 (file)
@@ -907,7 +907,7 @@ make_relative_path(const std::string& base_dir,
   const auto path_suffix = std::string(original_path.substr(path.length()));
   const auto real_path = Util::real_path(std::string(path));
 
-  const auto add_relpath_candidates = [&](nonstd::string_view path) {
+  const auto add_relpath_candidates = [&](auto path) {
     const std::string normalized_path = Util::normalize_absolute_path(path);
     relpath_candidates.push_back(
       Util::get_relative_path(actual_cwd, normalized_path));
@@ -924,7 +924,7 @@ make_relative_path(const std::string& base_dir,
   // Find best (i.e. shortest existing) match:
   std::sort(relpath_candidates.begin(),
             relpath_candidates.end(),
-            [](const std::string& path1, const std::string& path2) {
+            [](const auto& path1, const auto& path2) {
               return path1.length() < path2.length();
             });
   for (const auto& relpath : relpath_candidates) {
index 5b1db3b43807962e8f550dace79d678fe77c0830..bd8f2cb429279cf45855e22f461294d67acff304 100644 (file)
@@ -2169,10 +2169,9 @@ update_stats_and_maybe_move_cache_file(const Context& ctx,
   const auto stats_file =
     FMT("{}/{}/stats", ctx.config.cache_dir(), level_string);
 
-  auto counters =
-    Statistics::update(stats_file, [&counter_updates](Counters& cs) {
-      cs.increment(counter_updates);
-    });
+  auto counters = Statistics::update(stats_file, [&counter_updates](auto& cs) {
+    cs.increment(counter_updates);
+  });
   if (!counters) {
     return nullopt;
   }
@@ -2238,8 +2237,8 @@ finalize_stats_and_trigger_cleanup(Context& ctx)
     const auto bucket = getpid() % 256;
     const auto stats_file =
       FMT("{}/{:x}/{:x}/stats", config.cache_dir(), bucket / 16, bucket % 16);
-    Statistics::update(
-      stats_file, [&ctx](Counters& cs) { cs.increment(ctx.counter_updates); });
+    Statistics::update(stats_file,
+                       [&ctx](auto& cs) { cs.increment(ctx.counter_updates); });
     return;
   }
 
index 5c76ebbebafe5d0f85dab2cc8612cb7c3ebd2b44..20e6060b57ca36393c8be4c31ebc16a3c909bac1 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright (C) 2002-2006 Andrew Tridgell
-// Copyright (C) 2009-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2009-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -58,7 +58,7 @@ update_counters(const std::string& dir,
                 bool cleanup_performed)
 {
   const std::string stats_file = dir + "/stats";
-  Statistics::update(stats_file, [=](Counters& cs) {
+  Statistics::update(stats_file, [=](auto& cs) {
     if (cleanup_performed) {
       cs.increment(Statistic::cleanups_performed);
     }
@@ -74,8 +74,7 @@ clean_old(const Context& ctx,
 {
   Util::for_each_level_1_subdir(
     ctx.config.cache_dir(),
-    [&](const std::string& subdir,
-        const Util::ProgressReceiver& sub_progress_receiver) {
+    [&](const auto& subdir, const auto& sub_progress_receiver) {
       clean_up_dir(subdir, 0, 0, max_age, sub_progress_receiver);
     },
     progress_receiver);
@@ -119,10 +118,9 @@ clean_up_dir(const std::string& subdir,
   }
 
   // Sort according to modification time, oldest first.
-  std::sort(
-    files.begin(), files.end(), [](const CacheFile& f1, const CacheFile& f2) {
-      return f1.lstat().mtime() < f2.lstat().mtime();
-    });
+  std::sort(files.begin(), files.end(), [](const auto& f1, const auto& f2) {
+    return f1.lstat().mtime() < f2.lstat().mtime();
+  });
 
   LOG("Before cleanup: {:.0f} KiB, {:.0f} files",
       static_cast<double>(cache_size) / 1024,
@@ -186,8 +184,7 @@ clean_up_all(const Config& config,
 {
   Util::for_each_level_1_subdir(
     config.cache_dir(),
-    [&](const std::string& subdir,
-        const Util::ProgressReceiver& sub_progress_receiver) {
+    [&](const auto& subdir, const auto& sub_progress_receiver) {
       clean_up_dir(subdir,
                    config.max_size() / 16,
                    config.max_files() / 16,
index 1164b795010d72968629c24d52d80d628e29f0fc..3d18b87343ff0bcf717bac53a53053e8cdf3c6ba 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -196,7 +196,7 @@ recompress_file(RecompressionStatistics& statistics,
   atomic_new_file.commit();
   auto new_stat = Stat::stat(cache_file.path(), Stat::OnError::log);
 
-  Statistics::update(stats_file, [=](Counters& cs) {
+  Statistics::update(stats_file, [=](auto& cs) {
     cs.increment(Statistic::cache_size_kibibyte,
                  Util::size_change_kibibyte(old_stat, new_stat));
   });
@@ -219,8 +219,7 @@ compress_stats(const Config& config,
 
   Util::for_each_level_1_subdir(
     config.cache_dir(),
-    [&](const std::string& subdir,
-        const Util::ProgressReceiver& sub_progress_receiver) {
+    [&](const auto& subdir, const auto& sub_progress_receiver) {
       const std::vector<CacheFile> files = Util::get_level_1_files(
         subdir, [&](double progress) { sub_progress_receiver(progress / 2); });
 
@@ -285,8 +284,7 @@ compress_recompress(Context& ctx,
 
   Util::for_each_level_1_subdir(
     ctx.config.cache_dir(),
-    [&](const std::string& subdir,
-        const Util::ProgressReceiver& sub_progress_receiver) {
+    [&](const auto& subdir, const auto& sub_progress_receiver) {
       std::vector<CacheFile> files =
         Util::get_level_1_files(subdir, [&](double progress) {
           sub_progress_receiver(0.1 * progress);
index b0523356ad2bfc87a0dadb92b37385d077027b28..d646fa4ac29b54abbe9d578393049cb890f93342 100644 (file)
@@ -414,11 +414,10 @@ TEST_CASE("Config::visit_items")
 
   std::vector<std::string> received_items;
 
-  config.visit_items([&](const std::string& key,
-                         const std::string& value,
-                         const std::string& origin) {
-    received_items.push_back(FMT("({}) {} = {}", origin, key, value));
-  });
+  config.visit_items(
+    [&](const auto& key, const auto& value, const auto& origin) {
+      received_items.push_back(FMT("({}) {} = {}", origin, key, value));
+    });
 
   std::vector<std::string> expected = {
     "(test.conf) absolute_paths_in_stderr = true",
index 5d10966d78b2d176ac5617ba2edd2b9865dc36cb..07d752759814b0e39dbc7cef8ee8e9c731637ad3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2011-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -97,7 +97,7 @@ TEST_CASE("Update")
 
   Util::write_file("test", "0 1 2 3 27 5\n");
 
-  auto counters = Statistics::update("test", [](Counters& cs) {
+  auto counters = Statistics::update("test", [](auto& cs) {
     cs.increment(Statistic::internal_error, 1);
     cs.increment(Statistic::cache_miss, 6);
   });
@@ -116,7 +116,7 @@ TEST_CASE("Get result")
   TestContext test_context;
 
   auto counters = Statistics::update(
-    "test", [](Counters& cs) { cs.increment(Statistic::cache_miss, 1); });
+    "test", [](auto& cs) { cs.increment(Statistic::cache_miss, 1); });
   REQUIRE(counters);
 
   auto result = Statistics::get_result_message(*counters);
@@ -128,7 +128,7 @@ TEST_CASE("Log result")
   TestContext test_context;
 
   auto counters = Statistics::update(
-    "test", [](Counters& cs) { cs.increment(Statistic::cache_miss, 1); });
+    "test", [](auto& cs) { cs.increment(Statistic::cache_miss, 1); });
   REQUIRE(counters);
 
   auto result_id = Statistics::get_result_id(*counters);
index cb2be415c2d126cde905a236b92dd7a321c93fde..243748786378c783c730890e2040fada3398d2c8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -249,9 +249,7 @@ TEST_CASE("Util::for_each_level_1_subdir")
   std::vector<std::string> actual;
   Util::for_each_level_1_subdir(
     "cache_dir",
-    [&](const std::string& subdir, const Util::ProgressReceiver&) {
-      actual.push_back(subdir);
-    },
+    [&](const auto& subdir, const auto&) { actual.push_back(subdir); },
     [](double) {});
 
   std::vector<std::string> expected = {
@@ -397,10 +395,9 @@ TEST_CASE("Util::get_level_1_files")
 
     // Files within a level are in arbitrary order, sort them to be able to
     // verify them.
-    std::sort(
-      files.begin(), files.end(), [](const CacheFile& f1, const CacheFile& f2) {
-        return f1.path() < f2.path();
-      });
+    std::sort(files.begin(), files.end(), [](const auto& f1, const auto& f2) {
+      return f1.path() < f2.path();
+    });
 
     CHECK(files[0].path() == os_path("0/1/file_b"));
     CHECK(files[0].lstat().size() == 1);
index cd59588ae82e8ac2ea091ad74dfbd3b644b87034..3236a4883822697e203ce96e4c10d3e2b5ab9726 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -42,11 +42,10 @@ helper(const char* args,
        const char* find_executable_return_string = nullptr)
 {
   const auto find_executable_stub =
-    [&find_executable_return_string](
-      const Context&, const std::string& s, const std::string&) -> std::string {
-    return find_executable_return_string ? find_executable_return_string
-                                         : "resolved_" + s;
-  };
+    [&find_executable_return_string](const auto&, const auto& s, const auto&) {
+      return find_executable_return_string ? find_executable_return_string
+                                           : "resolved_" + s;
+    };
 
   Context ctx;
   ctx.config.set_compiler(config_compiler);