Sort inputs to compile and link

This change sorts the input files of compile and link and also traverses
directories in sorted order in FileCollection::Create. This change
attempts to fix non-determinism issues with aapt2.

Bug: 122518436
Test: builds
Change-Id: I615b8d7f1117e3850366760f16672f0cf5b02070
This commit is contained in:
Ryan Mitchell
2019-02-20 08:05:31 -08:00
parent 32981ff4d4
commit f22ed8dc0e
2 changed files with 11 additions and 2 deletions

View File

@@ -769,7 +769,10 @@ int CompileCommand::Action(const std::vector<std::string>& args) {
auto collection = util::make_unique<io::FileCollection>();
// Collect data from the path for each input file.
for (const std::string& arg : args) {
std::vector<std::string> sorted_args = args;
std::sort(sorted_args.begin(), sorted_args.end());
for (const std::string& arg : sorted_args) {
collection->InsertFile(arg);
}

View File

@@ -79,6 +79,7 @@ std::unique_ptr<FileCollection> FileCollection::Create(const android::StringPiec
return nullptr;
}
std::vector<std::string> sorted_files;
while (struct dirent *entry = readdir(d.get())) {
std::string prefix_path = root.to_string();
file::AppendPath(&prefix_path, entry->d_name);
@@ -105,10 +106,15 @@ std::unique_ptr<FileCollection> FileCollection::Create(const android::StringPiec
continue;
}
collection->InsertFile(full_path);
sorted_files.push_back(full_path);
}
}
std::sort(sorted_files.begin(), sorted_files.end());
for (const std::string& full_path : sorted_files) {
collection->InsertFile(full_path);
}
return collection;
}