diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2022-10-05 20:34:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 19:34:31 +0200 |
commit | 8b65880b5ad817156b58c58b5133aafc99b0a264 (patch) | |
tree | 6e157bbbe48186daa65908a012c76721b48d66cc /src/core | |
parent | 9d3188484149a0d0b914f855b9ae1956c37d76c1 (diff) | |
download | ccache-8b65880b5ad817156b58c58b5133aafc99b0a264.tar.gz |
feat: Support auto depend mode for MSVC without /showIncludes (#1158)
Co-authored-by: Luboš Luňák <l.lunak@centrum.cz>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/core/ResultRetriever.cpp | 6 | ||||
-rw-r--r-- | src/core/ShowIncludesParser.cpp | 78 | ||||
-rw-r--r-- | src/core/ShowIncludesParser.hpp | 33 |
4 files changed, 117 insertions, 1 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d2431be3..6932336f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -6,6 +6,7 @@ set( ResultExtractor.cpp ResultInspector.cpp ResultRetriever.cpp + ShowIncludesParser.cpp Statistics.cpp StatisticsCounters.cpp StatsLog.cpp diff --git a/src/core/ResultRetriever.cpp b/src/core/ResultRetriever.cpp index bdefc19f..95925836 100644 --- a/src/core/ResultRetriever.cpp +++ b/src/core/ResultRetriever.cpp @@ -24,6 +24,7 @@ #include <Context.hpp> #include <Stat.hpp> +#include <core/ShowIncludesParser.hpp> #include <core/exceptions.hpp> #include <core/wincompat.hpp> #include <fmtmacros.hpp> @@ -61,7 +62,10 @@ ResultRetriever::on_embedded_file(uint8_t file_number, data.size()); if (file_type == FileType::stdout_output) { - Util::send_to_fd(m_ctx, util::to_string_view(data), STDOUT_FILENO); + std::string str = util::to_string(util::to_string_view(data)); + Util::send_to_fd(m_ctx, + ShowIncludesParser::strip_includes(m_ctx, std::move(str)), + STDOUT_FILENO); } else if (file_type == FileType::stderr_output) { Util::send_to_fd(m_ctx, util::to_string_view(data), STDERR_FILENO); } else { diff --git a/src/core/ShowIncludesParser.cpp b/src/core/ShowIncludesParser.cpp new file mode 100644 index 00000000..318e8237 --- /dev/null +++ b/src/core/ShowIncludesParser.cpp @@ -0,0 +1,78 @@ +// Copyright (C) 2022 Joel Rosdahl and other contributors +// +// See doc/AUTHORS.adoc for a complete list of contributors. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// 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 <Context.hpp> +#include <Util.hpp> +#include <util/string.hpp> + +namespace core::ShowIncludesParser { + +std::vector<std::string_view> +tokenize(std::string_view file_content, std::string_view prefix) +{ + // -showIncludes output is written to stdout together with other messages. + // Every line of it is '<prefix> <spaces> <file>', prefix is 'Note: including + // file:' in English but can be localized. + + if (prefix.empty()) { + prefix = "Note: including file:"; + } + + std::vector<std::string_view> result; + // This will split at each \r or \n, but that simply means there will be empty + // "lines". + for (std::string_view line : Util::split_into_views(file_content, "\r\n")) { + if (util::starts_with(line, prefix)) { + size_t pos = prefix.size(); + while (pos < line.size() && isspace(line[pos])) { + ++pos; + } + std::string_view include = line.substr(pos); + if (!include.empty()) { + result.push_back(include); + } + } + } + return result; +} + +std::string +strip_includes(const Context& ctx, std::string&& stdout_data) +{ + using util::Tokenizer; + using Mode = Tokenizer::Mode; + using IncludeDelimiter = Tokenizer::IncludeDelimiter; + + if (stdout_data.empty() || !ctx.auto_depend_mode + || ctx.config.compiler_type() != CompilerType::msvc) { + return std::move(stdout_data); + } + + std::string new_stdout_text; + for (const auto line : Tokenizer( + stdout_data, "\n", Mode::include_empty, IncludeDelimiter::yes)) { + if (!util::starts_with(line, "Note: including file:")) { + new_stdout_text.append(line.data(), line.length()); + } + } + return new_stdout_text; +} + +} // namespace core::ShowIncludesParser diff --git a/src/core/ShowIncludesParser.hpp b/src/core/ShowIncludesParser.hpp new file mode 100644 index 00000000..ebc2284b --- /dev/null +++ b/src/core/ShowIncludesParser.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2022 Joel Rosdahl and other contributors +// +// See doc/AUTHORS.adoc for a complete list of contributors. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +#pragma once + +#include <string_view> +#include <vector> + +class Context; + +namespace core::ShowIncludesParser { + +std::vector<std::string_view> tokenize(std::string_view file_content, + std::string_view prefix); + +std::string strip_includes(const Context& ctx, std::string&& stdout_data); + +} // namespace core::ShowIncludesParser |