summaryrefslogtreecommitdiff
path: root/src/buildtool/main/main.cpp
diff options
context:
space:
mode:
authorAlberto Sartori <alberto.sartori@huawei.com>2023-10-26 11:03:37 +0200
committerAlberto Sartori <alberto.sartori@huawei.com>2023-11-15 20:19:18 +0100
commite1e82f82251fc16b648571396ff27445a110c15e (patch)
treeca51e31c29a86a25806349343e4059a85532bc26 /src/buildtool/main/main.cpp
parentf6bf3fe59c14429947098c60b558a1b5b1ed6fa6 (diff)
downloadjustbuild-e1e82f82251fc16b648571396ff27445a110c15e.tar.gz
ReadConfiguredTarget: handle absent target roots
Diffstat (limited to 'src/buildtool/main/main.cpp')
-rw-r--r--src/buildtool/main/main.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 58ff080f..b6e7b63f 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -424,6 +424,36 @@ void SetupHashFunction() {
return Target::ConfiguredTarget{.target = std::move(*entity),
.config = std::move(config)};
}
+#ifndef BOOTSTRAP_BUILD_TOOL
+ if (target_root->IsAbsent()) {
+ // since the user has not specified the target to build, we use the most
+ // reasonable default value:
+ //
+ // module -> "." (i.e., current module)
+ // target -> "" (i.e., firstmost lexicographical target name)
+
+ auto target = nlohmann::json::parse(R"([".",""])");
+ Logger::Log(LogLevel::Debug,
+ "Detected absent target root for repo {} and no target was "
+ "given. Assuming default target {}",
+ main_repo,
+ target.dump());
+ auto entity = Base::ParseEntityNameFromJson(
+ target,
+ Base::EntityName{Base::NamedTarget{main_repo, current_module, ""}},
+ [&target](std::string const& parse_err) {
+ Logger::Log(LogLevel::Error,
+ "Parsing target name {} failed with:\n{}",
+ target.dump(),
+ parse_err);
+ });
+ if (not entity) {
+ std::exit(kExitFailure);
+ }
+ return Target::ConfiguredTarget{.target = std::move(*entity),
+ .config = std::move(config)};
+ }
+#endif
auto const target_file =
(std::filesystem::path{current_module} / target_file_name).string();
if (not target_root->IsFile(target_file)) {