diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/aapt2/cmd/Compile.cpp | 5 | ||||
| -rw-r--r-- | tools/aapt2/io/FileSystem.cpp | 8 | ||||
| -rw-r--r-- | tools/apilint/apilint.py | 5 | ||||
| -rw-r--r-- | tools/apilint/apilint_test.py | 16 |
4 files changed, 30 insertions, 4 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; } diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py index 59e89f515e82..4c02d94542d0 100644 --- a/tools/apilint/apilint.py +++ b/tools/apilint/apilint.py @@ -208,13 +208,14 @@ class Class(): class Package(): + NAME = re.compile("package(?: .*)? ([A-Za-z.]+)") + def __init__(self, line, raw, blame): self.line = line self.raw = raw.strip(" {;") self.blame = blame - raw = raw.split() - self.name = raw[raw.index("package")+1] + self.name = Package.NAME.match(raw).group(1) self.name_path = self.name.split(".") def __repr__(self): diff --git a/tools/apilint/apilint_test.py b/tools/apilint/apilint_test.py index 3716bf9f5d6f..c10ef15d02ad 100644 --- a/tools/apilint/apilint_test.py +++ b/tools/apilint/apilint_test.py @@ -369,5 +369,21 @@ class V2ParserTests(unittest.TestCase): m = self._method('method @NonNull public @NonNull String @NonNull [] split(@NonNull String, int);') self.assertEquals('java.lang.String[]', m.typ) +class PackageTests(unittest.TestCase): + def _package(self, raw): + return apilint.Package(123, raw, "blame") + + def test_regular_package(self): + p = self._package("package an.pref.int {") + self.assertEquals('an.pref.int', p.name) + + def test_annotation_package(self): + p = self._package("package @RestrictTo(a.b.C) an.pref.int {") + self.assertEquals('an.pref.int', p.name) + + def test_multi_annotation_package(self): + p = self._package("package @Rt(a.b.L_G_P) @RestrictTo(a.b.C) an.pref.int {") + self.assertEquals('an.pref.int', p.name) + if __name__ == "__main__": unittest.main() |