Set materialized file names correctly.
Change-Id: I0848ad4da4f2033dd7804686e65bd44c690a2036
diff --git a/src/compiler_llvm/compilation_unit.cc b/src/compiler_llvm/compilation_unit.cc
index a1d66f1..b1ca333 100644
--- a/src/compiler_llvm/compilation_unit.cc
+++ b/src/compiler_llvm/compilation_unit.cc
@@ -205,13 +205,22 @@
};
bool CompilationUnit::Materialize() {
- std::string tmp_file = GetArtCacheOrDie();
- tmp_file += "/art-llvm-XXXXXX";
+ const char* android_data = getenv("ANDROID_DATA");
+ if (android_data == NULL) {
+ if (OS::DirectoryExists("/data")) {
+ android_data = "/data";
+ } else {
+ android_data = "/tmp";
+ }
+ }
+
+ std::string art_cache = GetArtCacheOrDie(android_data);
+ art_cache += "/art-llvm-XXXXXX";
// Prepare the input
- ScopedTempFile input(tmp_file);
+ ScopedTempFile input(art_cache);
if (input.GetFd() < 0) {
- PLOG(ERROR) << "Failed to save the module to the file " << tmp_file;
+ PLOG(ERROR) << "Failed to save the module to the file " << art_cache;
return false;
}
@@ -221,9 +230,9 @@
}
// Prepare the output
- ScopedTempFile output(tmp_file);
+ ScopedTempFile output(art_cache);
if (output.GetFd() < 0) {
- PLOG(ERROR) << "Failed to prepare the output file " << tmp_file;
+ PLOG(ERROR) << "Failed to prepare the output file " << art_cache;
return false;
}
diff --git a/src/utils.cc b/src/utils.cc
index dc1ebff..67fda67 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -906,8 +906,8 @@
return android_data;
}
-std::string GetArtCacheOrDie() {
- std::string art_cache(StringPrintf("%s/art-cache", GetAndroidData()));
+std::string GetArtCacheOrDie(const char* android_data) {
+ std::string art_cache(StringPrintf("%s/art-cache", android_data));
if (!OS::DirectoryExists(art_cache.c_str())) {
if (StartsWith(art_cache, "/tmp/")) {
@@ -925,7 +925,7 @@
}
std::string GetArtCacheFilenameOrDie(const std::string& location) {
- std::string art_cache(GetArtCacheOrDie());
+ std::string art_cache(GetArtCacheOrDie(GetAndroidData()));
CHECK_EQ(location[0], '/') << location;
std::string cache_file(location, 1); // skip leading slash
std::replace(cache_file.begin(), cache_file.end(), '/', '@');
diff --git a/src/utils.h b/src/utils.h
index f94c05e..994e9bc 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -283,7 +283,7 @@
const char* GetAndroidData();
// Returns the art-cache location, or dies trying.
-std::string GetArtCacheOrDie();
+std::string GetArtCacheOrDie(const char* android_data);
// Returns the art-cache location for a DexFile or OatFile, or dies trying.
std::string GetArtCacheFilenameOrDie(const std::string& location);