diff options
author | Shane Farmer <safarmer@google.com> | 2017-11-29 16:07:51 -0800 |
---|---|---|
committer | Shane Farmer <safarmer@google.com> | 2017-12-05 10:52:48 -0800 |
commit | 666de34a58320ecf24b78fff836732d8278f3e98 (patch) | |
tree | e977214900398a0c8dc325893a5dc2aa0cbc3790 /tools/aapt2/optimize/MultiApkGenerator.cpp | |
parent | 4f7413ea39e52fba994d41007f3f02170f1edfb2 (diff) |
AAPT2: Allow output artifacts to be filtered.
A new optional flag has been added to allow a list of artifacts that
should be written as output to be provided. If the flag is provided,
only artifacts that have an output name matching an entry in the list
will be processed.
Test: manually ran against an APK with multiple artifacts in the
configuration and confirmed that only the specified artifacts were
written.
Test: Ran all unit tests.
Change-Id: Ia32b19acf1b2ef3711abf13df08dc7b1aa0cf161
Diffstat (limited to 'tools/aapt2/optimize/MultiApkGenerator.cpp')
-rw-r--r-- | tools/aapt2/optimize/MultiApkGenerator.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/aapt2/optimize/MultiApkGenerator.cpp b/tools/aapt2/optimize/MultiApkGenerator.cpp index 3c96344d8602..da3b8792be69 100644 --- a/tools/aapt2/optimize/MultiApkGenerator.cpp +++ b/tools/aapt2/optimize/MultiApkGenerator.cpp @@ -137,6 +137,10 @@ bool MultiApkGenerator::FromBaseApk(const MultiApkGeneratorOptions& options) { const StringPiece ext = file::GetExtension(apk_name); const std::string base_name = apk_name.substr(0, apk_name.rfind(ext.to_string())); + std::unordered_set<std::string> artifacts_to_keep = options.kept_artifacts; + std::unordered_set<std::string> filtered_artifacts; + std::unordered_set<std::string> kept_artifacts; + // For now, just write out the stripped APK since ABI splitting doesn't modify anything else. for (const Artifact& artifact : config.artifacts) { SourcePathDiagnostics diag{{apk_name}, context_->GetDiagnostics()}; @@ -163,6 +167,20 @@ bool MultiApkGenerator::FromBaseApk(const MultiApkGeneratorOptions& options) { ContextWrapper wrapped_context{context_}; wrapped_context.SetSource({artifact_name}); + if (!options.kept_artifacts.empty()) { + const auto& it = artifacts_to_keep.find(artifact_name); + if (it == artifacts_to_keep.end()) { + filtered_artifacts.insert(artifact_name); + if (context_->IsVerbose()) { + context_->GetDiagnostics()->Note(DiagMessage(artifact_name) << "skipping artifact"); + } + continue; + } else { + artifacts_to_keep.erase(it); + kept_artifacts.insert(artifact_name); + } + } + std::unique_ptr<ResourceTable> table = FilterTable(artifact, config, *apk_->GetResourceTable(), &wrapped_context, &filters); if (!table) { @@ -197,6 +215,30 @@ bool MultiApkGenerator::FromBaseApk(const MultiApkGeneratorOptions& options) { } } + // Make sure all of the requested artifacts were valid. If there are any kept artifacts left, + // either the config or the command line was wrong. + if (!artifacts_to_keep.empty()) { + context_->GetDiagnostics()->Error( + DiagMessage() << "The configuration and command line to filter artifacts do not match"); + + context_->GetDiagnostics()->Error(DiagMessage() << kept_artifacts.size() << " kept:"); + for (const auto& artifact : kept_artifacts) { + context_->GetDiagnostics()->Error(DiagMessage() << " " << artifact); + } + + context_->GetDiagnostics()->Error(DiagMessage() << filtered_artifacts.size() << " filtered:"); + for (const auto& artifact : filtered_artifacts) { + context_->GetDiagnostics()->Error(DiagMessage() << " " << artifact); + } + + context_->GetDiagnostics()->Error(DiagMessage() << artifacts_to_keep.size() << " missing:"); + for (const auto& artifact : artifacts_to_keep) { + context_->GetDiagnostics()->Error(DiagMessage() << " " << artifact); + } + + return false; + } + return true; } |