]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Sort sloppiness parsing/generation
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 31 Mar 2022 19:17:32 +0000 (21:17 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 1 Apr 2022 18:26:42 +0000 (20:26 +0200)
src/Config.cpp
unittest/test_Config.cpp

index 09531ff71920b063d3346c80488e17ce66246299..ffc885977814ef3de6bc517ea32ccc1a7409d9f5 100644 (file)
@@ -267,7 +267,9 @@ parse_sloppiness(const std::string& value)
     end = value.find_first_of(", ", start);
     std::string token =
       util::strip_whitespace(value.substr(start, end - start));
-    if (token == "file_stat_matches") {
+    if (token == "clang_index_store") {
+      result.enable(core::Sloppy::clang_index_store);
+    } else if (token == "file_stat_matches") {
       result.enable(core::Sloppy::file_stat_matches);
     } else if (token == "file_stat_matches_ctime") {
       result.enable(core::Sloppy::file_stat_matches_ctime);
@@ -275,20 +277,18 @@ parse_sloppiness(const std::string& value)
       result.enable(core::Sloppy::include_file_ctime);
     } else if (token == "include_file_mtime") {
       result.enable(core::Sloppy::include_file_mtime);
-    } else if (token == "system_headers" || token == "no_system_headers") {
-      result.enable(core::Sloppy::system_headers);
-    } else if (token == "pch_defines") {
-      result.enable(core::Sloppy::pch_defines);
-    } else if (token == "time_macros") {
-      result.enable(core::Sloppy::time_macros);
-    } else if (token == "clang_index_store") {
-      result.enable(core::Sloppy::clang_index_store);
+    } else if (token == "ivfsoverlay") {
+      result.enable(core::Sloppy::ivfsoverlay);
     } else if (token == "locale") {
       result.enable(core::Sloppy::locale);
     } else if (token == "modules") {
       result.enable(core::Sloppy::modules);
-    } else if (token == "ivfsoverlay") {
-      result.enable(core::Sloppy::ivfsoverlay);
+    } else if (token == "pch_defines") {
+      result.enable(core::Sloppy::pch_defines);
+    } else if (token == "system_headers" || token == "no_system_headers") {
+      result.enable(core::Sloppy::system_headers);
+    } else if (token == "time_macros") {
+      result.enable(core::Sloppy::time_macros);
     } // else: ignore unknown value for forward compatibility
     start = value.find_first_not_of(", ", end);
   }
@@ -299,17 +299,8 @@ std::string
 format_sloppiness(core::Sloppiness sloppiness)
 {
   std::string result;
-  if (sloppiness.is_enabled(core::Sloppy::include_file_mtime)) {
-    result += "include_file_mtime, ";
-  }
-  if (sloppiness.is_enabled(core::Sloppy::include_file_ctime)) {
-    result += "include_file_ctime, ";
-  }
-  if (sloppiness.is_enabled(core::Sloppy::time_macros)) {
-    result += "time_macros, ";
-  }
-  if (sloppiness.is_enabled(core::Sloppy::pch_defines)) {
-    result += "pch_defines, ";
+  if (sloppiness.is_enabled(core::Sloppy::clang_index_store)) {
+    result += "clang_index_store, ";
   }
   if (sloppiness.is_enabled(core::Sloppy::file_stat_matches)) {
     result += "file_stat_matches, ";
@@ -317,11 +308,14 @@ format_sloppiness(core::Sloppiness sloppiness)
   if (sloppiness.is_enabled(core::Sloppy::file_stat_matches_ctime)) {
     result += "file_stat_matches_ctime, ";
   }
-  if (sloppiness.is_enabled(core::Sloppy::system_headers)) {
-    result += "system_headers, ";
+  if (sloppiness.is_enabled(core::Sloppy::include_file_ctime)) {
+    result += "include_file_ctime, ";
   }
-  if (sloppiness.is_enabled(core::Sloppy::clang_index_store)) {
-    result += "clang_index_store, ";
+  if (sloppiness.is_enabled(core::Sloppy::include_file_mtime)) {
+    result += "include_file_mtime, ";
+  }
+  if (sloppiness.is_enabled(core::Sloppy::ivfsoverlay)) {
+    result += "ivfsoverlay, ";
   }
   if (sloppiness.is_enabled(core::Sloppy::locale)) {
     result += "locale, ";
@@ -329,8 +323,14 @@ format_sloppiness(core::Sloppiness sloppiness)
   if (sloppiness.is_enabled(core::Sloppy::modules)) {
     result += "modules, ";
   }
-  if (sloppiness.is_enabled(core::Sloppy::ivfsoverlay)) {
-    result += "ivfsoverlay, ";
+  if (sloppiness.is_enabled(core::Sloppy::pch_defines)) {
+    result += "pch_defines, ";
+  }
+  if (sloppiness.is_enabled(core::Sloppy::system_headers)) {
+    result += "system_headers, ";
+  }
+  if (sloppiness.is_enabled(core::Sloppy::time_macros)) {
+    result += "time_macros, ";
   }
   if (!result.empty()) {
     // Strip last ", ".
index 1fed21c8cce582d344582001a737184ca2491130..c5ff92ad9a9af51ee8eeee33cf94f1b007980f05 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2011-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -169,15 +169,15 @@ TEST_CASE("Config::update_from_file")
   CHECK(config.reshare());
   CHECK_FALSE(config.run_second_cpp());
   CHECK(config.sloppiness().to_bitmask()
-        == (static_cast<uint32_t>(core::Sloppy::include_file_mtime)
-            | static_cast<uint32_t>(core::Sloppy::include_file_ctime)
-            | static_cast<uint32_t>(core::Sloppy::time_macros)
+        == (static_cast<uint32_t>(core::Sloppy::clang_index_store)
             | static_cast<uint32_t>(core::Sloppy::file_stat_matches)
             | static_cast<uint32_t>(core::Sloppy::file_stat_matches_ctime)
-            | static_cast<uint32_t>(core::Sloppy::system_headers)
+            | static_cast<uint32_t>(core::Sloppy::include_file_ctime)
+            | static_cast<uint32_t>(core::Sloppy::include_file_mtime)
+            | static_cast<uint32_t>(core::Sloppy::ivfsoverlay)
             | static_cast<uint32_t>(core::Sloppy::pch_defines)
-            | static_cast<uint32_t>(core::Sloppy::clang_index_store)
-            | static_cast<uint32_t>(core::Sloppy::ivfsoverlay)));
+            | static_cast<uint32_t>(core::Sloppy::system_headers)
+            | static_cast<uint32_t>(core::Sloppy::time_macros)));
   CHECK_FALSE(config.stats());
   CHECK(config.temporary_dir() == FMT("{}_foo", user));
   CHECK(config.umask() == 0777u);
@@ -473,9 +473,9 @@ TEST_CASE("Config::visit_items")
     "(test.conf) reshare = true",
     "(test.conf) run_second_cpp = false",
     "(test.conf) secondary_storage = ss",
-    "(test.conf) sloppiness = include_file_mtime, include_file_ctime,"
-    " time_macros, pch_defines, file_stat_matches, file_stat_matches_ctime,"
-    " system_headers, clang_index_store, ivfsoverlay",
+    "(test.conf) sloppiness = clang_index_store, file_stat_matches,"
+    " file_stat_matches_ctime, include_file_ctime, include_file_mtime,"
+    " ivfsoverlay, pch_defines, system_headers, time_macros",
     "(test.conf) stats = false",
     "(test.conf) stats_log = sl",
     "(test.conf) temporary_dir = td",