Don't use the default boot image location with non-default bootclasspath
Some unit tests are using a non-default bootclasspath. In such cases,
the runtime cannot use the default boot image location anyway.
Before this change, during those tests, the runtime attempted to use the
default boot image location and then rejected it. This workflow worked
for a long time. However, it no longer works since aosp/2458432 because
that CL introduced some logic that infers the default boot image
location based on environment variables, which may not exist in some
chroot environment.
After this change, the runtime doesn't attempt to use the default boot
image location at all.
This fixes the LUCI breakage caused by aosp/2458432.
Bug: 269230245
Test: Presubmit
Change-Id: Iecd9b7d05fa91fd96eee5072ca5797c08c36a16e
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 03f5fe7..d093878 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <sys/stat.h>
+#include <algorithm>
#include <forward_list>
#include <fstream>
#include <iostream>
@@ -724,8 +725,15 @@
if (!IsBootImage() && boot_image_filename_.empty()) {
DCHECK(!IsBootImageExtension());
- boot_image_filename_ =
- GetDefaultBootImageLocation(android_root_, /*deny_art_apex_data_files=*/false);
+ if (std::any_of(runtime_args_.begin(), runtime_args_.end(), [](const char* arg) {
+ return android::base::StartsWith(arg, "-Xbootclasspath:");
+ })) {
+ LOG(WARNING) << "--boot-image is not specified while -Xbootclasspath is specified. Running "
+ "dex2oat in imageless mode";
+ } else {
+ boot_image_filename_ =
+ GetDefaultBootImageLocation(android_root_, /*deny_art_apex_data_files=*/false);
+ }
}
if (dex_filenames_.empty() && zip_fd_ == -1) {
diff --git a/libartbase/base/file_utils.h b/libartbase/base/file_utils.h
index a8fb006..408163f 100644
--- a/libartbase/base/file_utils.h
+++ b/libartbase/base/file_utils.h
@@ -80,6 +80,8 @@
// Returns the default boot image location, based on the passed `android_root`.
// Returns an empty string if an error occurs.
+// The default boot image location can only be used with the default bootclasspath (the value of the
+// BOOTCLASSPATH environment variable).
std::string GetDefaultBootImageLocationSafe(const std::string& android_root,
bool deny_art_apex_data_files,
std::string* error_msg);
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index b682e60..6b77ce8 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -674,6 +674,7 @@
using M = RuntimeArgumentMap;
RuntimeArgumentMap args = parser->ReleaseArgumentsMap();
+ bool use_default_bootclasspath = true;
// -help, -showversion, etc.
if (args.Exists(M::Help)) {
@@ -687,6 +688,7 @@
Exit(0);
} else if (args.Exists(M::BootClassPath)) {
LOG(INFO) << "setting boot class path to " << args.Get(M::BootClassPath)->Join();
+ use_default_bootclasspath = false;
}
if (args.GetOrDefault(M::Interpret)) {
@@ -776,7 +778,8 @@
args.Set(M::AllowInMemoryCompilation, Unit());
}
- if (!args.Exists(M::CompilerCallbacksPtr) && !args.Exists(M::Image)) {
+ if (!args.Exists(M::CompilerCallbacksPtr) && !args.Exists(M::Image) &&
+ use_default_bootclasspath) {
const bool deny_art_apex_data_files = args.Exists(M::DenyArtApexDataFiles);
std::string image_locations =
GetDefaultBootImageLocation(GetAndroidRoot(), deny_art_apex_data_files);