summaryrefslogtreecommitdiff
path: root/src/buildtool/main/main.cpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-11-07 09:00:00 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-11-11 15:28:36 +0100
commitbbd3319a00e91bd50fcabeb99e6096a349f692ca (patch)
treec9be59eb9a81b0ca331ea241539e92437e478f32 /src/buildtool/main/main.cpp
parent78c51ae888d8e7bf6a0c77d905179b30eaf54d8c (diff)
downloadjustbuild-bbd3319a00e91bd50fcabeb99e6096a349f692ca.tar.gz
Support dumping variables of the analysed target
Add an option --dump-vars showing the variables of the configuration used (including the use of them being unset). This information can be used, e.g., to export a given target in a maximally flexible way.
Diffstat (limited to 'src/buildtool/main/main.cpp')
-rw-r--r--src/buildtool/main/main.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index ac74fdce..ded21591 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -746,6 +746,29 @@ void DumpBlobs(std::string const& file_path, AnalysisResult const& result) {
}
}
+void DumpVars(std::string const& file_path, AnalysisResult const& result) {
+ auto vars = std::vector<std::string>{};
+ vars.reserve(result.target->Vars().size());
+ for (auto const& x : result.target->Vars()) {
+ vars.push_back(x);
+ }
+ std::sort(vars.begin(), vars.end());
+ auto const dump_string = nlohmann::json(vars).dump();
+ if (file_path == "-") {
+ Logger::Log(
+ LogLevel::Info, "Variables for target {}:", result.id.ToString());
+ std::cout << dump_string << std::endl;
+ }
+ else {
+ Logger::Log(LogLevel::Info,
+ "Dumping varables for target {} to file '{}'.",
+ result.id.ToString(),
+ file_path);
+ std::ofstream os(file_path);
+ os << dump_string << std::endl;
+ }
+}
+
void DumpTrees(std::string const& file_path, AnalysisResult const& result) {
auto const dump_string = TreesToJson(result.target).dump(2);
if (file_path == "-") {
@@ -912,6 +935,9 @@ void DumpNodes(std::string const& file_path, AnalysisResult const& result) {
if (clargs.dump_trees) {
DumpTrees(*clargs.dump_trees, result);
}
+ if (clargs.dump_vars) {
+ DumpVars(*clargs.dump_vars, result);
+ }
if (clargs.dump_targets) {
DumpTargets(*clargs.dump_targets, result_map.ConfiguredTargets());
}