Support running art gtests out-of-tree
Art host gtests would CHECK that the binary path was below
ANDROID_BUILD_TOP. This could cause problems for some build
configurations such as custom OUT_DIRs and using the vscode debugger.
Since having ANDROID_BUILD_TOP be correct is the only actually
important thing we can just ignore this discrepency. Change the test
setup to prefer ANDROID_BUILD_TOP if set and it differs from the
binary location.
Test: gtests
Change-Id: I566fd4c1b801efe87bf368caa41f2330f659b4b2
diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc
index c372e10..70b94b8 100644
--- a/libartbase/base/common_art_test.cc
+++ b/libartbase/base/common_art_test.cc
@@ -172,8 +172,12 @@
android_build_top = std::filesystem::path(android_build_top).string();
CHECK(!android_build_top.empty());
if (android_build_top_from_env != nullptr) {
- CHECK_EQ(std::filesystem::weakly_canonical(android_build_top).string(),
- std::filesystem::weakly_canonical(android_build_top_from_env).string());
+ if (std::filesystem::weakly_canonical(android_build_top).string() !=
+ std::filesystem::weakly_canonical(android_build_top_from_env).string()) {
+ LOG(WARNING) << "Execution path (" << argv << ") not below ANDROID_BUILD_TOP ("
+ << android_build_top_from_env << ")! Using env-var.";
+ android_build_top = android_build_top_from_env;
+ }
} else {
setenv("ANDROID_BUILD_TOP", android_build_top.c_str(), /*overwrite=*/0);
}