diff options
author | Shane Farmer <safarmer@google.com> | 2017-08-24 15:55:36 -0700 |
---|---|---|
committer | Shane Farmer <safarmer@google.com> | 2017-08-31 10:17:39 -0700 |
commit | 9ecc0751e30086c0668c8fe5758f14fc5acf5ae8 (patch) | |
tree | 1ba755615a30e1c5199a59772780a6e7dc60742a /tools/aapt2/optimize/MultiApkGenerator.cpp | |
parent | c7674ae31623eeca2265e34042bdcdcbcab84942 (diff) |
AAPT2: Add flag to print multi APK artifact names.
- Added new flag that exits after printing the list of artifact names
that would be generated from the combination of the configuration file
and input APK.
- Cleaned up the code to generate the artifact names which also involved
adding some more test cases for corner cases.
Test: Unit tests
Test: Manually ran new command
Test: Manually ran old command
Change-Id: I8d30e7a4a070af26945b8f544a13f23bdf1ba169
Diffstat (limited to 'tools/aapt2/optimize/MultiApkGenerator.cpp')
-rw-r--r-- | tools/aapt2/optimize/MultiApkGenerator.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/tools/aapt2/optimize/MultiApkGenerator.cpp b/tools/aapt2/optimize/MultiApkGenerator.cpp index 83162640a5d9..e7a4f8578529 100644 --- a/tools/aapt2/optimize/MultiApkGenerator.cpp +++ b/tools/aapt2/optimize/MultiApkGenerator.cpp @@ -44,11 +44,11 @@ bool MultiApkGenerator::FromBaseApk(const std::string& out_dir, const PostProcessingConfiguration& config, const TableFlattenerOptions& table_flattener_options) { // TODO(safarmer): Handle APK version codes for the generated APKs. - // TODO(safarmer): Handle explicit outputs/generating an output file list for other tools. + IDiagnostics* diag = context_->GetDiagnostics(); - const std::string& apk_path = file::GetFilename(apk_->GetSource().path).to_string(); - const StringPiece ext = file::GetExtension(apk_path); - const std::string base_name = apk_path.substr(0, apk_path.rfind(ext.to_string())); + const std::string& apk_name = file::GetFilename(apk_->GetSource().path).to_string(); + const StringPiece ext = file::GetExtension(apk_name); + const std::string base_name = apk_name.substr(0, apk_name.rfind(ext.to_string())); // For now, just write out the stripped APK since ABI splitting doesn't modify anything else. for (const Artifact& artifact : config.artifacts) { @@ -57,20 +57,17 @@ bool MultiApkGenerator::FromBaseApk(const std::string& out_dir, AxisConfigFilter axis_filter; if (!artifact.name && !config.artifact_format) { - context_->GetDiagnostics()->Error( + diag->Error( DiagMessage() << "Artifact does not have a name and no global name template defined"); return false; } Maybe<std::string> artifact_name = - (artifact.name) - ? artifact.Name(base_name, ext.substr(1), context_->GetDiagnostics()) - : artifact.ToArtifactName(config.artifact_format.value(), context_->GetDiagnostics(), - base_name, ext.substr(1)); + (artifact.name) ? artifact.Name(apk_name, diag) + : artifact.ToArtifactName(config.artifact_format.value(), apk_name, diag); if (!artifact_name) { - context_->GetDiagnostics()->Error(DiagMessage() - << "Could not determine split APK artifact name"); + diag->Error(DiagMessage() << "Could not determine split APK artifact name"); return false; } @@ -80,8 +77,7 @@ bool MultiApkGenerator::FromBaseApk(const std::string& out_dir, auto group = config.abi_groups.find(group_name); // TODO: Remove validation when configuration parser ensures referential integrity. if (group == config.abi_groups.end()) { - context_->GetDiagnostics()->Error(DiagMessage() << "could not find referenced ABI group '" - << group_name << "'"); + diag->Error(DiagMessage() << "could not find referenced ABI group '" << group_name << "'"); return false; } filters.AddFilter(AbiFilter::FromAbiList(group->second)); @@ -93,8 +89,7 @@ bool MultiApkGenerator::FromBaseApk(const std::string& out_dir, auto group = config.screen_density_groups.find(group_name); // TODO: Remove validation when configuration parser ensures referential integrity. if (group == config.screen_density_groups.end()) { - context_->GetDiagnostics()->Error(DiagMessage() << "could not find referenced group '" - << group_name << "'"); + diag->Error(DiagMessage() << "could not find referenced group '" << group_name << "'"); return false; } @@ -109,8 +104,7 @@ bool MultiApkGenerator::FromBaseApk(const std::string& out_dir, auto group = config.locale_groups.find(group_name); // TODO: Remove validation when configuration parser ensures referential integrity. if (group == config.locale_groups.end()) { - context_->GetDiagnostics()->Error(DiagMessage() << "could not find referenced group '" - << group_name << "'"); + diag->Error(DiagMessage() << "could not find referenced group '" << group_name << "'"); return false; } @@ -132,11 +126,10 @@ bool MultiApkGenerator::FromBaseApk(const std::string& out_dir, } file::AppendPath(&out, artifact_name.value()); - std::unique_ptr<IArchiveWriter> writer = - CreateZipFileArchiveWriter(context_->GetDiagnostics(), out); + std::unique_ptr<IArchiveWriter> writer = CreateZipFileArchiveWriter(diag, out); if (context_->IsVerbose()) { - context_->GetDiagnostics()->Note(DiagMessage() << "Writing output: " << out); + diag->Note(DiagMessage() << "Writing output: " << out); } if (!apk_->WriteToArchive(context_, table.get(), table_flattener_options, &filters, |