diff options
author | 2023-02-27 16:21:11 +0000 | |
---|---|---|
committer | 2023-02-27 18:20:36 +0000 | |
commit | 51754b860868fc5629da6b572e6966448834e293 (patch) | |
tree | 2bd5d496b1ddcf280db3cde8d1f93540c16394bc | |
parent | 771b44f32420c613acdf2046777c6df7d68a2734 (diff) |
Revert "Add the mainline framework boot image extension to the default."
This reverts commit c66398d182443208e73133705da1a25a3794fc8e.
Reason for revert: Maybe(?) caused regressions on Golem.
Bug: 270958761
Change-Id: If9f27d2cbe2d22a1f4bd1e0efab8f85d0e1f1a78
-rw-r--r-- | dexoptanalyzer/dexoptanalyzer.cc | 11 | ||||
-rw-r--r-- | libartbase/base/file_utils.cc | 119 | ||||
-rw-r--r-- | libartbase/base/file_utils.h | 10 | ||||
-rw-r--r-- | test/dexpreopt/dexpreopt_test.cc | 10 |
4 files changed, 34 insertions, 116 deletions
diff --git a/dexoptanalyzer/dexoptanalyzer.cc b/dexoptanalyzer/dexoptanalyzer.cc index b182f68a7f..ef4315739b 100644 --- a/dexoptanalyzer/dexoptanalyzer.cc +++ b/dexoptanalyzer/dexoptanalyzer.cc @@ -239,16 +239,11 @@ class DexoptAnalyzer final { // If we don't receive the image, try to use the default one. // Tests may specify a different image (e.g. core image). std::string error_msg; - std::string android_root = GetAndroidRootSafe(&error_msg); - if (android_root.empty()) { - LOG(ERROR) << error_msg; - Usage("--image unspecified and ANDROID_ROOT not set."); - } - image_ = GetDefaultBootImageLocationSafe( - android_root, /*deny_art_apex_data_files=*/false, &error_msg); + image_ = GetDefaultBootImageLocation(&error_msg); + if (image_.empty()) { LOG(ERROR) << error_msg; - Usage("--image unspecified and failed to get default boot image location."); + Usage("--image unspecified and ANDROID_ROOT not set or image file does not exist."); } } } diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc index bf0422a954..239628978e 100644 --- a/libartbase/base/file_utils.cc +++ b/libartbase/base/file_utils.cc @@ -40,7 +40,6 @@ #include <memory> #include <sstream> -#include <vector> #include "android-base/file.h" #include "android-base/logging.h" @@ -51,7 +50,6 @@ #include "base/os.h" #include "base/stl_util.h" #include "base/unix_file/fd_file.h" -#include "base/utils.h" #if defined(__APPLE__) #include <crt_externs.h> @@ -80,7 +78,6 @@ static constexpr const char* kAndroidConscryptRootEnvVar = "ANDROID_CONSCRYPT_RO static constexpr const char* kAndroidI18nRootEnvVar = "ANDROID_I18N_ROOT"; static constexpr const char* kApexDefaultPath = "/apex/"; static constexpr const char* kArtApexDataEnvVar = "ART_APEX_DATA"; -static constexpr const char* kBootImageStem = "boot"; // Get the "root" directory containing the "lib" directory where this instance // of the libartbase library (which contains `GetRootContainingLibartbase`) is @@ -301,73 +298,10 @@ std::string GetPrebuiltPrimaryBootImageDir() { return GetPrebuiltPrimaryBootImageDir(android_root); } -static std::string GetFirstMainlineFrameworkLibraryName(std::string* error_msg) { - const char* env_bcp = getenv("BOOTCLASSPATH"); - const char* env_dex2oat_bcp = getenv("DEX2OATBOOTCLASSPATH"); - if (env_bcp == nullptr || env_dex2oat_bcp == nullptr) { - *error_msg = "BOOTCLASSPATH and DEX2OATBOOTCLASSPATH must not be empty"; - return ""; - } - - // DEX2OATBOOTCLASSPATH contains core libraries and framework libraries. We used to only compile - // those libraries. Now we compile mainline framework libraries as well, and we have repurposed - // DEX2OATBOOTCLASSPATH to indicate the separation between mainline framework libraries and other - // libraries. - std::string_view mainline_bcp(env_bcp); - if (!android::base::ConsumePrefix(&mainline_bcp, env_dex2oat_bcp)) { - *error_msg = "DEX2OATBOOTCLASSPATH must be a prefix of BOOTCLASSPATH"; - return ""; - } - - std::vector<std::string_view> mainline_bcp_jars; - Split(mainline_bcp, ':', &mainline_bcp_jars); - if (mainline_bcp_jars.empty()) { - *error_msg = "No mainline framework library found"; - return ""; - } - - std::string jar_name = android::base::Basename(mainline_bcp_jars[0]); - - std::string_view library_name(jar_name); - if (!android::base::ConsumeSuffix(&library_name, ".jar")) { - *error_msg = "Invalid mainline framework jar: " + jar_name; - return ""; - } - - return std::string(library_name); -} - -// Returns true when no error occurs, even if the extension doesn't exist. -static bool MaybeAppendBootImageMainlineExtension(const std::string& android_root, - /*inout*/ std::string* location, - /*out*/ std::string* error_msg) { - if (!kIsTargetAndroid) { - return true; - } - // Due to how the runtime determines the mapping between boot images and bootclasspath jars, the - // name of the boot image extension must be in the format of - // `<primary-boot-image-stem>-<first-library-name>.art`. - std::string library_name = GetFirstMainlineFrameworkLibraryName(error_msg); - if (library_name.empty()) { - return false; - } - std::string mainline_extension_location = StringPrintf( - "%s/framework/%s-%s.art", android_root.c_str(), kBootImageStem, library_name.c_str()); - std::string mainline_extension_path = - GetSystemImageFilename(mainline_extension_location.c_str(), kRuntimeISA); - if (!OS::FileExists(mainline_extension_path.c_str(), /*check_file_type=*/true)) { - // This is expected when the ART module is preloaded on an old source tree that doesn't - // dexpreopt mainline BCP jars, so it shouldn't be considered as an error. - return true; - } - *location += ":" + mainline_extension_location; - return true; -} - -std::string GetDefaultBootImageLocationSafe(const std::string& android_root, - bool deny_art_apex_data_files, - std::string* error_msg) { +std::string GetDefaultBootImageLocation(const std::string& android_root, + bool deny_art_apex_data_files) { constexpr static const char* kEtcBootImageProf = "etc/boot-image.prof"; + constexpr static const char* kBootImageStem = "boot"; constexpr static const char* kMinimalBootImageStem = "boot_minimal"; // If an update for the ART module has been been installed, a single boot image for the entire @@ -413,37 +347,28 @@ std::string GetDefaultBootImageLocationSafe(const std::string& android_root, PLOG(ERROR) << "Minimal boot image check failed, could not stat: " << boot_image_filename; } } - - // Boot image consists of three parts: + // Boot image consists of two parts: // - the primary boot image (contains the Core Libraries) - // - the boot image framework extension (contains framework libraries) - // - the boot image mainline extension (contains mainline framework libraries) - // Typically "/system/framework/boot.art!/apex/com.android.art/etc/boot-image.prof: - // /system/framework/boot-framework.art!/system/etc/boot-image.prof: - // /system/framework/boot-framework-adservices.art". - - std::string location = StringPrintf("%s/%s.art!%s/%s:%s/framework/%s-framework.art!%s/%s", - GetPrebuiltPrimaryBootImageDir(android_root).c_str(), - kBootImageStem, - kAndroidArtApexDefaultPath, - kEtcBootImageProf, - android_root.c_str(), - kBootImageStem, - android_root.c_str(), - kEtcBootImageProf); - if (!MaybeAppendBootImageMainlineExtension(android_root, &location, error_msg)) { + // - the boot image extensions (contains framework libraries) + // Typically "/apex/com.android.art/javalib/boot.art!/apex/com.android.art/etc/boot-image.prof: + // /system/framework/boot-framework.art!/system/etc/boot-image.prof". + return StringPrintf("%s/%s.art!%s/%s:%s/framework/%s-framework.art!%s/%s", + GetPrebuiltPrimaryBootImageDir(android_root).c_str(), + kBootImageStem, + kAndroidArtApexDefaultPath, + kEtcBootImageProf, + android_root.c_str(), + kBootImageStem, + android_root.c_str(), + kEtcBootImageProf); +} + +std::string GetDefaultBootImageLocation(std::string* error_msg) { + std::string android_root = GetAndroidRootSafe(error_msg); + if (android_root.empty()) { return ""; } - return location; -} - -std::string GetDefaultBootImageLocation(const std::string& android_root, - bool deny_art_apex_data_files) { - std::string error_msg; - std::string location = - GetDefaultBootImageLocationSafe(android_root, deny_art_apex_data_files, &error_msg); - CHECK(!location.empty()) << error_msg; - return location; + return GetDefaultBootImageLocation(android_root, /*deny_art_apex_data_files=*/false); } std::string GetJitZygoteBootImageLocation() { diff --git a/libartbase/base/file_utils.h b/libartbase/base/file_utils.h index a8fb0064a9..f539f5fd55 100644 --- a/libartbase/base/file_utils.h +++ b/libartbase/base/file_utils.h @@ -78,13 +78,11 @@ std::string GetArtApexData(); // generated at build time). std::string GetPrebuiltPrimaryBootImageDir(); -// Returns the default boot image location, based on the passed `android_root`. -// Returns an empty string if an error occurs. -std::string GetDefaultBootImageLocationSafe(const std::string& android_root, - bool deny_art_apex_data_files, - std::string* error_msg); +// Returns the default boot image location (ANDROID_ROOT/framework/boot.art). +// Returns an empty string if ANDROID_ROOT is not set. +std::string GetDefaultBootImageLocation(std::string* error_msg); -// Same as above, but fails if an error occurs. +// Returns the default boot image location, based on the passed `android_root`. std::string GetDefaultBootImageLocation(const std::string& android_root, bool deny_art_apex_data_files); diff --git a/test/dexpreopt/dexpreopt_test.cc b/test/dexpreopt/dexpreopt_test.cc index 3fb2730cc1..55593eae66 100644 --- a/test/dexpreopt/dexpreopt_test.cc +++ b/test/dexpreopt/dexpreopt_test.cc @@ -46,7 +46,7 @@ namespace art { -using ::testing::IsSupersetOf; +using ::testing::IsSubsetOf; constexpr const char* kZygote32 = "zygote"; constexpr const char* kZygote64 = "zygote64"; @@ -95,9 +95,9 @@ android::base::Result<std::vector<std::pair<std::string, InstructionSet>>> GetZy } android::base::Result<std::vector<std::string>> GetZygoteExpectedArtifacts(InstructionSet isa) { - std::vector<std::string> jars = GetListFromEnv("BOOTCLASSPATH"); + std::vector<std::string> jars = GetListFromEnv("DEX2OATBOOTCLASSPATH"); if (jars.empty()) { - return Errorf("Environment variable `BOOTCLASSPATH` is not defined or empty"); + return Errorf("Environment variable `DEX2OATBOOTCLASSPATH` is not defined or empty"); } std::string art_root = GetArtRoot(); std::string android_root = GetAndroidRoot(); @@ -218,7 +218,7 @@ TEST(DexpreoptTest, ForZygote) { GetZygoteMappedOatFiles(zygote_name); ASSERT_RESULT_OK(mapped_oat_files); - EXPECT_THAT(mapped_oat_files.value(), IsSupersetOf(expected_artifacts.value())); + EXPECT_THAT(expected_artifacts.value(), IsSubsetOf(mapped_oat_files.value())); } } @@ -236,7 +236,7 @@ TEST(DexpreoptTest, ForSystemServer) { GetSystemServerArtifactsMappedOdexes(); ASSERT_RESULT_OK(mapped_odexes); - EXPECT_THAT(mapped_odexes.value(), IsSupersetOf(expected_artifacts.value())); + EXPECT_THAT(expected_artifacts.value(), IsSubsetOf(mapped_odexes.value())); } } // namespace art |