diff options
author | Roland Levillain <rpl@google.com> | 2019-03-29 20:20:16 +0000 |
---|---|---|
committer | Roland Levillain <rpl@google.com> | 2019-04-12 13:47:09 +0100 |
commit | fb6a5c00ef02cda7ea919d717daaf46abd0414e4 (patch) | |
tree | 9ecfaac9bee174b3b31e0294c46c4d32a5f7b714 | |
parent | f160394fda141184f0ec3d139ec5ca810f142bda (diff) |
Add and use art::GetAndroidRuntimeBinDir.
This method returns the location of the directory containing the
Android Runtime binaries, which is expected to be the Android Runtime
APEX's bin directory on target and the Android Root's bin directory on
host (at least for now).
Also remove art::CommonArtTestImpl::GetTestAndroidRoot as it is no
longer used.
Test: ART gtests on host and target
Bug: 121117762
Change-Id: I4593bbd4d675ca9d3f7b708482aac82c1892a9ad
-rw-r--r-- | dexdump/dexdump_test.cc | 2 | ||||
-rw-r--r-- | dexlayout/dexdiag_test.cc | 14 | ||||
-rw-r--r-- | dexlayout/dexlayout_test.cc | 4 | ||||
-rw-r--r-- | dexlist/dexlist_test.cc | 3 | ||||
-rw-r--r-- | dexoptanalyzer/dexoptanalyzer_test.cc | 5 | ||||
-rw-r--r-- | imgdiag/imgdiag_test.cc | 17 | ||||
-rw-r--r-- | libartbase/base/common_art_test.cc | 9 | ||||
-rw-r--r-- | libartbase/base/common_art_test.h | 3 | ||||
-rw-r--r-- | libartbase/base/file_utils.cc | 11 | ||||
-rw-r--r-- | libartbase/base/file_utils.h | 3 | ||||
-rw-r--r-- | oatdump/oatdump_test.h | 10 | ||||
-rw-r--r-- | profman/profile_assistant_test.cc | 6 | ||||
-rw-r--r-- | runtime/runtime.cc | 6 | ||||
-rw-r--r-- | tools/dexanalyze/dexanalyze_test.cc | 2 | ||||
-rw-r--r-- | tools/hiddenapi/hiddenapi_test.cc | 5 |
15 files changed, 45 insertions, 55 deletions
diff --git a/dexdump/dexdump_test.cc b/dexdump/dexdump_test.cc index a0f5335409..4ddb208a92 100644 --- a/dexdump/dexdump_test.cc +++ b/dexdump/dexdump_test.cc @@ -39,7 +39,7 @@ class DexDumpTest : public CommonRuntimeTest { // Runs test with given arguments. bool Exec(const std::vector<std::string>& args, std::string* error_msg) { - std::string file_path = GetTestAndroidRoot() + "/bin/dexdump"; + std::string file_path = GetAndroidRuntimeBinDir() + "/dexdump"; EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path"; std::vector<std::string> exec_argv = { file_path }; exec_argv.insert(exec_argv.end(), args.begin(), args.end()); diff --git a/dexlayout/dexdiag_test.cc b/dexlayout/dexdiag_test.cc index e220f39f1b..0791e9a563 100644 --- a/dexlayout/dexdiag_test.cc +++ b/dexlayout/dexdiag_test.cc @@ -39,18 +39,14 @@ class DexDiagTest : public CommonArtTest { // Path to the dexdiag(d?)[32|64] binary. std::string GetDexDiagFilePath() { - std::string root = GetTestAndroidRoot(); - - root += "/bin/"; - root += kDexDiagBinaryName; - - std::string root32 = root + "32"; + std::string path = GetAndroidRuntimeBinDir() + '/' + kDexDiagBinaryName; + std::string path32 = path + "32"; // If we have both a 32-bit and a 64-bit build, the 32-bit file will have a 32 suffix. - if (OS::FileExists(root32.c_str()) && !Is64BitInstructionSet(kRuntimeISA)) { - return root32; + if (OS::FileExists(path32.c_str()) && !Is64BitInstructionSet(kRuntimeISA)) { + return path32; } else { // This is a 64-bit build or only a single build exists. - return root; + return path; } } diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc index fb1c8461e8..5ee63b5feb 100644 --- a/dexlayout/dexlayout_test.cc +++ b/dexlayout/dexlayout_test.cc @@ -253,14 +253,14 @@ static void WriteFileBase64(const char* base64, const char* location) { class DexLayoutTest : public CommonArtTest { protected: std::string GetDexLayoutPath() { - return GetTestAndroidRoot() + "/bin/dexlayoutd"; + return GetAndroidRuntimeBinDir() + "/dexlayoutd"; } // Runs FullPlainOutput test. bool FullPlainOutputExec(std::string* error_msg) { ScratchFile dexdump_output; const std::string& dexdump_filename = dexdump_output.GetFilename(); - std::string dexdump = GetTestAndroidRoot() + "/bin/dexdump"; + std::string dexdump = GetAndroidRuntimeBinDir() + "/dexdump"; EXPECT_TRUE(OS::FileExists(dexdump.c_str())) << dexdump << " should be a valid file path"; ScratchFile dexlayout_output; diff --git a/dexlist/dexlist_test.cc b/dexlist/dexlist_test.cc index 39e5f8cd99..32bc735487 100644 --- a/dexlist/dexlist_test.cc +++ b/dexlist/dexlist_test.cc @@ -41,8 +41,7 @@ class DexListTest : public CommonRuntimeTest { // Runs test with given arguments. bool Exec(const std::vector<std::string>& args, std::string* error_msg) { - std::string file_path = GetTestAndroidRoot(); - file_path += "/bin/dexlist"; + std::string file_path = GetAndroidRuntimeBinDir() + "/dexlist"; EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path"; std::vector<std::string> exec_argv = { file_path }; exec_argv.insert(exec_argv.end(), args.begin(), args.end()); diff --git a/dexoptanalyzer/dexoptanalyzer_test.cc b/dexoptanalyzer/dexoptanalyzer_test.cc index 7b6b36c133..9f8dbd7b0e 100644 --- a/dexoptanalyzer/dexoptanalyzer_test.cc +++ b/dexoptanalyzer/dexoptanalyzer_test.cc @@ -25,10 +25,9 @@ namespace art { class DexoptAnalyzerTest : public DexoptTest { protected: std::string GetDexoptAnalyzerCmd() { - std::string file_path = GetTestAndroidRoot(); - file_path += "/bin/dexoptanalyzer"; + std::string file_path = GetAndroidRuntimeBinDir() + "/dexoptanalyzer"; if (kIsDebugBuild) { - file_path += "d"; + file_path += 'd'; } EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path"; return file_path; diff --git a/imgdiag/imgdiag_test.cc b/imgdiag/imgdiag_test.cc index 739d9b8329..426f9efd34 100644 --- a/imgdiag/imgdiag_test.cc +++ b/imgdiag/imgdiag_test.cc @@ -61,22 +61,17 @@ class ImgDiagTest : public CommonRuntimeTest { // Path to the imgdiag(d?)[32|64] binary. std::string GetImgDiagFilePath() { - std::string root = GetTestAndroidRoot(); - - root += "/bin/"; - root += kImgDiagBinaryName; - + std::string path = GetAndroidRuntimeBinDir() + '/' + kImgDiagBinaryName; if (kIsDebugBuild) { - root += "d"; + path += 'd'; } - - std::string root32 = root + "32"; + std::string path32 = path + "32"; // If we have both a 32-bit and a 64-bit build, the 32-bit file will have a 32 suffix. - if (OS::FileExists(root32.c_str()) && !Is64BitInstructionSet(kRuntimeISA)) { - return root32; + if (OS::FileExists(path32.c_str()) && !Is64BitInstructionSet(kRuntimeISA)) { + return path32; // Only a single build exists, so the filename never has an extra suffix. } else { - return root; + return path; } } diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc index 242db428d5..afdb733035 100644 --- a/libartbase/base/common_art_test.cc +++ b/libartbase/base/common_art_test.cc @@ -400,15 +400,6 @@ std::string CommonArtTestImpl::GetClassPathOption(const char* option, return option + android::base::Join(class_path, ':'); } -std::string CommonArtTestImpl::GetTestAndroidRoot() { - if (IsHost()) { - const char* host_dir = getenv("ANDROID_HOST_OUT"); - CHECK(host_dir != nullptr); - return host_dir; - } - return GetAndroidRoot(); -} - // Check that for target builds we have ART_TARGET_NATIVETEST_DIR set. #ifdef ART_TARGET #ifndef ART_TARGET_NATIVETEST_DIR diff --git a/libartbase/base/common_art_test.h b/libartbase/base/common_art_test.h index a1f7cbb107..09264a7cb6 100644 --- a/libartbase/base/common_art_test.h +++ b/libartbase/base/common_art_test.h @@ -26,6 +26,7 @@ #include <android-base/logging.h> +#include "base/file_utils.h" #include "base/globals.h" #include "base/mutex.h" #include "base/os.h" @@ -184,8 +185,6 @@ class CommonArtTestImpl { void ClearDirectory(const char* dirpath, bool recursive = true); - std::string GetTestAndroidRoot(); - // Open a file (allows reading of framework jars). std::vector<std::unique_ptr<const DexFile>> OpenDexFiles(const char* filename); diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc index 1a1310342c..f2a2d406e6 100644 --- a/libartbase/base/file_utils.cc +++ b/libartbase/base/file_utils.cc @@ -271,6 +271,17 @@ std::string GetAndroidRuntimeRoot() { return ret; } +std::string GetAndroidRuntimeBinDir() { + // Environment variable `ANDROID_RUNTIME_ROOT` is defined as + // `$ANDROID_HOST_OUT/com.android.runtime` on host. However, host ART binaries + // are still installed in `$ANDROID_HOST_OUT/bin` (i.e. outside the Android + // Runtime Root). The situation is cleaner on target, where + // `ANDROID_RUNTIME_ROOT` is `$ANDROID_ROOT/apex/com.android.runtime` and ART + // binaries are installed in `$ANDROID_ROOT/apex/com.android.runtime/bin`. + std::string android_runtime_root = kIsTargetBuild ? GetAndroidRuntimeRoot() : GetAndroidRoot(); + return android_runtime_root + "/bin"; +} + std::string GetAndroidDataSafe(std::string* error_msg) { const char* android_dir = GetAndroidDirSafe(kAndroidDataEnvVar, kAndroidDataDefaultPath, diff --git a/libartbase/base/file_utils.h b/libartbase/base/file_utils.h index 2115e954f8..7e97ab0b9e 100644 --- a/libartbase/base/file_utils.h +++ b/libartbase/base/file_utils.h @@ -54,6 +54,9 @@ std::string GetAndroidRuntimeRoot(); // Find $ANDROID_RUNTIME_ROOT, /apex/com.android.runtime, or return an empty string. std::string GetAndroidRuntimeRootSafe(/*out*/ std::string* error_msg); +// Return the path to the directory containing the Android Runtime binaries. +std::string GetAndroidRuntimeBinDir(); + // Find $ANDROID_DATA, /data, or abort. std::string GetAndroidData(); // Find $ANDROID_DATA, /data, or return an empty string. diff --git a/oatdump/oatdump_test.h b/oatdump/oatdump_test.h index c4f29677a9..fa416e7a68 100644 --- a/oatdump/oatdump_test.h +++ b/oatdump/oatdump_test.h @@ -72,16 +72,14 @@ class OatDumpTest : public CommonRuntimeTest { // Returns path to the oatdump/dex2oat/dexdump binary. std::string GetExecutableFilePath(const char* name, bool is_debug, bool is_static) { - std::string root = GetTestAndroidRoot(); - root += "/bin/"; - root += name; + std::string path = GetAndroidRuntimeBinDir() + '/' + name; if (is_debug) { - root += "d"; + path += 'd'; } if (is_static) { - root += "s"; + path += 's'; } - return root; + return path; } std::string GetExecutableFilePath(Flavor flavor, const char* name) { diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc index e9061515ad..7b57c46df3 100644 --- a/profman/profile_assistant_test.cc +++ b/profman/profile_assistant_test.cc @@ -198,13 +198,11 @@ class ProfileAssistantTest : public CommonRuntimeTest { } std::string GetProfmanCmd() { - std::string file_path = GetTestAndroidRoot(); - file_path += "/bin/profman"; + std::string file_path = GetAndroidRuntimeBinDir() + "/profman"; if (kIsDebugBuild) { file_path += "d"; } - EXPECT_TRUE(OS::FileExists(file_path.c_str())) - << file_path << " should be a valid file path"; + EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path"; return file_path; } diff --git a/runtime/runtime.cc b/runtime/runtime.cc index dd7c21938f..ee7e264558 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -765,8 +765,10 @@ std::string Runtime::GetCompilerExecutable() const { if (!compiler_executable_.empty()) { return compiler_executable_; } - std::string compiler_executable(GetAndroidRoot()); - compiler_executable += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat"); + std::string compiler_executable = GetAndroidRuntimeBinDir() + "/dex2oat"; + if (kIsDebugBuild) { + compiler_executable += 'd'; + } return compiler_executable; } diff --git a/tools/dexanalyze/dexanalyze_test.cc b/tools/dexanalyze/dexanalyze_test.cc index c6648c09db..3bfbc79b84 100644 --- a/tools/dexanalyze/dexanalyze_test.cc +++ b/tools/dexanalyze/dexanalyze_test.cc @@ -22,7 +22,7 @@ namespace art { class DexAnalyzeTest : public CommonRuntimeTest { public: std::string GetDexAnalyzePath() { - return GetTestAndroidRoot() + "/bin/dexanalyze"; + return GetAndroidRuntimeBinDir() + "/dexanalyze"; } void DexAnalyzeExec(const std::vector<std::string>& args, bool expect_success) { diff --git a/tools/hiddenapi/hiddenapi_test.cc b/tools/hiddenapi/hiddenapi_test.cc index 9f65a5450c..7c9a95cbfd 100644 --- a/tools/hiddenapi/hiddenapi_test.cc +++ b/tools/hiddenapi/hiddenapi_test.cc @@ -31,10 +31,9 @@ namespace art { class HiddenApiTest : public CommonRuntimeTest { protected: std::string GetHiddenApiCmd() { - std::string file_path = GetTestAndroidRoot(); - file_path += "/bin/hiddenapi"; + std::string file_path = GetAndroidRuntimeBinDir() + "/hiddenapi"; if (kIsDebugBuild) { - file_path += "d"; + file_path += 'd'; } if (!OS::FileExists(file_path.c_str())) { LOG(FATAL) << "Could not find binary " << file_path; |