Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 911f76c3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Implement filter-product" into main

parents 735008fc 5fe521e5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -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",
@@ -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",
+10 −0
Original line number Original line Diff line number Diff line
@@ -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"
@@ -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) {
+5 −0
Original line number Original line Diff line number Diff line
@@ -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.  */
@@ -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;
+2 −1
Original line number Original line Diff line number Diff line
@@ -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"
@@ -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;
+3 −25
Original line number Original line Diff line number Diff line
@@ -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"


@@ -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