summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2022-10-12 21:29:01 +0300
committerGitHub <noreply@github.com>2022-10-12 20:29:01 +0200
commitb1348e5f5ebe10b486b4e86f0114884a04f9531a (patch)
treeeacf9bb3dacf331ccb19cf032a68bd2e0ff90eca /src/core
parente505f1a57a784a4c58934b0e1dea3facfd326f3d (diff)
downloadccache-b1348e5f5ebe10b486b4e86f0114884a04f9531a.tar.gz
feat: Support depend mode for MSVC (#992)
Based on -showIncludes, which prints included files on stdout with a certain text prefix. Otherwise pretty similar to depend mode handling for GCC. This makes MSVC building way faster. Co-authored-by: Luboš Luňák <l.lunak@centrum.cz>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/ShowIncludesParser.cpp52
-rw-r--r--src/core/ShowIncludesParser.hpp31
3 files changed, 84 insertions, 0 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/ShowIncludesParser.cpp b/src/core/ShowIncludesParser.cpp
new file mode 100644
index 00000000..a25cf76a
--- /dev/null
+++ b/src/core/ShowIncludesParser.cpp
@@ -0,0 +1,52 @@
+// 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.
+
+ 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;
+}
+
+} // namespace core::ShowIncludesParser
diff --git a/src/core/ShowIncludesParser.hpp b/src/core/ShowIncludesParser.hpp
new file mode 100644
index 00000000..a977cec0
--- /dev/null
+++ b/src/core/ShowIncludesParser.hpp
@@ -0,0 +1,31 @@
+// 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);
+
+} // namespace core::ShowIncludesParser