Loading tools/aapt2/Android.bp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -122,7 +122,6 @@ cc_library_host_static { "link/AutoVersioner.cpp", "link/AutoVersioner.cpp", "link/ManifestFixer.cpp", "link/ManifestFixer.cpp", "link/NoDefaultResourceRemover.cpp", "link/NoDefaultResourceRemover.cpp", "link/ProductFilter.cpp", "link/PrivateAttributeMover.cpp", "link/PrivateAttributeMover.cpp", "link/ReferenceLinker.cpp", "link/ReferenceLinker.cpp", "link/ResourceExcluder.cpp", "link/ResourceExcluder.cpp", Loading @@ -135,6 +134,7 @@ cc_library_host_static { "optimize/ResourceFilter.cpp", "optimize/ResourceFilter.cpp", "optimize/Obfuscator.cpp", "optimize/Obfuscator.cpp", "optimize/VersionCollapser.cpp", "optimize/VersionCollapser.cpp", "process/ProductFilter.cpp", "process/SymbolTable.cpp", "process/SymbolTable.cpp", "split/TableSplitter.cpp", "split/TableSplitter.cpp", "text/Printer.cpp", "text/Printer.cpp", Loading tools/aapt2/cmd/Compile.cpp +10 −0 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,7 @@ #include "io/StringStream.h" #include "io/StringStream.h" #include "io/Util.h" #include "io/Util.h" #include "io/ZipArchive.h" #include "io/ZipArchive.h" #include "process/ProductFilter.h" #include "trace/TraceBuffer.h" #include "trace/TraceBuffer.h" #include "util/Files.h" #include "util/Files.h" #include "util/Util.h" #include "util/Util.h" Loading Loading @@ -179,6 +180,15 @@ static bool CompileTable(IAaptContext* context, const CompileOptions& options, if (!res_parser.Parse(&xml_parser)) { if (!res_parser.Parse(&xml_parser)) { return false; return false; } } if (options.product_.has_value()) { if (!ProductFilter({*options.product_}, /* remove_default_config_values = */ true) .Consume(context, &table)) { context->GetDiagnostics()->Error(android::DiagMessage(path_data.source) << "failed to filter product"); return false; } } } } if (options.pseudolocalize && translatable_file) { if (options.pseudolocalize && translatable_file) { Loading tools/aapt2/cmd/Compile.h +5 −0 Original line number Original line Diff line number Diff line Loading @@ -44,6 +44,7 @@ struct CompileOptions { // See comments on aapt::ResourceParserOptions. // See comments on aapt::ResourceParserOptions. bool preserve_visibility_of_styleables = false; bool preserve_visibility_of_styleables = false; bool verbose = false; bool verbose = false; std::optional<std::string> product_; }; }; /** Parses flags and compiles resources to be used in linking. */ /** Parses flags and compiles resources to be used in linking. */ Loading Loading @@ -87,6 +88,10 @@ class CompileCommand : public Command { "Sets the ratio of resources to generate grammatical gender strings for. The " "Sets the ratio of resources to generate grammatical gender strings for. The " "ratio has to be a float number between 0 and 1.", "ratio has to be a float number between 0 and 1.", &options_.pseudo_localize_gender_ratio); &options_.pseudo_localize_gender_ratio); AddOptionalFlag("--filter-product", "Leave only resources specific to the given product. All " "other resources (including defaults) are removed.", &options_.product_); } } int Action(const std::vector<std::string>& args) override; int Action(const std::vector<std::string>& args) override; Loading tools/aapt2/cmd/Link.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -66,6 +66,7 @@ #include "optimize/ResourceDeduper.h" #include "optimize/ResourceDeduper.h" #include "optimize/VersionCollapser.h" #include "optimize/VersionCollapser.h" #include "process/IResourceTableConsumer.h" #include "process/IResourceTableConsumer.h" #include "process/ProductFilter.h" #include "process/SymbolTable.h" #include "process/SymbolTable.h" #include "split/TableSplitter.h" #include "split/TableSplitter.h" #include "trace/TraceBuffer.h" #include "trace/TraceBuffer.h" Loading Loading @@ -2128,7 +2129,7 @@ class Linker { << "can't select products when building static library"); << "can't select products when building static library"); } } } else { } else { ProductFilter product_filter(options_.products); ProductFilter product_filter(options_.products, /* remove_default_config_values = */ false); if (!product_filter.Consume(context_, &final_table_)) { if (!product_filter.Consume(context_, &final_table_)) { context_->GetDiagnostics()->Error(android::DiagMessage() << "failed stripping products"); context_->GetDiagnostics()->Error(android::DiagMessage() << "failed stripping products"); return 1; return 1; Loading tools/aapt2/link/Linkers.h +3 −25 Original line number Original line Diff line number Diff line Loading @@ -20,12 +20,12 @@ #include <set> #include <set> #include <unordered_set> #include <unordered_set> #include "Resource.h" #include "SdkConstants.h" #include "android-base/macros.h" #include "android-base/macros.h" #include "android-base/result.h" #include "androidfw/ConfigDescription.h" #include "androidfw/ConfigDescription.h" #include "androidfw/StringPiece.h" #include "androidfw/StringPiece.h" #include "Resource.h" #include "SdkConstants.h" #include "process/IResourceTableConsumer.h" #include "process/IResourceTableConsumer.h" #include "xml/XmlDom.h" #include "xml/XmlDom.h" Loading Loading @@ -92,28 +92,6 @@ class PrivateAttributeMover : public IResourceTableConsumer { DISALLOW_COPY_AND_ASSIGN(PrivateAttributeMover); DISALLOW_COPY_AND_ASSIGN(PrivateAttributeMover); }; }; class ResourceConfigValue; class ProductFilter : public IResourceTableConsumer { public: using ResourceConfigValueIter = std::vector<std::unique_ptr<ResourceConfigValue>>::iterator; explicit ProductFilter(std::unordered_set<std::string> products) : products_(products) { } ResourceConfigValueIter SelectProductToKeep(const ResourceNameRef& name, const ResourceConfigValueIter begin, const ResourceConfigValueIter end, android::IDiagnostics* diag); bool Consume(IAaptContext* context, ResourceTable* table) override; private: DISALLOW_COPY_AND_ASSIGN(ProductFilter); std::unordered_set<std::string> products_; }; // Removes namespace nodes and URI information from the XmlResource. // Removes namespace nodes and URI information from the XmlResource. // // // Once an XmlResource is processed by this consumer, it is no longer able to have its attributes // Once an XmlResource is processed by this consumer, it is no longer able to have its attributes Loading Loading
tools/aapt2/Android.bp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -122,7 +122,6 @@ cc_library_host_static { "link/AutoVersioner.cpp", "link/AutoVersioner.cpp", "link/ManifestFixer.cpp", "link/ManifestFixer.cpp", "link/NoDefaultResourceRemover.cpp", "link/NoDefaultResourceRemover.cpp", "link/ProductFilter.cpp", "link/PrivateAttributeMover.cpp", "link/PrivateAttributeMover.cpp", "link/ReferenceLinker.cpp", "link/ReferenceLinker.cpp", "link/ResourceExcluder.cpp", "link/ResourceExcluder.cpp", Loading @@ -135,6 +134,7 @@ cc_library_host_static { "optimize/ResourceFilter.cpp", "optimize/ResourceFilter.cpp", "optimize/Obfuscator.cpp", "optimize/Obfuscator.cpp", "optimize/VersionCollapser.cpp", "optimize/VersionCollapser.cpp", "process/ProductFilter.cpp", "process/SymbolTable.cpp", "process/SymbolTable.cpp", "split/TableSplitter.cpp", "split/TableSplitter.cpp", "text/Printer.cpp", "text/Printer.cpp", Loading
tools/aapt2/cmd/Compile.cpp +10 −0 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,7 @@ #include "io/StringStream.h" #include "io/StringStream.h" #include "io/Util.h" #include "io/Util.h" #include "io/ZipArchive.h" #include "io/ZipArchive.h" #include "process/ProductFilter.h" #include "trace/TraceBuffer.h" #include "trace/TraceBuffer.h" #include "util/Files.h" #include "util/Files.h" #include "util/Util.h" #include "util/Util.h" Loading Loading @@ -179,6 +180,15 @@ static bool CompileTable(IAaptContext* context, const CompileOptions& options, if (!res_parser.Parse(&xml_parser)) { if (!res_parser.Parse(&xml_parser)) { return false; return false; } } if (options.product_.has_value()) { if (!ProductFilter({*options.product_}, /* remove_default_config_values = */ true) .Consume(context, &table)) { context->GetDiagnostics()->Error(android::DiagMessage(path_data.source) << "failed to filter product"); return false; } } } } if (options.pseudolocalize && translatable_file) { if (options.pseudolocalize && translatable_file) { Loading
tools/aapt2/cmd/Compile.h +5 −0 Original line number Original line Diff line number Diff line Loading @@ -44,6 +44,7 @@ struct CompileOptions { // See comments on aapt::ResourceParserOptions. // See comments on aapt::ResourceParserOptions. bool preserve_visibility_of_styleables = false; bool preserve_visibility_of_styleables = false; bool verbose = false; bool verbose = false; std::optional<std::string> product_; }; }; /** Parses flags and compiles resources to be used in linking. */ /** Parses flags and compiles resources to be used in linking. */ Loading Loading @@ -87,6 +88,10 @@ class CompileCommand : public Command { "Sets the ratio of resources to generate grammatical gender strings for. The " "Sets the ratio of resources to generate grammatical gender strings for. The " "ratio has to be a float number between 0 and 1.", "ratio has to be a float number between 0 and 1.", &options_.pseudo_localize_gender_ratio); &options_.pseudo_localize_gender_ratio); AddOptionalFlag("--filter-product", "Leave only resources specific to the given product. All " "other resources (including defaults) are removed.", &options_.product_); } } int Action(const std::vector<std::string>& args) override; int Action(const std::vector<std::string>& args) override; Loading
tools/aapt2/cmd/Link.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -66,6 +66,7 @@ #include "optimize/ResourceDeduper.h" #include "optimize/ResourceDeduper.h" #include "optimize/VersionCollapser.h" #include "optimize/VersionCollapser.h" #include "process/IResourceTableConsumer.h" #include "process/IResourceTableConsumer.h" #include "process/ProductFilter.h" #include "process/SymbolTable.h" #include "process/SymbolTable.h" #include "split/TableSplitter.h" #include "split/TableSplitter.h" #include "trace/TraceBuffer.h" #include "trace/TraceBuffer.h" Loading Loading @@ -2128,7 +2129,7 @@ class Linker { << "can't select products when building static library"); << "can't select products when building static library"); } } } else { } else { ProductFilter product_filter(options_.products); ProductFilter product_filter(options_.products, /* remove_default_config_values = */ false); if (!product_filter.Consume(context_, &final_table_)) { if (!product_filter.Consume(context_, &final_table_)) { context_->GetDiagnostics()->Error(android::DiagMessage() << "failed stripping products"); context_->GetDiagnostics()->Error(android::DiagMessage() << "failed stripping products"); return 1; return 1; Loading
tools/aapt2/link/Linkers.h +3 −25 Original line number Original line Diff line number Diff line Loading @@ -20,12 +20,12 @@ #include <set> #include <set> #include <unordered_set> #include <unordered_set> #include "Resource.h" #include "SdkConstants.h" #include "android-base/macros.h" #include "android-base/macros.h" #include "android-base/result.h" #include "androidfw/ConfigDescription.h" #include "androidfw/ConfigDescription.h" #include "androidfw/StringPiece.h" #include "androidfw/StringPiece.h" #include "Resource.h" #include "SdkConstants.h" #include "process/IResourceTableConsumer.h" #include "process/IResourceTableConsumer.h" #include "xml/XmlDom.h" #include "xml/XmlDom.h" Loading Loading @@ -92,28 +92,6 @@ class PrivateAttributeMover : public IResourceTableConsumer { DISALLOW_COPY_AND_ASSIGN(PrivateAttributeMover); DISALLOW_COPY_AND_ASSIGN(PrivateAttributeMover); }; }; class ResourceConfigValue; class ProductFilter : public IResourceTableConsumer { public: using ResourceConfigValueIter = std::vector<std::unique_ptr<ResourceConfigValue>>::iterator; explicit ProductFilter(std::unordered_set<std::string> products) : products_(products) { } ResourceConfigValueIter SelectProductToKeep(const ResourceNameRef& name, const ResourceConfigValueIter begin, const ResourceConfigValueIter end, android::IDiagnostics* diag); bool Consume(IAaptContext* context, ResourceTable* table) override; private: DISALLOW_COPY_AND_ASSIGN(ProductFilter); std::unordered_set<std::string> products_; }; // Removes namespace nodes and URI information from the XmlResource. // Removes namespace nodes and URI information from the XmlResource. // // // Once an XmlResource is processed by this consumer, it is no longer able to have its attributes // Once an XmlResource is processed by this consumer, it is no longer able to have its attributes Loading