diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/target_map/result_map.hpp | 20 | ||||
-rw-r--r-- | src/buildtool/common/cli.hpp | 26 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 12 |
3 files changed, 33 insertions, 25 deletions
diff --git a/src/buildtool/build_engine/target_map/result_map.hpp b/src/buildtool/build_engine/target_map/result_map.hpp index 14fd8f11..9753b9e0 100644 --- a/src/buildtool/build_engine/target_map/result_map.hpp +++ b/src/buildtool/build_engine/target_map/result_map.hpp @@ -18,9 +18,9 @@ #include <algorithm> #include <compare> #include <cstddef> +#include <filesystem> #include <fstream> #include <functional> -#include <iomanip> #include <iterator> #include <memory> #include <mutex> @@ -381,15 +381,21 @@ class ResultTargetMap { } template <bool kIncludeOrigins = true> - auto ToFile(std::string const& graph_file, + auto ToFile(std::vector<std::filesystem::path> const& destinations, gsl::not_null<Statistics const*> const& stats, gsl::not_null<Progress*> const& progress, int indent = 2) const -> void { - Logger::Log( - LogLevel::Info, "Dumping action graph to file {}.", graph_file); - std::ofstream os(graph_file); - os << std::setw(indent) << ToJson<kIncludeOrigins>(stats, progress) - << std::endl; + if (not destinations.empty()) { + // As serialization is expensive, compute the string only once + auto data = ToJson<kIncludeOrigins>(stats, progress).dump(indent); + for (auto const& graph_file : destinations) { + Logger::Log(LogLevel::Info, + "Dumping action graph to file {}.", + graph_file.string()); + std::ofstream os(graph_file); + os << data << std::endl; + } + } } void Clear(gsl::not_null<TaskSystem*> const& ts) { diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index ef6c043c..a8acea87 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -73,8 +73,8 @@ struct AnalysisArguments { std::optional<std::filesystem::path> target_root; std::optional<std::filesystem::path> rule_root; std::optional<std::filesystem::path> expression_root; - std::optional<std::filesystem::path> graph_file; - std::optional<std::filesystem::path> graph_file_plain; + std::vector<std::filesystem::path> graph_file; + std::vector<std::filesystem::path> graph_file_plain; std::optional<std::filesystem::path> artifacts_to_build_file; std::optional<std::filesystem::path> serve_errors_file; }; @@ -346,16 +346,22 @@ static inline auto SetupAnalysisArguments( "errors as json.") ->type_name("PATH"); if (with_graph) { - app->add_option( + app->add_option_function<std::string>( "--dump-graph", - clargs->graph_file, + [clargs](auto const& file_) { + clargs->graph_file.emplace_back(file_); + }, "File path for writing the action graph description to.") - ->type_name("PATH"); - app->add_option("--dump-plain-graph", - clargs->graph_file_plain, - "File path for writing the action graph description " - "(without origins) to.") - ->type_name("PATH"); + ->type_name("PATH") + ->trigger_on_parse(); + app->add_option_function<std::string>( + "--dump-plain-graph", + [clargs](auto const& file_) { + clargs->graph_file_plain.emplace_back(file_); + }, + "File path for writing the action graph description to.") + ->type_name("PATH") + ->trigger_on_parse(); app->add_option("--dump-artifacts-to-build", clargs->artifacts_to_build_file, "File path for writing the artifacts to build to.") diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index e4ac6a02..b8579b55 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -1150,14 +1150,10 @@ auto main(int argc, char* argv[]) -> int { not_eligible); } - if (arguments.analysis.graph_file) { - analyse_result->result_map.ToFile( - *arguments.analysis.graph_file, &stats, &progress); - } - if (arguments.analysis.graph_file_plain) { - analyse_result->result_map.ToFile</*kIncludeOrigins=*/false>( - *arguments.analysis.graph_file_plain, &stats, &progress); - } + analyse_result->result_map.ToFile( + arguments.analysis.graph_file, &stats, &progress); + analyse_result->result_map.ToFile</*kIncludeOrigins=*/false>( + arguments.analysis.graph_file_plain, &stats, &progress); auto const [artifacts, runfiles] = ReadOutputArtifacts(analyse_result->target); if (arguments.analysis.artifacts_to_build_file) { |