diff options
| author | 2019-02-20 08:05:31 -0800 | |
|---|---|---|
| committer | 2019-02-26 17:40:30 +0000 | |
| commit | f22ed8dc0ec107cb0e80eb25c7de4094c7f5301e (patch) | |
| tree | cfbd2d0f979450690cedae268be10116e160107c | |
| parent | 32981ff4d406cd44c5e57814088028fecb9bf72f (diff) | |
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
| -rw-r--r-- | tools/aapt2/cmd/Compile.cpp | 5 | ||||
| -rw-r--r-- | tools/aapt2/io/FileSystem.cpp | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp index 0512bdc5bf72..bec6c6973613 100644 --- a/tools/aapt2/cmd/Compile.cpp +++ b/tools/aapt2/cmd/Compile.cpp @@ -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); } diff --git a/tools/aapt2/io/FileSystem.cpp b/tools/aapt2/io/FileSystem.cpp index 51cc9032fb3e..e15f935cad27 100644 --- a/tools/aapt2/io/FileSystem.cpp +++ b/tools/aapt2/io/FileSystem.cpp @@ -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; } |