diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp index cc1cd5cf941ea..b64cd8c432d41 100644 --- a/tools/aapt2/cmd/Compile.cpp +++ b/tools/aapt2/cmd/Compile.cpp @@ -480,7 +480,8 @@ static bool CompilePng(IAaptContext* context, const CompileOptions& options, { std::string content; - if (!android::base::ReadFileToString(path_data.source.path, &content)) { + if (!android::base::ReadFileToString(path_data.source.path, &content, + true /*follow_symlinks*/)) { context->GetDiagnostics()->Error(DiagMessage(path_data.source) << "failed to open file: " << android::base::SystemErrorCodeToString(errno)); diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp index 24a687cd4d864..dd4b2ba9ff16b 100644 --- a/tools/aapt2/cmd/Link.cpp +++ b/tools/aapt2/cmd/Link.cpp @@ -632,7 +632,7 @@ static bool WriteStableIdMapToPath(IDiagnostics* diag, static bool LoadStableIdMap(IDiagnostics* diag, const std::string& path, std::unordered_map* out_id_map) { std::string content; - if (!android::base::ReadFileToString(path, &content)) { + if (!android::base::ReadFileToString(path, &content, true /*follow_symlinks*/)) { diag->Error(DiagMessage(path) << "failed reading stable ID file"); return false; } diff --git a/tools/aapt2/integration-tests/SymlinkTest/Android.mk b/tools/aapt2/integration-tests/SymlinkTest/Android.mk new file mode 100644 index 0000000000000..902fc65a667fa --- /dev/null +++ b/tools/aapt2/integration-tests/SymlinkTest/Android.mk @@ -0,0 +1,23 @@ +# +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_USE_AAPT2 := true +LOCAL_PACKAGE_NAME := AaptSymlinkTest +LOCAL_MODULE_TAGS := tests +include $(BUILD_PACKAGE) diff --git a/tools/aapt2/integration-tests/SymlinkTest/AndroidManifest.xml b/tools/aapt2/integration-tests/SymlinkTest/AndroidManifest.xml new file mode 100644 index 0000000000000..abbfa531ea568 --- /dev/null +++ b/tools/aapt2/integration-tests/SymlinkTest/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + + diff --git a/tools/aapt2/integration-tests/SymlinkTest/res/drawable/white_3x3.9.png b/tools/aapt2/integration-tests/SymlinkTest/res/drawable/white_3x3.9.png new file mode 120000 index 0000000000000..a7e8e2f79d90e --- /dev/null +++ b/tools/aapt2/integration-tests/SymlinkTest/res/drawable/white_3x3.9.png @@ -0,0 +1 @@ +../../targets/white_3x3.9.png \ No newline at end of file diff --git a/tools/aapt2/integration-tests/SymlinkTest/res/layout/layout.xml b/tools/aapt2/integration-tests/SymlinkTest/res/layout/layout.xml new file mode 120000 index 0000000000000..29c30e1d283c0 --- /dev/null +++ b/tools/aapt2/integration-tests/SymlinkTest/res/layout/layout.xml @@ -0,0 +1 @@ +../../targets/layout.xml \ No newline at end of file diff --git a/tools/aapt2/integration-tests/SymlinkTest/res/values/values.xml b/tools/aapt2/integration-tests/SymlinkTest/res/values/values.xml new file mode 120000 index 0000000000000..554bb7128a499 --- /dev/null +++ b/tools/aapt2/integration-tests/SymlinkTest/res/values/values.xml @@ -0,0 +1 @@ +../../targets/values.xml \ No newline at end of file diff --git a/tools/aapt2/integration-tests/SymlinkTest/targets/layout.xml b/tools/aapt2/integration-tests/SymlinkTest/targets/layout.xml new file mode 100644 index 0000000000000..e5835ed1a1691 --- /dev/null +++ b/tools/aapt2/integration-tests/SymlinkTest/targets/layout.xml @@ -0,0 +1,19 @@ + + + + diff --git a/tools/aapt2/integration-tests/SymlinkTest/targets/values.xml b/tools/aapt2/integration-tests/SymlinkTest/targets/values.xml new file mode 100644 index 0000000000000..5b028438c1a00 --- /dev/null +++ b/tools/aapt2/integration-tests/SymlinkTest/targets/values.xml @@ -0,0 +1,19 @@ + + + + + true + diff --git a/tools/aapt2/integration-tests/SymlinkTest/targets/white_3x3.9.png b/tools/aapt2/integration-tests/SymlinkTest/targets/white_3x3.9.png new file mode 100644 index 0000000000000..1a3731bbc8b88 Binary files /dev/null and b/tools/aapt2/integration-tests/SymlinkTest/targets/white_3x3.9.png differ diff --git a/tools/aapt2/readme.md b/tools/aapt2/readme.md index 7e28ae7b6f78d..ac09b5933ef6e 100644 --- a/tools/aapt2/readme.md +++ b/tools/aapt2/readme.md @@ -1,5 +1,9 @@ # Android Asset Packaging Tool 2.0 (AAPT2) release notes +## Version 2.17 +### `aapt2 compile ...` +- Fixed an issue where symlinks would not be followed when compiling PNGs. (bug 62144459) + ## Version 2.16 ### `aapt2 link ...` - Versioning of XML files is more intelligent, using a small set of rules to degrade diff --git a/tools/aapt2/util/Files.cpp b/tools/aapt2/util/Files.cpp index d10351b48eb36..1bf25947ea931 100644 --- a/tools/aapt2/util/Files.cpp +++ b/tools/aapt2/util/Files.cpp @@ -181,12 +181,13 @@ Maybe MmapPath(const StringPiece& path, return std::move(filemap); } -bool AppendArgsFromFile(const StringPiece& path, - std::vector* out_arglist, +bool AppendArgsFromFile(const StringPiece& path, std::vector* out_arglist, std::string* out_error) { std::string contents; - if (!android::base::ReadFileToString(path.to_string(), &contents)) { - if (out_error) *out_error = "failed to read argument-list file"; + if (!android::base::ReadFileToString(path.to_string(), &contents, true /*follow_symlinks*/)) { + if (out_error) { + *out_error = "failed to read argument-list file"; + } return false; }