summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/main/cli.cpp5
-rw-r--r--src/buildtool/main/describe.cpp24
-rw-r--r--src/buildtool/main/exit_codes.hpp5
-rw-r--r--src/buildtool/main/main.cpp62
4 files changed, 55 insertions, 41 deletions
diff --git a/src/buildtool/main/cli.cpp b/src/buildtool/main/cli.cpp
index bfb79858..61ef7a09 100644
--- a/src/buildtool/main/cli.cpp
+++ b/src/buildtool/main/cli.cpp
@@ -225,10 +225,11 @@ auto ParseCommandLineArguments(int argc, char const* const* argv)
try {
app.parse(argc, argv);
} catch (CLI::Error& e) {
- std::exit(app.exit(e));
+ auto exit_code = app.exit(e);
+ std::exit(exit_code == 0 ? kExitSuccess : kExitSyntaxError);
} catch (std::exception const& ex) {
Logger::Log(LogLevel::Error, "Command line parse error: {}", ex.what());
- std::exit(kExitFailure);
+ std::exit(kExitSyntaxError);
}
if (*cmd_version) {
diff --git a/src/buildtool/main/describe.cpp b/src/buildtool/main/describe.cpp
index f2dcadf4..96a99d69 100644
--- a/src/buildtool/main/describe.cpp
+++ b/src/buildtool/main/describe.cpp
@@ -259,14 +259,14 @@ auto DescribeUserDefinedRule(
});
}
if (failed) {
- return kExitFailure;
+ return kExitAnalysisFailure;
}
auto ruledesc_it = rules_file.find(rule_name.GetNamedTarget().name);
if (ruledesc_it == rules_file.end()) {
Logger::Log(LogLevel::Error,
"Rule definition of {} is missing",
rule_name.ToString());
- return kExitFailure;
+ return kExitAnalysisFailure;
}
if (print_json) {
PrintRuleAsOrderedJson(*ruledesc_it, rule_name.ToJson());
@@ -291,7 +291,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
"endpoint was configured. Please provide "
"--remote-serve-address and retry.",
id.target.ToJson().dump()));
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// check that just serve and the client use same remote execution
// endpoint; it might make sense in the future to remove or avoid this
@@ -300,7 +300,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
Logger::Log(LogLevel::Error,
"Inconsistent remote execution endpoint and serve "
"endpoint configuration detected.");
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// ask serve endpoint to provide the description
auto const& repo_name = id.target.ToModule().repository;
@@ -311,7 +311,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
LogLevel::Error,
"Failed to get the target root id for repository \"{}\"",
repo_name);
- return kExitFailure;
+ return kExitBuildEnvironment;
}
if (auto dgst = serve->ServeTargetDescription(
*target_root_id,
@@ -332,7 +332,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
Logger::Log(LogLevel::Error,
"Failed to retrieve blob {} from remote CAS",
desc_info.ToString());
- return kExitFailure;
+ return kExitBuildEnvironment;
}
}
auto const desc_str = apis.local->RetrieveToMemory(desc_info);
@@ -340,7 +340,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
Logger::Log(LogLevel::Error,
"Could not load in memory blob {}",
desc_info.ToString());
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// parse blob into JSON object
nlohmann::json desc;
@@ -351,7 +351,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
LogLevel::Error,
"Parsing served target description failed with:\n{}",
ex.what());
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// serve endpoint already checked that this target is of
// "type": "export", so we can just print the description
@@ -380,7 +380,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
"Serve endpoint could not provide description of target {} "
"with absent root.",
id.target.ToJson().dump());
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// process with a present target root
@@ -401,7 +401,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
});
}
if (failed) {
- return kExitFailure;
+ return kExitAnalysisFailure;
}
auto desc_it = targets_file.find(id.target.GetNamedTarget().name);
if (desc_it == targets_file.end()) {
@@ -415,7 +415,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
Logger::Log(LogLevel::Error,
"{} is a target without specified type.",
id.ToString());
- return kExitFailure;
+ return kExitAnalysisFailure;
}
if (BuildMaps::Target::IsBuiltInRule(*rule_it)) {
if (print_json) {
@@ -470,7 +470,7 @@ auto DescribeTarget(BuildMaps::Target::ConfiguredTarget const& id,
parse_err);
});
if (not rule_name) {
- return kExitFailure;
+ return kExitAnalysisFailure;
}
if (not print_json) {
std::cout << id.ToString() << " is defined by user-defined rule "
diff --git a/src/buildtool/main/exit_codes.hpp b/src/buildtool/main/exit_codes.hpp
index c690c22c..41d2925f 100644
--- a/src/buildtool/main/exit_codes.hpp
+++ b/src/buildtool/main/exit_codes.hpp
@@ -20,7 +20,10 @@
enum ExitCodes : std::uint8_t {
kExitSuccess = 0,
kExitFailure = 1,
- kExitSuccessFailedArtifacts = 2
+ kExitSuccessFailedArtifacts = 2,
+ kExitAnalysisFailure = 8,
+ kExitBuildEnvironment = 16,
+ kExitSyntaxError = 32
};
#endif // INCLUDED_SRC_BUILDTOOL_MAIN_EXIT_CODES_HPP
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index a0aa27fe..0a979a78 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -765,25 +765,25 @@ auto main(int argc, char* argv[]) -> int {
auto const storage_config = CreateStorageConfig(
arguments.endpoint, arguments.protocol.hash_type);
if (not storage_config) {
- return kExitFailure;
+ return kExitBuildEnvironment;
}
if (GarbageCollector::TriggerGarbageCollection(
*storage_config, arguments.gc.no_rotate)) {
return kExitSuccess;
}
- return kExitFailure;
+ return kExitBuildEnvironment;
}
auto local_exec_config = CreateLocalExecutionConfig(arguments.build);
if (not local_exec_config) {
- return kExitFailure;
+ return kExitBuildEnvironment;
}
auto auth_config =
CreateAuthConfig(arguments.auth, arguments.cauth, arguments.sauth);
if (not auth_config) {
- return kExitFailure;
+ return kExitBuildEnvironment;
}
if (arguments.cmd == SubCommand::kExecute) {
@@ -803,7 +803,7 @@ auto main(int argc, char* argv[]) -> int {
auto const storage_config = CreateStorageConfig(
arguments.endpoint, arguments.protocol.hash_type);
if (not storage_config) {
- return kExitFailure;
+ return kExitBuildEnvironment;
}
auto const storage = Storage::Create(&*storage_config);
@@ -830,20 +830,20 @@ auto main(int argc, char* argv[]) -> int {
? kExitSuccess
: kExitFailure;
}
- return kExitFailure;
+ return kExitBuildEnvironment;
}
auto serve_config = CreateServeConfig(
arguments.serve, arguments.common, arguments.build, arguments.tc);
if (not serve_config) {
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// Set up the retry arguments, needed only for the client-side logic of
// remote execution, i.e., just serve and the regular just client.
auto retry_config = CreateRetryConfig(arguments.retry);
if (not retry_config) {
- return kExitFailure;
+ return kExitBuildEnvironment;
}
if (arguments.cmd == SubCommand::kServe) {
@@ -859,7 +859,7 @@ auto main(int argc, char* argv[]) -> int {
auto remote_exec_config = CreateRemoteExecutionConfig(
arguments.endpoint, arguments.rebuild);
if (not remote_exec_config) {
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// Set up storage for serve operation.
@@ -870,7 +870,7 @@ auto main(int argc, char* argv[]) -> int {
remote_exec_config->platform_properties,
remote_exec_config->dispatch);
if (not storage_config) {
- return kExitFailure;
+ return kExitBuildEnvironment;
}
auto const storage = Storage::Create(&*storage_config);
@@ -910,7 +910,7 @@ auto main(int argc, char* argv[]) -> int {
? kExitSuccess
: kExitFailure;
}
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// Setup profile logging, if requested
@@ -937,9 +937,9 @@ auto main(int argc, char* argv[]) -> int {
CreateRemoteExecutionConfig(arguments.endpoint, arguments.rebuild);
if (not remote_exec_config) {
if (profile != nullptr) {
- profile->Write(kExitFailure);
+ profile->Write(kExitBuildEnvironment);
}
- return kExitFailure;
+ return kExitBuildEnvironment;
}
// Set up storage for client-side operation. This needs to have all the
@@ -959,9 +959,9 @@ auto main(int argc, char* argv[]) -> int {
#endif // BOOTSTRAP_BUILD_TOOL
if (not storage_config) {
if (profile != nullptr) {
- profile->Write(kExitFailure);
+ profile->Write(kExitBuildEnvironment);
}
- return kExitFailure;
+ return kExitBuildEnvironment;
}
auto const storage = Storage::Create(&*storage_config);
@@ -1025,12 +1025,12 @@ auto main(int argc, char* argv[]) -> int {
return FetchAndInstallArtifacts(
main_apis, arguments.fetch, remote_context)
? kExitSuccess
- : kExitFailure;
+ : kExitBuildEnvironment;
}
if (arguments.cmd == SubCommand::kAddToCas) {
return AddArtifactsToCas(arguments.to_add, storage, main_apis)
? kExitSuccess
- : kExitFailure;
+ : kExitBuildEnvironment;
}
#endif // BOOTSTRAP_BUILD_TOOL
@@ -1050,9 +1050,9 @@ auto main(int argc, char* argv[]) -> int {
&exec_context,
eval_root_jobs)) {
if (profile != nullptr) {
- profile->Write(kExitFailure);
+ profile->Write(kExitAnalysisFailure);
}
- return kExitFailure;
+ return kExitAnalysisFailure;
}
#else
std::optional<ServeApi> serve;
@@ -1062,9 +1062,9 @@ auto main(int argc, char* argv[]) -> int {
auto lock = GarbageCollector::SharedLock(*storage_config);
if (not lock) {
if (profile != nullptr) {
- profile->Write(kExitFailure);
+ profile->Write(kExitBuildEnvironment);
}
- return kExitFailure;
+ return kExitBuildEnvironment;
}
if (arguments.cmd == SubCommand::kTraverse) {
@@ -1076,7 +1076,7 @@ auto main(int argc, char* argv[]) -> int {
"together.",
"--git-cas",
"--compatible");
- return kExitFailure;
+ return kExitSyntaxError;
}
if (not repo_config.SetGitCAS(*arguments.graph.git_cas,
LogLevel::Debug)) {
@@ -1114,9 +1114,9 @@ auto main(int argc, char* argv[]) -> int {
return result;
}
if (profile != nullptr) {
- profile->Write(kExitFailure);
+ profile->Write(kExitAnalysisFailure);
}
- return kExitFailure;
+ return kExitAnalysisFailure;
}
#endif // BOOTSTRAP_BUILD_TOOL
@@ -1276,14 +1276,24 @@ auto main(int argc, char* argv[]) -> int {
}
return result;
}
+ if (profile != nullptr) {
+ profile->Write(kExitFailure);
+ }
+ return kExitFailure;
#endif // BOOTSTRAP_BUILD_TOOL
}
+ else {
+ if (profile != nullptr) {
+ profile->Write(kExitAnalysisFailure);
+ }
+ return kExitAnalysisFailure;
+ }
} catch (std::exception const& ex) {
Logger::Log(
LogLevel::Error, "Caught exception with message: {}", ex.what());
}
if (profile != nullptr) {
- profile->Write(kExitFailure);
+ profile->Write(kExitBuildEnvironment);
}
- return kExitFailure;
+ return kExitBuildEnvironment;
}