From f22ed8dc0ec107cb0e80eb25c7de4094c7f5301e Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 20 Feb 2019 08:05:31 -0800 Subject: 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 --- tools/aapt2/cmd/Compile.cpp | 5 ++++- 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& args) { auto collection = util::make_unique(); // Collect data from the path for each input file. - for (const std::string& arg : args) { + std::vector 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::Create(const android::StringPiec return nullptr; } + std::vector 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::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; } -- cgit v1.2.3-59-g8ed1b