diff options
author | 2018-02-13 15:26:21 -0800 | |
---|---|---|
committer | 2018-02-20 16:35:18 +0000 | |
commit | 88c6d26dd8686bdb366d54937a505f10f3bf1cd8 (patch) | |
tree | 2f07c4ef2144c4a909760260389d070fe22af05e | |
parent | 38321bb87c3630afaef76f312e90df5bca6a0554 (diff) |
patchoat: take directories instead of filenames
patchoat was already ignoring the basename part of the filename passed
to it for both --output-image-file and --output-image-relocation-file.
We can therefore just pass in the directories instead.
Bug: 72828459
Test: make test-art-host-gtest-patchoat_test
Change-Id: I1a699d1f6746f068078ae768d30690431578d84e
-rw-r--r-- | patchoat/patchoat.cc | 37 | ||||
-rw-r--r-- | patchoat/patchoat_test.cc | 20 | ||||
-rw-r--r-- | runtime/dex2oat_environment_test.h | 20 | ||||
-rw-r--r-- | runtime/dexopt_test.cc | 17 | ||||
-rw-r--r-- | runtime/gc/space/image_space.cc | 20 |
5 files changed, 48 insertions, 66 deletions
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc index 4900f178b9..9267b184a5 100644 --- a/patchoat/patchoat.cc +++ b/patchoat/patchoat.cc @@ -1093,10 +1093,10 @@ NO_RETURN static void Usage(const char *fmt, ...) { UsageError(" --input-image-location=<file.art>: Specifies the 'location' of the image file to"); UsageError(" be patched."); UsageError(""); - UsageError(" --output-image-file=<file.art>: Specifies the exact file to write the patched"); - UsageError(" image file to."); + UsageError(" --output-image-directory=<dir>: Specifies the directory to write the patched"); + UsageError(" image file(s) to."); UsageError(""); - UsageError(" --output-image-relocation-file=<file.art.rel>: Specifies the exact file to write"); + UsageError(" --output-image-relocation-directory=<dir>: Specifies the directory to write"); UsageError(" the image relocation information to."); UsageError(""); UsageError(" --base-offset-delta=<delta>: Specify the amount to change the old base-offset by."); @@ -1116,13 +1116,13 @@ static int patchoat_patch_image(TimingLogger& timings, InstructionSet isa, const std::string& input_image_location, const std::string& output_image_directory, - const std::string& output_image_relocation_filename, + const std::string& output_image_relocation_directory, off_t base_delta, bool base_delta_set, bool debug) { CHECK(!input_image_location.empty()); - if ((output_image_directory.empty()) && (output_image_relocation_filename.empty())) { - Usage("Image patching requires --output-image-file or --output-image-relocation-file"); + if ((output_image_directory.empty()) && (output_image_relocation_directory.empty())) { + Usage("Image patching requires --output-image-directory or --output-image-relocation-directory"); } if (!base_delta_set) { @@ -1141,9 +1141,6 @@ static int patchoat_patch_image(TimingLogger& timings, TimingLogger::ScopedTiming pt("patch image and oat", &timings); - std::string output_image_relocation_directory = - output_image_relocation_filename.substr( - 0, output_image_relocation_filename.find_last_of('/')); bool ret = PatchOat::Patch( input_image_location, @@ -1201,8 +1198,8 @@ static int patchoat(int argc, char **argv) { bool isa_set = false; InstructionSet isa = InstructionSet::kNone; std::string input_image_location; - std::string output_image_filename; - std::string output_image_relocation_filename; + std::string output_image_directory; + std::string output_image_relocation_directory; off_t base_delta = 0; bool base_delta_set = false; bool dump_timings = kIsDebugBuild; @@ -1223,11 +1220,11 @@ static int patchoat(int argc, char **argv) { } } else if (option.starts_with("--input-image-location=")) { input_image_location = option.substr(strlen("--input-image-location=")).data(); - } else if (option.starts_with("--output-image-file=")) { - output_image_filename = option.substr(strlen("--output-image-file=")).data(); - } else if (option.starts_with("--output-image-relocation-file=")) { - output_image_relocation_filename = - option.substr(strlen("--output-image-relocation-file=")).data(); + } else if (option.starts_with("--output-image-directory=")) { + output_image_directory = option.substr(strlen("--output-image-directory=")).data(); + } else if (option.starts_with("--output-image-relocation-directory=")) { + output_image_relocation_directory = + option.substr(strlen("--output-image-relocation-directory=")).data(); } else if (option.starts_with("--base-offset-delta=")) { const char* base_delta_str = option.substr(strlen("--base-offset-delta=")).data(); base_delta_set = true; @@ -1245,12 +1242,6 @@ static int patchoat(int argc, char **argv) { } } - // TODO: Have calls to patchoat pass in the output_image directory instead of - // the output_image_filename. - std::string output_image_directory; - if (!output_image_filename.empty()) - output_image_directory = android::base::Dirname(output_image_filename); - // The instruction set is mandatory. This simplifies things... if (!isa_set) { Usage("Instruction set must be set."); @@ -1267,7 +1258,7 @@ static int patchoat(int argc, char **argv) { isa, input_image_location, output_image_directory, - output_image_relocation_filename, + output_image_relocation_directory, base_delta, base_delta_set, debug); diff --git a/patchoat/patchoat_test.cc b/patchoat/patchoat_test.cc index 69c6bfae30..ac3abd0642 100644 --- a/patchoat/patchoat_test.cc +++ b/patchoat/patchoat_test.cc @@ -137,32 +137,32 @@ class PatchoatTest : public DexoptTest { } bool RelocateBootImage(const std::string& input_image_location, - const std::string& output_image_filename, + const std::string& output_image_directory, off_t base_offset_delta, std::string* error_msg) { std::vector<std::string> argv = BasePatchoatCommand(input_image_location, base_offset_delta); - argv.push_back("--output-image-file=" + output_image_filename); + argv.push_back("--output-image-directory=" + output_image_directory); return RunDex2OatOrPatchoat(argv, error_msg); } bool VerifyBootImage(const std::string& input_image_location, - const std::string& output_image_filename, + const std::string& output_image_directory, off_t base_offset_delta, std::string* error_msg) { std::vector<std::string> argv = BasePatchoatCommand(input_image_location, base_offset_delta); - argv.push_back("--output-image-file=" + output_image_filename); + argv.push_back("--output-image-directory=" + output_image_directory); argv.push_back("--verify"); return RunDex2OatOrPatchoat(argv, error_msg); } bool GenerateBootImageRelFile(const std::string& input_image_location, - const std::string& output_rel_filename, + const std::string& output_rel_directory, off_t base_offset_delta, std::string* error_msg) { std::vector<std::string> argv = BasePatchoatCommand(input_image_location, base_offset_delta); - argv.push_back("--output-image-relocation-file=" + output_rel_filename); + argv.push_back("--output-image-relocation-directory=" + output_rel_directory); return RunDex2OatOrPatchoat(argv, error_msg); } @@ -375,7 +375,7 @@ TEST_F(PatchoatTest, PatchoatRelocationSameAsDex2oatRelocation) { ASSERT_EQ(0, symlink(dex2oat_orig_dir.c_str(), dex2oat_orig_with_arch_dir.c_str())); if (!RelocateBootImage( dex2oat_orig_dir + "/boot.art", - patchoat_dir + "/boot.art", + patchoat_dir, base_addr_delta, &error_msg)) { FAIL() << "RelocateBootImage failed: " << error_msg; @@ -467,7 +467,7 @@ TEST_F(PatchoatTest, RelFileVerification) { off_t base_addr_delta = 0x100000; if (!GenerateBootImageRelFile( dex2oat_orig_dir + "/boot.art", - dex2oat_orig_dir + "/boot.art.rel", + dex2oat_orig_dir, base_addr_delta, &error_msg)) { FAIL() << "RelocateBootImage failed: " << error_msg; @@ -483,7 +483,7 @@ TEST_F(PatchoatTest, RelFileVerification) { base_addr_delta -= 0x10000; if (!RelocateBootImage( dex2oat_orig_dir + "/boot.art", - relocated_dir + "/boot.art", + relocated_dir, base_addr_delta, &error_msg)) { FAIL() << "RelocateBootImage failed: " << error_msg; @@ -524,7 +524,7 @@ TEST_F(PatchoatTest, RelFileVerification) { // Assert that verification works with the .rel files. if (!VerifyBootImage( dex2oat_orig_dir + "/boot.art", - relocated_dir + "/boot.art", + relocated_dir, base_addr_delta, &error_msg)) { FAIL() << "VerifyBootImage failed: " << error_msg; diff --git a/runtime/dex2oat_environment_test.h b/runtime/dex2oat_environment_test.h index 20cde530c2..75642fc889 100644 --- a/runtime/dex2oat_environment_test.h +++ b/runtime/dex2oat_environment_test.h @@ -160,26 +160,6 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { + "/core.art"; } - bool GetCachedImageFile(const std::string& image_location, - /*out*/std::string* image, - /*out*/std::string* error_msg) const { - std::string cache; - bool have_android_data; - bool dalvik_cache_exists; - bool is_global_cache; - GetDalvikCache(GetInstructionSetString(kRuntimeISA), - true, - &cache, - &have_android_data, - &dalvik_cache_exists, - &is_global_cache); - if (!dalvik_cache_exists) { - *error_msg = "Failed to create dalvik cache"; - return false; - } - return GetDalvikCacheFilename(image_location.c_str(), cache.c_str(), image, error_msg); - } - // Returns the path to an image location whose contents differ from the // image at GetImageLocation(). This is used for testing mismatched // image checksums in the oat_file_assistant_tests. diff --git a/runtime/dexopt_test.cc b/runtime/dexopt_test.cc index 8ce7921287..c19fa82877 100644 --- a/runtime/dexopt_test.cc +++ b/runtime/dexopt_test.cc @@ -20,6 +20,7 @@ #include <backtrace/BacktraceMap.h> #include <gtest/gtest.h> +#include "base/file_utils.h" #include "common_runtime_test.h" #include "compiler_callbacks.h" #include "dex2oat_environment_test.h" @@ -197,8 +198,18 @@ void DexoptTest::GenerateOatForTest(const char* dex_location, CompilerFilter::Fi } bool DexoptTest::PreRelocateImage(const std::string& image_location, std::string* error_msg) { - std::string image; - if (!GetCachedImageFile(image_location, &image, error_msg)) { + std::string dalvik_cache; + bool have_android_data; + bool dalvik_cache_exists; + bool is_global_cache; + GetDalvikCache(GetInstructionSetString(kRuntimeISA), + true, + &dalvik_cache, + &have_android_data, + &dalvik_cache_exists, + &is_global_cache); + if (!dalvik_cache_exists) { + *error_msg = "Failed to create dalvik cache"; return false; } @@ -208,7 +219,7 @@ bool DexoptTest::PreRelocateImage(const std::string& image_location, std::string std::vector<std::string> argv; argv.push_back(patchoat); argv.push_back("--input-image-location=" + image_location); - argv.push_back("--output-image-file=" + image); + argv.push_back("--output-image-directory=" + dalvik_cache); argv.push_back("--instruction-set=" + std::string(GetInstructionSetString(kRuntimeISA))); argv.push_back("--base-offset-delta=0x00008000"); return Exec(argv, error_msg); diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index 2b06e838ce..9ae1f45511 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -240,7 +240,7 @@ static bool ReadSpecificImageHeader(const char* filename, ImageHeader* image_hea // Relocate the image at image_location to dest_filename and relocate it by a random amount. static bool RelocateImage(const char* image_location, - const char* dest_filename, + const char* dest_directory, InstructionSet isa, std::string* error_msg) { // We should clean up so we are more likely to have room for the image. @@ -254,8 +254,8 @@ static bool RelocateImage(const char* image_location, std::string input_image_location_arg("--input-image-location="); input_image_location_arg += image_location; - std::string output_image_filename_arg("--output-image-file="); - output_image_filename_arg += dest_filename; + std::string output_image_directory_arg("--output-image-directory="); + output_image_directory_arg += dest_directory; std::string instruction_set_arg("--instruction-set="); instruction_set_arg += GetInstructionSetString(isa); @@ -267,7 +267,7 @@ static bool RelocateImage(const char* image_location, argv.push_back(patchoat); argv.push_back(input_image_location_arg); - argv.push_back(output_image_filename_arg); + argv.push_back(output_image_directory_arg); argv.push_back(instruction_set_arg); argv.push_back(base_offset_arg); @@ -278,7 +278,7 @@ static bool RelocateImage(const char* image_location, } static bool VerifyImage(const char* image_location, - const char* dest_filename, + const char* dest_directory, InstructionSet isa, std::string* error_msg) { std::string patchoat(Runtime::Current()->GetPatchoatExecutable()); @@ -286,8 +286,8 @@ static bool VerifyImage(const char* image_location, std::string input_image_location_arg("--input-image-location="); input_image_location_arg += image_location; - std::string output_image_filename_arg("--output-image-file="); - output_image_filename_arg += dest_filename; + std::string output_image_directory_arg("--output-image-directory="); + output_image_directory_arg += dest_directory; std::string instruction_set_arg("--instruction-set="); instruction_set_arg += GetInstructionSetString(isa); @@ -296,7 +296,7 @@ static bool VerifyImage(const char* image_location, argv.push_back(patchoat); argv.push_back(input_image_location_arg); - argv.push_back(output_image_filename_arg); + argv.push_back(output_image_directory_arg); argv.push_back(instruction_set_arg); @@ -1536,7 +1536,7 @@ std::unique_ptr<ImageSpace> ImageSpace::CreateBootImage(const char* image_locati std::string local_error_msg; // All secondary images are verified when the primary image is verified. bool verified = secondary_image || VerifyImage(image_location, - cache_filename.c_str(), + dalvik_cache.c_str(), image_isa, &local_error_msg); if (!(verified && CheckSpace(dalvik_cache, &local_error_msg))) { @@ -1628,7 +1628,7 @@ std::unique_ptr<ImageSpace> ImageSpace::CreateBootImage(const char* image_locati _exit(1); } else if (ImageCreationAllowed(is_global_cache, image_isa, &local_error_msg)) { bool patch_success = - RelocateImage(image_location, cache_filename.c_str(), image_isa, &local_error_msg); + RelocateImage(image_location, dalvik_cache.c_str(), image_isa, &local_error_msg); if (patch_success) { std::unique_ptr<ImageSpace> patched_space = ImageSpaceLoader::Load(image_location, |