Skip to content

Commit

Permalink
Abort the compilation if we fail to read preloaded-classes files.
Browse files Browse the repository at this point in the history
Bug: 162110941
Test: m
Change-Id: I4e77f9e8e7992f8a02972b3f0cf3b48b23e52aab
  • Loading branch information
Nicolas Geoffray committed Mar 24, 2022
1 parent fc1ba6d commit 2bd92d3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions dex2oat/dex2oat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2541,11 +2541,15 @@ class Dex2Oat final {
preloaded_classes_ = std::make_unique<HashSet<std::string>>();
if (!preloaded_classes_fds_.empty()) {
for (int fd : preloaded_classes_fds_) {
ReadCommentedInputFromFd(fd, nullptr, preloaded_classes_.get());
if (!ReadCommentedInputFromFd(fd, nullptr, preloaded_classes_.get())) {
return false;
}
}
} else {
for (const std::string& file : preloaded_classes_files_) {
ReadCommentedInputFromFile(file.c_str(), nullptr, preloaded_classes_.get());
if (!ReadCommentedInputFromFile(file.c_str(), nullptr, preloaded_classes_.get())) {
return false;
}
}
}
return true;
Expand Down Expand Up @@ -2780,25 +2784,27 @@ class Dex2Oat final {
}

template <typename T>
static void ReadCommentedInputFromFile(
static bool ReadCommentedInputFromFile(
const char* input_filename, std::function<std::string(const char*)>* process, T* output) {
auto input_file = std::unique_ptr<FILE, decltype(&fclose)>{fopen(input_filename, "r"), fclose};
if (!input_file) {
LOG(ERROR) << "Failed to open input file " << input_filename;
return;
return false;
}
ReadCommentedInputStream<T>(input_file.get(), process, output);
return true;
}

template <typename T>
static void ReadCommentedInputFromFd(
static bool ReadCommentedInputFromFd(
int input_fd, std::function<std::string(const char*)>* process, T* output) {
auto input_file = std::unique_ptr<FILE, decltype(&fclose)>{fdopen(input_fd, "r"), fclose};
if (!input_file) {
LOG(ERROR) << "Failed to re-open input fd from /prof/self/fd/" << input_fd;
return;
return false;
}
ReadCommentedInputStream<T>(input_file.get(), process, output);
return true;
}

// Read lines from the given file, dropping comments and empty lines. Post-process each line with
Expand Down

0 comments on commit 2bd92d3

Please sign in to comment.