]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Rename "at file" to "response file" internally
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 24 Oct 2024 14:34:52 +0000 (16:34 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 24 Oct 2024 14:36:33 +0000 (16:36 +0200)
doc/MANUAL.adoc
src/ccache/argprocessing.cpp
src/ccache/args.cpp
src/ccache/args.hpp
src/ccache/config.cpp
src/ccache/config.hpp
unittest/test_args.cpp
unittest/test_config.cpp

index 7e8b9ed68d13da88c515582a2081c7afe302099b..8ad193323bb774695720b79613074d290e4ae96b 100644 (file)
@@ -994,16 +994,17 @@ NOTE: In previous ccache versions this option was called *secondary_storage*
 [#config_response_file_format]
 *response_file_format* (*CCACHE_RESPONSE_FILE_FORMAT*)::
 
-    Ccache normally guesses the response file format based on the compiler type. The
-    *response_file_format* option lets you force the response file quoting behavior.
-    This can be useful if the compiler supports both posix and windows response file
-    quoting. Possible values are:
+    Ccache normally guesses the response file format based on the compiler type.
+    The *response_file_format* option lets you force the response file quoting
+    behavior. This can be useful if the compiler supports both POSIX and Windows
+    response file quoting. Possible values are:
 +
 --
 *auto*::
-    Guess one of the formats below based on the compiler type. This is the default.
+    Guess one of the formats below based on the compiler type. This is the
+    default.
 *posix*::
-    Posix quoting behavior.
+    POSIX quoting behavior.
 *windows*::
     Windows quoting behavior.
 --
index bb9188472624d4bb562ffd90e05ccc58118d2c5e..e55da8c4b30716d9eafbfcdcd8219c6327c39a9e 100644 (file)
@@ -399,7 +399,8 @@ process_option_arg(const Context& ctx,
     if (argpath[-1] == '-') {
       ++argpath;
     }
-    auto file_args = Args::from_atfile(argpath, config.atfile_format());
+    auto file_args =
+      Args::from_response_file(argpath, config.response_file_format());
     if (!file_args) {
       LOG("Couldn't read arg file {}", argpath);
       return Statistic::bad_compiler_arguments;
@@ -422,7 +423,8 @@ process_option_arg(const Context& ctx,
     // Argument is a comma-separated list of files.
     auto paths = util::split_into_strings(args[i], ",");
     for (auto it = paths.rbegin(); it != paths.rend(); ++it) {
-      auto file_args = Args::from_atfile(*it, AtFileFormat::gcc);
+      auto file_args =
+        Args::from_response_file(*it, Args::ResponseFileFormat::posix);
       if (!file_args) {
         LOG("Couldn't read CUDA options file {}", *it);
         return Statistic::bad_compiler_arguments;
index 8e7a42f0335e7460b1d7d31c509124f5a881591c..19cf78395795cc215d4900bef50924af50f2d904 100644 (file)
@@ -48,13 +48,13 @@ Args::from_string(std::string_view command)
 }
 
 std::optional<Args>
-Args::from_atfile(const std::string& filename, AtFileFormat format)
+Args::from_response_file(const std::string& filename, ResponseFileFormat format)
 {
-  ASSERT(format != AtFileFormat::auto_guess);
+  ASSERT(format != ResponseFileFormat::auto_guess);
 
   const auto argtext = util::read_file<std::string>(filename);
   if (!argtext) {
-    LOG("Failed to read atfile {}: {}", filename, argtext.error());
+    LOG("Failed to read response file {}: {}", filename, argtext.error());
     return std::nullopt;
   }
 
@@ -72,16 +72,16 @@ Args::from_atfile(const std::string& filename, AtFileFormat format)
     switch (*pos) {
     case '\\':
       switch (format) {
-      case AtFileFormat::auto_guess:
+      case ResponseFileFormat::auto_guess:
         ASSERT(false); // Can't happen
         break;
-      case AtFileFormat::gcc:
+      case ResponseFileFormat::posix:
         pos++;
         if (*pos == '\0') {
           continue;
         }
         break;
-      case AtFileFormat::msvc:
+      case ResponseFileFormat::windows:
         size_t count = 0;
         while (*pos == '\\') {
           count++;
@@ -113,7 +113,7 @@ Args::from_atfile(const std::string& filename, AtFileFormat format)
       break;
 
     case '\'':
-      if (format == AtFileFormat::msvc) {
+      if (format == ResponseFileFormat::windows) {
         break;
       }
       [[fallthrough]];
@@ -123,7 +123,7 @@ Args::from_atfile(const std::string& filename, AtFileFormat format)
         if (quoting == *pos) {
           quoting = '\0';
           pos++;
-          if (format == AtFileFormat::msvc && *pos == '"') {
+          if (format == ResponseFileFormat::windows && *pos == '"') {
             // Any double-quote directly following a closing quote is treated as
             // (or as part of) plain unwrapped text that is adjacent to the
             // double-quoted group
index 325337e5350bc8a57f39358308b90b00e43615d3..4f7b10efe18989fa4e9ab85b683d859cd4ef6d2c 100644 (file)
 #include <string_view>
 #include <vector>
 
-enum class AtFileFormat;
-
 class Args
 {
 public:
+  enum class ResponseFileFormat {
+    auto_guess,
+    posix,   // '\'' and '"' quote, '\\' escapes any character
+    windows, // '"' quotes, '\\' escapes only '"' and '\\'
+  };
+
   Args() = default;
   Args(const Args& other) = default;
   Args(Args&& other) noexcept;
@@ -37,8 +41,8 @@ public:
   static Args from_argv(int argc, const char* const* argv);
   static Args from_string(std::string_view command);
 
-  static std::optional<Args> from_atfile(const std::string& filename,
-                                         AtFileFormat format);
+  static std::optional<Args> from_response_file(const std::string& filename,
+                                                ResponseFileFormat format);
 
   Args& operator=(const Args& other) = default;
   Args& operator=(Args&& other) noexcept;
index ce10d23730dc9f0e63f15c2f39128d0dc3c239cd..2cfb300f5402e4d4571b03fd1268e2fc6c8a052c 100644 (file)
@@ -228,15 +228,15 @@ const std::unordered_map<std::string, std::string> k_env_variable_table = {
   {"UMASK", "umask"},
 };
 
-AtFileFormat
+Args::ResponseFileFormat
 parse_response_file_format(const std::string& value)
 {
-  if (value == "windows") {
-    return AtFileFormat::msvc;
-  } else if (value == "posix") {
-    return AtFileFormat::gcc;
+  if (value == "posix") {
+    return Args::ResponseFileFormat::posix;
+  } else if (value == "windows") {
+    return Args::ResponseFileFormat::windows;
   } else {
-    return AtFileFormat::auto_guess;
+    return Args::ResponseFileFormat::auto_guess;
   }
 }
 
@@ -541,14 +541,14 @@ home_directory()
 }
 
 std::string
-atfile_format_to_string(AtFileFormat atfile_format)
+response_file_format_to_string(Args::ResponseFileFormat response_file_format)
 {
-  switch (atfile_format) {
-  case AtFileFormat::auto_guess:
+  switch (response_file_format) {
+  case Args::ResponseFileFormat::auto_guess:
     return "auto";
-  case AtFileFormat::gcc:
+  case Args::ResponseFileFormat::posix:
     return "posix";
-  case AtFileFormat::msvc:
+  case Args::ResponseFileFormat::windows:
     return "windows";
   }
 
@@ -907,7 +907,7 @@ Config::get_string_value(const std::string& key) const
     return format_bool(m_reshare);
 
   case ConfigItem::response_file_format:
-    return atfile_format_to_string(m_atfile_format);
+    return response_file_format_to_string(m_response_file_format);
 
   case ConfigItem::run_second_cpp:
     return format_bool(m_run_second_cpp);
@@ -1177,7 +1177,7 @@ Config::set_item(const std::string& key,
     break;
 
   case ConfigItem::response_file_format:
-    m_atfile_format = parse_response_file_format(value);
+    m_response_file_format = parse_response_file_format(value);
     break;
 
   case ConfigItem::run_second_cpp:
index 4e8a60f3b9ed6a1e1bb577f98a594088ad221b49..a527533bc2b638cf3ed3414094e66d6c1de4943a 100644 (file)
@@ -18,6 +18,7 @@
 
 #pragma once
 
+#include <ccache/args.hpp>
 #include <ccache/core/sloppiness.hpp>
 #include <ccache/util/noncopyable.hpp>
 #include <ccache/util/string.hpp>
@@ -43,12 +44,6 @@ enum class CompilerType {
   other
 };
 
-enum class AtFileFormat {
-  gcc,  // '\'' and '"' quote, '\\' escapes any character
-  msvc, // '"' quotes, '\\' escapes only '"' and '\\'
-  auto_guess,
-};
-
 std::string compiler_type_to_string(CompilerType compiler_type);
 
 class Config : util::NonCopyable
@@ -59,7 +54,7 @@ public:
   void read(const std::vector<std::string>& cmdline_config_settings = {});
 
   bool absolute_paths_in_stderr() const;
-  AtFileFormat atfile_format() const;
+  Args::ResponseFileFormat response_file_format() const;
   const std::filesystem::path& base_dir() const;
   const std::filesystem::path& cache_dir() const;
   const std::string& compiler() const;
@@ -175,7 +170,8 @@ private:
   std::filesystem::path m_system_config_path;
 
   bool m_absolute_paths_in_stderr = false;
-  AtFileFormat m_atfile_format = AtFileFormat::auto_guess;
+  Args::ResponseFileFormat m_response_file_format =
+    Args::ResponseFileFormat::auto_guess;
   std::filesystem::path m_base_dir;
   std::filesystem::path m_cache_dir;
   std::string m_compiler;
@@ -244,18 +240,15 @@ Config::absolute_paths_in_stderr() const
   return m_absolute_paths_in_stderr;
 }
 
-inline AtFileFormat
-Config::atfile_format() const
+inline Args::ResponseFileFormat
+Config::response_file_format() const
 {
-  if (m_atfile_format != AtFileFormat::auto_guess) {
-    return m_atfile_format;
-  }
-
-  if (is_compiler_group_msvc()) {
-    return AtFileFormat::msvc;
+  if (m_response_file_format != Args::ResponseFileFormat::auto_guess) {
+    return m_response_file_format;
   }
 
-  return AtFileFormat::gcc;
+  return is_compiler_group_msvc() ? Args::ResponseFileFormat::windows
+                                  : Args::ResponseFileFormat::posix;
 }
 
 inline const std::filesystem::path&
index e9dc3bf2e0eed47ba3b43cec7307ac204ae052d6..650e2bac396319d224b2cf1cb60ba45ae8f7c41c 100644 (file)
@@ -79,44 +79,46 @@ TEST_CASE("Args::from_string")
   CHECK(args[3] == "f");
 }
 
-TEST_CASE("Args::from_atfile")
+TEST_CASE("Args::from_response_file")
 {
   TestContext test_context;
+  using ResponseFileFormat = Args::ResponseFileFormat;
 
   Args args;
 
   SUBCASE("Nonexistent file")
   {
-    CHECK(Args::from_atfile("at_file", AtFileFormat::gcc) == std::nullopt);
+    CHECK(Args::from_response_file("rsp_file", ResponseFileFormat::posix)
+          == std::nullopt);
   }
 
   SUBCASE("Empty")
   {
-    util::write_file("at_file", "");
-    args = *Args::from_atfile("at_file", AtFileFormat::gcc);
+    util::write_file("rsp_file", "");
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix);
     CHECK(args.size() == 0);
   }
 
   SUBCASE("One argument without newline")
   {
-    util::write_file("at_file", "foo");
-    args = *Args::from_atfile("at_file", AtFileFormat::gcc);
+    util::write_file("rsp_file", "foo");
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix);
     CHECK(args.size() == 1);
     CHECK(args[0] == "foo");
   }
 
   SUBCASE("One argument with newline")
   {
-    util::write_file("at_file", "foo\n");
-    args = *Args::from_atfile("at_file", AtFileFormat::gcc);
+    util::write_file("rsp_file", "foo\n");
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix);
     CHECK(args.size() == 1);
     CHECK(args[0] == "foo");
   }
 
   SUBCASE("Multiple simple arguments")
   {
-    util::write_file("at_file", "x y z\n");
-    args = *Args::from_atfile("at_file", AtFileFormat::gcc);
+    util::write_file("rsp_file", "x y z\n");
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix);
     CHECK(args.size() == 3);
     CHECK(args[0] == "x");
     CHECK(args[1] == "y");
@@ -126,10 +128,10 @@ TEST_CASE("Args::from_atfile")
   SUBCASE("Tricky quoting")
   {
     util::write_file(
-      "at_file",
+      "rsp_file",
       "first\rsec\\\tond\tthi\\\\rd\nfourth  \tfif\\ th \"si'x\\\" th\""
       " 'seve\nth'\\");
-    args = *Args::from_atfile("at_file", AtFileFormat::gcc);
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::posix);
     CHECK(args.size() == 7);
     CHECK(args[0] == "first");
     CHECK(args[1] == "sec\tond");
@@ -142,8 +144,8 @@ TEST_CASE("Args::from_atfile")
 
   SUBCASE("Ignore single quote in MSVC format")
   {
-    util::write_file("at_file", "'a b'");
-    args = *Args::from_atfile("at_file", AtFileFormat::msvc);
+    util::write_file("rsp_file", "'a b'");
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows);
     CHECK(args.size() == 2);
     CHECK(args[0] == "'a");
     CHECK(args[1] == "b'");
@@ -151,24 +153,24 @@ TEST_CASE("Args::from_atfile")
 
   SUBCASE("Backslash as directory separator in MSVC format")
   {
-    util::write_file("at_file", R"("-DDIRSEP='A\B\C'")");
-    args = *Args::from_atfile("at_file", AtFileFormat::msvc);
+    util::write_file("rsp_file", R"("-DDIRSEP='A\B\C'")");
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows);
     CHECK(args.size() == 1);
     CHECK(args[0] == R"(-DDIRSEP='A\B\C')");
   }
 
   SUBCASE("Backslash before quote in MSVC format")
   {
-    util::write_file("at_file", R"(/Fo"N.dir\Release\\")");
-    args = *Args::from_atfile("at_file", AtFileFormat::msvc);
+    util::write_file("rsp_file", R"(/Fo"N.dir\Release\\")");
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows);
     CHECK(args.size() == 1);
     CHECK(args[0] == R"(/FoN.dir\Release\)");
   }
 
   SUBCASE("Arguments on multiple lines in MSVC format")
   {
-    util::write_file("at_file", "a\nb");
-    args = *Args::from_atfile("at_file", AtFileFormat::msvc);
+    util::write_file("rsp_file", "a\nb");
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows);
     CHECK(args.size() == 2);
     CHECK(args[0] == "a");
     CHECK(args[1] == "b");
@@ -177,11 +179,11 @@ TEST_CASE("Args::from_atfile")
   SUBCASE("Tricky quoting in MSVC format (#1247)")
   {
     util::write_file(
-      "at_file",
+      "rsp_file",
       R"(\ \\ '\\' "\\" '"\\"' "'\\'" '''\\''' ''"\\"'' '"'\\'"' '""\\""' "''\\''" "'"\\"'" ""'\\'"" """\\""" )"
       R"(\'\' '\'\'' "\'\'" ''\'\''' '"\'\'"' "'\'\''" ""\'\'"" '''\'\'''' ''"\'\'"'' '"'\'\''"' '""\'\'""' "''\'\'''" "'"\'\'"'" ""'\'\''"" """\'\'""" )"
       R"(\"\" '\"\"' "\"\"" ''\"\"'' '"\"\""' "'\"\"'" ""\"\""" '''\"\"''' ''"\"\""'' '"'\"\"'"' '""\"\"""' "''\"\"''" "'"\"\""'" ""'\"\"'"" """\"\"""")");
-    args = *Args::from_atfile("at_file", AtFileFormat::msvc);
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows);
     CHECK(args.size() == 44);
     CHECK(args[0] == R"(\)");
     CHECK(args[1] == R"(\\)");
@@ -233,12 +235,12 @@ TEST_CASE("Args::from_atfile")
   {
     // See
     // https://learn.microsoft.com/en-us/previous-versions//17w5ykft(v=vs.85)?redirectedfrom=MSDN
-    util::write_file("at_file",
+    util::write_file("rsp_file",
                      R"("abc" d e )"
                      R"(a\\\b d"e f"g h )"
                      R"(a\\\"b c d )"
                      R"(a\\\\"b c" d e)");
-    args = *Args::from_atfile("at_file", AtFileFormat::msvc);
+    args = *Args::from_response_file("rsp_file", ResponseFileFormat::windows);
     CHECK(args.size() == 12);
     CHECK(args[0] == R"(abc)");
     CHECK(args[1] == R"(d)");
index 5f79bb8e68544b106b400a64a148769ba8d60629..0ca6d068e99b1405503a6b44f1d87941864d27b2 100644 (file)
@@ -310,6 +310,8 @@ TEST_CASE("Config::update_from_environment")
 
 TEST_CASE("Config::response_file_format")
 {
+  using ResponseFileFormat = Args::ResponseFileFormat;
+
   Config config;
 
   SUBCASE("from config gcc")
@@ -317,7 +319,7 @@ TEST_CASE("Config::response_file_format")
     util::write_file("ccache.conf", "response_file_format = posix");
     CHECK(config.update_from_file("ccache.conf"));
 
-    CHECK(config.atfile_format() == AtFileFormat::gcc);
+    CHECK(config.response_file_format() == ResponseFileFormat::posix);
   }
 
   SUBCASE("from config msvc")
@@ -325,7 +327,7 @@ TEST_CASE("Config::response_file_format")
     util::write_file("ccache.conf", "response_file_format = windows");
     CHECK(config.update_from_file("ccache.conf"));
 
-    CHECK(config.atfile_format() == AtFileFormat::msvc);
+    CHECK(config.response_file_format() == ResponseFileFormat::windows);
   }
 
   SUBCASE("from config msvc with clang compiler")
@@ -334,7 +336,7 @@ TEST_CASE("Config::response_file_format")
                      "response_file_format = windows\ncompiler_type = clang");
     CHECK(config.update_from_file("ccache.conf"));
 
-    CHECK(config.atfile_format() == AtFileFormat::msvc);
+    CHECK(config.response_file_format() == ResponseFileFormat::windows);
   }
 
   SUBCASE("guess from compiler gcc")
@@ -342,7 +344,7 @@ TEST_CASE("Config::response_file_format")
     util::write_file("ccache.conf", "compiler_type = clang");
     CHECK(config.update_from_file("ccache.conf"));
 
-    CHECK(config.atfile_format() == AtFileFormat::gcc);
+    CHECK(config.response_file_format() == ResponseFileFormat::posix);
   }
 
   SUBCASE("guess from compiler msvc")
@@ -350,7 +352,7 @@ TEST_CASE("Config::response_file_format")
     util::write_file("ccache.conf", "compiler_type = msvc");
     CHECK(config.update_from_file("ccache.conf"));
 
-    CHECK(config.atfile_format() == AtFileFormat::msvc);
+    CHECK(config.response_file_format() == ResponseFileFormat::windows);
   }
 }