From: Joel Rosdahl Date: Sat, 15 Oct 2022 18:26:18 +0000 (+0200) Subject: refactor: Rename ShowIncludesParser to MsvcShowIncludesOutput X-Git-Tag: v4.7~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=552d736e12931f1c9e286c8495a4687457921ba8;p=thirdparty%2Fccache.git refactor: Rename ShowIncludesParser to MsvcShowIncludesOutput I think that this is more in line with what the namespace represents. I also renamed ShowIncludesParser::tokenize to MsvcShowIncludesOutput::get_includes since it's not returning generic tokens but specifically includes files. --- diff --git a/src/ccache.cpp b/src/ccache.cpp index f3333365b..308685671 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -44,9 +44,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -698,7 +698,7 @@ struct DoExecuteResult static std::optional result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data) { - for (std::string_view token : core::ShowIncludesParser::tokenize( + for (std::string_view token : core::MsvcShowIncludesOutput::get_includes( stdout_data, ctx.config.msvc_dep_prefix())) { const std::string path = Util::make_relative_path(ctx, token); remember_include_file(ctx, path, hash, false, &hash); @@ -1076,7 +1076,7 @@ to_cache(Context& ctx, ctx, util::to_string_view(result->stderr_data), STDERR_FILENO); Util::send_to_fd( ctx, - util::to_string_view(core::ShowIncludesParser::strip_includes( + util::to_string_view(core::MsvcShowIncludesOutput::strip_includes( ctx, std::move(result->stdout_data))), STDOUT_FILENO); @@ -1138,7 +1138,7 @@ to_cache(Context& ctx, // Send stdout after stderr, it makes the output clearer with MSVC. Util::send_to_fd( ctx, - util::to_string_view(core::ShowIncludesParser::strip_includes( + util::to_string_view(core::MsvcShowIncludesOutput::strip_includes( ctx, std::move(result->stdout_data))), STDOUT_FILENO); diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1fa9f7073..c664dda53 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -6,7 +6,7 @@ set( ResultExtractor.cpp ResultInspector.cpp ResultRetriever.cpp - ShowIncludesParser.cpp + MsvcShowIncludesOutput.cpp Statistics.cpp StatisticsCounters.cpp StatsLog.cpp diff --git a/src/core/ShowIncludesParser.cpp b/src/core/MsvcShowIncludesOutput.cpp similarity index 92% rename from src/core/ShowIncludesParser.cpp rename to src/core/MsvcShowIncludesOutput.cpp index f05521eb9..5289eadc6 100644 --- a/src/core/ShowIncludesParser.cpp +++ b/src/core/MsvcShowIncludesOutput.cpp @@ -16,16 +16,16 @@ // this program; if not, write to the Free Software Foundation, Inc., 51 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -#include "ShowIncludesParser.hpp" +#include "MsvcShowIncludesOutput.hpp" #include #include #include -namespace core::ShowIncludesParser { +namespace core::MsvcShowIncludesOutput { std::vector -tokenize(std::string_view file_content, std::string_view prefix) +get_includes(std::string_view file_content, std::string_view prefix) { // /showIncludes output is written to stdout together with other messages. // Every line of it is " " where the prefix is "Note: @@ -73,4 +73,4 @@ strip_includes(const Context& ctx, util::Bytes&& stdout_data) return util::Bytes(new_stdout_text.data(), new_stdout_text.size()); } -} // namespace core::ShowIncludesParser +} // namespace core::MsvcShowIncludesOutput diff --git a/src/core/ShowIncludesParser.hpp b/src/core/MsvcShowIncludesOutput.hpp similarity index 81% rename from src/core/ShowIncludesParser.hpp rename to src/core/MsvcShowIncludesOutput.hpp index a368d62b8..97c59c061 100644 --- a/src/core/ShowIncludesParser.hpp +++ b/src/core/MsvcShowIncludesOutput.hpp @@ -25,11 +25,11 @@ class Context; -namespace core::ShowIncludesParser { +namespace core::MsvcShowIncludesOutput { -std::vector tokenize(std::string_view file_content, - std::string_view prefix); +std::vector get_includes(std::string_view file_content, + std::string_view prefix); util::Bytes strip_includes(const Context& ctx, util::Bytes&& stdout_data); -} // namespace core::ShowIncludesParser +} // namespace core::MsvcShowIncludesOutput diff --git a/src/core/ResultRetriever.cpp b/src/core/ResultRetriever.cpp index 484e1632a..0aecc17d1 100644 --- a/src/core/ResultRetriever.cpp +++ b/src/core/ResultRetriever.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -64,7 +64,7 @@ ResultRetriever::on_embedded_file(uint8_t file_number, if (file_type == FileType::stdout_output) { Util::send_to_fd( m_ctx, - util::to_string_view(ShowIncludesParser::strip_includes(m_ctx, data)), + util::to_string_view(MsvcShowIncludesOutput::strip_includes(m_ctx, data)), STDOUT_FILENO); } else if (file_type == FileType::stderr_output) { Util::send_to_fd(m_ctx, util::to_string_view(data), STDERR_FILENO); diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index e0ec8b325..d6e57da32 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -13,7 +13,7 @@ set( test_ccache.cpp test_compopt.cpp test_compression_types.cpp - test_core_ShowIncludesParser.cpp + test_core_MsvcShowIncludesOutput.cpp test_core_Statistics.cpp test_core_StatisticsCounters.cpp test_core_StatsLog.cpp diff --git a/unittest/test_core_ShowIncludesParser.cpp b/unittest/test_core_MsvcShowIncludesOutput.cpp similarity index 79% rename from unittest/test_core_ShowIncludesParser.cpp rename to unittest/test_core_MsvcShowIncludesOutput.cpp index 61af1f824..0e0f71783 100644 --- a/unittest/test_core_ShowIncludesParser.cpp +++ b/unittest/test_core_MsvcShowIncludesOutput.cpp @@ -17,7 +17,7 @@ // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "../src/Context.hpp" -#include "../src/core/ShowIncludesParser.hpp" +#include "../src/core/MsvcShowIncludesOutput.hpp" #include "../src/util/string.hpp" #include "TestUtil.hpp" @@ -25,15 +25,15 @@ static const std::string defaultPrefix = "Note: including file:"; -TEST_SUITE_BEGIN("ShowIncludesParser"); +TEST_SUITE_BEGIN("MsvcShowIncludesOutput"); -TEST_CASE("ShowIncludesParser::tokenize") +TEST_CASE("MsvcShowIncludesOutput::get_includes") { SUBCASE("Parse empty output") { std::string contents; const auto result = - core::ShowIncludesParser::tokenize(contents, defaultPrefix); + core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix); CHECK(result.size() == 0); } @@ -47,7 +47,7 @@ Note: including file: F:\Projects\ccache\src\NonCopyable.hpp Note: including file: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\deque )"; const auto result = - core::ShowIncludesParser::tokenize(contents, defaultPrefix); + core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix); REQUIRE(result.size() == 5); CHECK(result[0] == "F:/Projects/ccache/build-msvc/config.h"); CHECK(result[1] == R"(F:\Projects\ccache\unittest\../src/Context.hpp)"); @@ -64,7 +64,7 @@ Note: including file: C:\Program Files\Microsoft Visual Studio\2022\Community\ "Note: including file: foo\r\n" "Note: including file: bar\r\n"; const auto result = - core::ShowIncludesParser::tokenize(contents, defaultPrefix); + core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix); REQUIRE(result.size() == 2); CHECK(result[0] == "foo"); CHECK(result[1] == "bar"); @@ -77,7 +77,7 @@ Note: including file: C:\Program Files\Microsoft Visual Studio\2022\Community\ "Note: including file: \n" "Note: including file: bar\n"; const auto result = - core::ShowIncludesParser::tokenize(contents, defaultPrefix); + core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix); REQUIRE(result.size() == 2); CHECK(result[0] == "foo"); CHECK(result[1] == "bar"); @@ -88,14 +88,15 @@ Note: including file: C:\Program Files\Microsoft Visual Studio\2022\Community\ std::string contents = R"(custom foo custom bar Just a line with custom in the middle)"; - const auto result = core::ShowIncludesParser::tokenize(contents, "custom"); + const auto result = + core::MsvcShowIncludesOutput::get_includes(contents, "custom"); REQUIRE(result.size() == 2); CHECK(result[0] == "foo"); CHECK(result[1] == "bar"); } } -TEST_CASE("ShowIncludesParser::strip_includes") +TEST_CASE("MsvcShowIncludesOutput::strip_includes") { Context ctx; const util::Bytes input = util::to_span( @@ -106,14 +107,14 @@ TEST_CASE("ShowIncludesParser::strip_includes") SUBCASE("Empty output") { const util::Bytes result = - core::ShowIncludesParser::strip_includes(ctx, {}); + core::MsvcShowIncludesOutput::strip_includes(ctx, {}); CHECK(result.size() == 0); } SUBCASE("Feature disabled") { const util::Bytes result = - core::ShowIncludesParser::strip_includes(ctx, util::Bytes(input)); + core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input)); CHECK(result == input); } @@ -122,7 +123,7 @@ TEST_CASE("ShowIncludesParser::strip_includes") SUBCASE("Wrong compiler") { const util::Bytes result = - core::ShowIncludesParser::strip_includes(ctx, util::Bytes(input)); + core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input)); CHECK(result == input); } @@ -131,13 +132,13 @@ TEST_CASE("ShowIncludesParser::strip_includes") SUBCASE("Simple output") { const util::Bytes result = - core::ShowIncludesParser::strip_includes(ctx, util::Bytes(input)); + core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input)); CHECK(result == util::to_span("First\nSecond\n")); } SUBCASE("Empty lines") { - const util::Bytes result = core::ShowIncludesParser::strip_includes( + const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes( ctx, util::to_span("First\n" "\n" @@ -150,7 +151,7 @@ TEST_CASE("ShowIncludesParser::strip_includes") SUBCASE("CRLF") { - const util::Bytes result = core::ShowIncludesParser::strip_includes( + const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes( ctx, util::to_span("First\r\n" "Note: including file: foo\r\n" @@ -161,7 +162,7 @@ TEST_CASE("ShowIncludesParser::strip_includes") SUBCASE("Custom prefix") { ctx.config.set_msvc_dep_prefix("custom"); - const util::Bytes result = core::ShowIncludesParser::strip_includes( + const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes( ctx, util::to_span("First\n" "custom: including file: foo\n"