diff options
| author | 2017-11-13 23:52:28 +0000 | |
|---|---|---|
| committer | 2017-11-13 23:52:28 +0000 | |
| commit | 514971a39ca961c9fc748f9fb9a97e34a1067b3f (patch) | |
| tree | 833087829e7d7b2a8086c8fe5ac242dcb4827fb4 | |
| parent | 8d6eb1fdf857272c4f94a35d172ccf33ba58fd2c (diff) | |
| parent | d55bef78a5f2a0fe8068b26b463b161bd0398791 (diff) | |
Merge "AAPT2 - Convert command to copy all the files."
| -rw-r--r-- | tools/aapt2/LoadedApk.cpp | 3 | ||||
| -rw-r--r-- | tools/aapt2/cmd/Convert.cpp | 45 | ||||
| -rw-r--r-- | tools/aapt2/cmd/Optimize.cpp | 6 | ||||
| -rw-r--r-- | tools/aapt2/io/Util.cpp | 6 | ||||
| -rw-r--r-- | tools/aapt2/io/Util.h | 3 |
5 files changed, 45 insertions, 18 deletions
diff --git a/tools/aapt2/LoadedApk.cpp b/tools/aapt2/LoadedApk.cpp index 921d8531cbd3..5981401195a4 100644 --- a/tools/aapt2/LoadedApk.cpp +++ b/tools/aapt2/LoadedApk.cpp @@ -235,8 +235,7 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, ResourceTable* split_table return false; } } else { - uint32_t compression_flags = file->WasCompressed() ? ArchiveEntry::kCompress : 0u; - if (!io::CopyFileToArchive(context, file, path, compression_flags, writer)) { + if (!io::CopyFileToArchivePreserveCompression(context, file, path, writer)) { return false; } } diff --git a/tools/aapt2/cmd/Convert.cpp b/tools/aapt2/cmd/Convert.cpp index a34d51be221b..027ac8ff0000 100644 --- a/tools/aapt2/cmd/Convert.cpp +++ b/tools/aapt2/cmd/Convert.cpp @@ -46,17 +46,6 @@ class ISerializer { virtual bool SerializeTable(ResourceTable* table, IArchiveWriter* writer) = 0; virtual bool SerializeFile(const FileReference* file, IArchiveWriter* writer) = 0; - bool CopyFileToArchive(const FileReference* file, IArchiveWriter* writer) { - uint32_t compression_flags = file->file->WasCompressed() ? ArchiveEntry::kCompress : 0u; - if (!io::CopyFileToArchive(context_, file->file, *file->path, compression_flags, writer)) { - context_->GetDiagnostics()->Error(DiagMessage(source_) - << "failed to copy file " << *file->path); - return false; - } - - return true; - } - virtual ~ISerializer() = default; protected: @@ -66,18 +55,21 @@ class ISerializer { bool ConvertProtoApkToBinaryApk(IAaptContext* context, unique_ptr<LoadedApk> apk, ISerializer* serializer, IArchiveWriter* writer) { + // AndroidManifest.xml if (!serializer->SerializeXml(apk->GetManifest(), kAndroidManifestPath, true /*utf16*/, writer)) { context->GetDiagnostics()->Error(DiagMessage(apk->GetSource()) << "failed to serialize AndroidManifest.xml"); return false; } + // Resource table if (!serializer->SerializeTable(apk->GetResourceTable(), writer)) { context->GetDiagnostics()->Error(DiagMessage(apk->GetSource()) << "failed to serialize the resource table"); return false; } + // Resources for (const auto& package : apk->GetResourceTable()->packages) { for (const auto& type : package->types) { for (const auto& entry : type->entries) { @@ -100,6 +92,31 @@ bool ConvertProtoApkToBinaryApk(IAaptContext* context, unique_ptr<LoadedApk> apk } // entry } // type } // package + + // Other files + std::unique_ptr<io::IFileCollectionIterator> iterator = apk->GetFileCollection()->Iterator(); + while (iterator->HasNext()) { + io::IFile* file = iterator->Next(); + + std::string path = file->GetSource().path; + // The name of the path has the format "<zip-file-name>@<path-to-file>". + path = path.substr(path.find('@') + 1); + + // Manifest, resource table and resources have already been taken care of. + if (path == kAndroidManifestPath || + path == kApkResourceTablePath || + path == kProtoResourceTablePath || + path.find("res/") == 0) { + continue; + } + + if (!io::CopyFileToArchivePreserveCompression(context, file, path, writer)) { + context->GetDiagnostics()->Error(DiagMessage(apk->GetSource()) + << "failed to copy file " << path); + return false; + } + } + return true; } @@ -169,7 +186,11 @@ class BinarySerializer : public ISerializer { return false; } } else { - return CopyFileToArchive(file, writer); + if (!io::CopyFileToArchivePreserveCompression(context_, file->file, *file->path, writer)) { + context_->GetDiagnostics()->Error(DiagMessage(source_) + << "failed to copy file " << *file->path); + return false; + } } return true; diff --git a/tools/aapt2/cmd/Optimize.cpp b/tools/aapt2/cmd/Optimize.cpp index 688b6a7c3b3c..2bf91a530526 100644 --- a/tools/aapt2/cmd/Optimize.cpp +++ b/tools/aapt2/cmd/Optimize.cpp @@ -256,10 +256,8 @@ class OptimizeCommand { for (auto& entry : config_sorted_files) { FileReference* file_ref = entry.second; - uint32_t compression_flags = - file_ref->file->WasCompressed() ? ArchiveEntry::kCompress : 0u; - if (!io::CopyFileToArchive(context_, file_ref->file, *file_ref->path, compression_flags, - writer)) { + if (!io::CopyFileToArchivePreserveCompression(context_, file_ref->file, *file_ref->path, + writer)) { return false; } } diff --git a/tools/aapt2/io/Util.cpp b/tools/aapt2/io/Util.cpp index 7ee10161d86f..97516322c4cb 100644 --- a/tools/aapt2/io/Util.cpp +++ b/tools/aapt2/io/Util.cpp @@ -48,6 +48,12 @@ bool CopyFileToArchive(IAaptContext* context, io::IFile* file, const std::string return CopyInputStreamToArchive(context, data.get(), out_path, compression_flags, writer); } +bool CopyFileToArchivePreserveCompression(IAaptContext* context, io::IFile* file, + const std::string& out_path, IArchiveWriter* writer) { + uint32_t compression_flags = file->WasCompressed() ? ArchiveEntry::kCompress : 0u; + return CopyFileToArchive(context, file, out_path, compression_flags, writer); +} + bool CopyProtoToArchive(IAaptContext* context, ::google::protobuf::MessageLite* proto_msg, const std::string& out_path, uint32_t compression_flags, IArchiveWriter* writer) { diff --git a/tools/aapt2/io/Util.h b/tools/aapt2/io/Util.h index de2ab393336e..b07fb5399313 100644 --- a/tools/aapt2/io/Util.h +++ b/tools/aapt2/io/Util.h @@ -35,6 +35,9 @@ bool CopyInputStreamToArchive(IAaptContext* context, InputStream* in, const std: bool CopyFileToArchive(IAaptContext* context, IFile* file, const std::string& out_path, uint32_t compression_flags, IArchiveWriter* writer); +bool CopyFileToArchivePreserveCompression(IAaptContext* context, IFile* file, + const std::string& out_path, IArchiveWriter* writer); + bool CopyProtoToArchive(IAaptContext* context, ::google::protobuf::MessageLite* proto_msg, const std::string& out_path, uint32_t compression_flags, IArchiveWriter* writer); |