From: Joel Rosdahl Date: Thu, 24 Oct 2024 14:34:52 +0000 (+0200) Subject: refactor: Rename "at file" to "response file" internally X-Git-Tag: v4.11~57 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=44c39162e238aea7329e170139e68fcff5d3e447;p=thirdparty%2Fccache.git refactor: Rename "at file" to "response file" internally --- diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 7e8b9ed6..8ad19332 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -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. -- diff --git a/src/ccache/argprocessing.cpp b/src/ccache/argprocessing.cpp index bb918847..e55da8c4 100644 --- a/src/ccache/argprocessing.cpp +++ b/src/ccache/argprocessing.cpp @@ -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; diff --git a/src/ccache/args.cpp b/src/ccache/args.cpp index 8e7a42f0..19cf7839 100644 --- a/src/ccache/args.cpp +++ b/src/ccache/args.cpp @@ -48,13 +48,13 @@ Args::from_string(std::string_view command) } std::optional -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(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 diff --git a/src/ccache/args.hpp b/src/ccache/args.hpp index 325337e5..4f7b10ef 100644 --- a/src/ccache/args.hpp +++ b/src/ccache/args.hpp @@ -25,11 +25,15 @@ #include #include -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 from_atfile(const std::string& filename, - AtFileFormat format); + static std::optional from_response_file(const std::string& filename, + ResponseFileFormat format); Args& operator=(const Args& other) = default; Args& operator=(Args&& other) noexcept; diff --git a/src/ccache/config.cpp b/src/ccache/config.cpp index ce10d237..2cfb300f 100644 --- a/src/ccache/config.cpp +++ b/src/ccache/config.cpp @@ -228,15 +228,15 @@ const std::unordered_map 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: diff --git a/src/ccache/config.hpp b/src/ccache/config.hpp index 4e8a60f3..a527533b 100644 --- a/src/ccache/config.hpp +++ b/src/ccache/config.hpp @@ -18,6 +18,7 @@ #pragma once +#include #include #include #include @@ -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& 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& diff --git a/unittest/test_args.cpp b/unittest/test_args.cpp index e9dc3bf2..650e2bac 100644 --- a/unittest/test_args.cpp +++ b/unittest/test_args.cpp @@ -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)"); diff --git a/unittest/test_config.cpp b/unittest/test_config.cpp index 5f79bb8e..0ca6d068 100644 --- a/unittest/test_config.cpp +++ b/unittest/test_config.cpp @@ -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); } }