odrefresh should exit non-zero for invalid argument
This fixes two cases.
1. "Expected 1 argument, but have %d."
2. unknown action
Because of 1, the loop is actually not necessary (as pointed out by the
compiler), so removed.
With 2 now exits, the default return is never eached, thus deleted.
Bug: 205750213
Test: atest art_standalone_odrefresh_tests
Test: atest ComposHostTestCases
Change-Id: Ifc198e888045e633a63a918509faf9a0fe1e24fb
diff --git a/odrefresh/odrefresh_main.cc b/odrefresh/odrefresh_main.cc
index 0798ade..a70e2fb 100644
--- a/odrefresh/odrefresh_main.cc
+++ b/odrefresh/odrefresh_main.cc
@@ -182,6 +182,7 @@
config->SetZygoteKind(zygote_kind);
} else if (!InitializeCommonConfig(arg, config)) {
UsageError("Unrecognized argument: '%s'", arg);
+ exit(EX_USAGE);
}
}
return n;
@@ -322,48 +323,48 @@
argc -= n;
if (argc != 1) {
UsageError("Expected 1 argument, but have %d.", argc);
+ exit(EX_USAGE);
}
OdrMetrics metrics(config.GetArtifactDirectory());
OnDeviceRefresh odr(config);
- for (int i = 0; i < argc; ++i) {
- std::string_view action(argv[i]);
- CompilationOptions compilation_options;
- if (action == "--check") {
- // Fast determination of whether artifacts are up to date.
- return odr.CheckArtifactsAreUpToDate(metrics, &compilation_options);
- } else if (action == "--compile") {
- const ExitCode exit_code = odr.CheckArtifactsAreUpToDate(metrics, &compilation_options);
- if (exit_code != ExitCode::kCompilationRequired) {
- return exit_code;
- }
- OdrCompilationLog compilation_log;
- if (!compilation_log.ShouldAttemptCompile(metrics.GetTrigger())) {
- LOG(INFO) << "Compilation skipped because it was attempted recently";
- return ExitCode::kOkay;
- }
- ExitCode compile_result = odr.Compile(metrics, compilation_options);
- compilation_log.Log(metrics.GetArtApexVersion(),
- metrics.GetArtApexLastUpdateMillis(),
- metrics.GetTrigger(),
- compile_result);
- return compile_result;
- } else if (action == "--force-compile") {
- // Clean-up existing files.
- if (!odr.RemoveArtifactsDirectory()) {
- metrics.SetStatus(OdrMetrics::Status::kIoError);
- return ExitCode::kCleanupFailed;
- }
- return odr.Compile(metrics,
- CompilationOptions{
- .compile_boot_extensions_for_isas = config.GetBootExtensionIsas(),
- .system_server_jars_to_compile = odr.AllSystemServerJars(),
- });
- } else if (action == "--help") {
- UsageHelp(argv[0]);
- } else {
- UsageError("Unknown argument: ", argv[i]);
+
+ std::string_view action(argv[0]);
+ CompilationOptions compilation_options;
+ if (action == "--check") {
+ // Fast determination of whether artifacts are up to date.
+ return odr.CheckArtifactsAreUpToDate(metrics, &compilation_options);
+ } else if (action == "--compile") {
+ const ExitCode exit_code = odr.CheckArtifactsAreUpToDate(metrics, &compilation_options);
+ if (exit_code != ExitCode::kCompilationRequired) {
+ return exit_code;
}
+ OdrCompilationLog compilation_log;
+ if (!compilation_log.ShouldAttemptCompile(metrics.GetTrigger())) {
+ LOG(INFO) << "Compilation skipped because it was attempted recently";
+ return ExitCode::kOkay;
+ }
+ ExitCode compile_result = odr.Compile(metrics, compilation_options);
+ compilation_log.Log(metrics.GetArtApexVersion(),
+ metrics.GetArtApexLastUpdateMillis(),
+ metrics.GetTrigger(),
+ compile_result);
+ return compile_result;
+ } else if (action == "--force-compile") {
+ // Clean-up existing files.
+ if (!odr.RemoveArtifactsDirectory()) {
+ metrics.SetStatus(OdrMetrics::Status::kIoError);
+ return ExitCode::kCleanupFailed;
+ }
+ return odr.Compile(metrics,
+ CompilationOptions{
+ .compile_boot_extensions_for_isas = config.GetBootExtensionIsas(),
+ .system_server_jars_to_compile = odr.AllSystemServerJars(),
+ });
+ } else if (action == "--help") {
+ UsageHelp(argv[0]);
+ } else {
+ UsageError("Unknown argument: ", action);
+ exit(EX_USAGE);
}
- return ExitCode::kOkay;
}