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

Commit 9f1cf060 authored by Mark Punzalan's avatar Mark Punzalan Committed by Android (Google) Code Review
Browse files

Merge "Revert "Always enable sparse encoding if minSdk >= 32"" into main

parents 177be536 502bb719
Loading
Loading
Loading
Loading
+6 −18
Original line number Diff line number Diff line
@@ -54,9 +54,7 @@ std::string GetSafePath(StringPiece arg) {
void Command::AddRequiredFlag(StringPiece name, StringPiece description, std::string* value,
                              uint32_t flags) {
  auto func = [value, flags](StringPiece arg, std::ostream*) -> bool {
    if (value) {
    *value = (flags & Command::kPath) ? GetSafePath(arg) : std::string(arg);
    }
    return true;
  };

@@ -67,9 +65,7 @@ void Command::AddRequiredFlag(StringPiece name, StringPiece description, std::st
void Command::AddRequiredFlagList(StringPiece name, StringPiece description,
                                  std::vector<std::string>* value, uint32_t flags) {
  auto func = [value, flags](StringPiece arg, std::ostream*) -> bool {
    if (value) {
    value->push_back((flags & Command::kPath) ? GetSafePath(arg) : std::string(arg));
    }
    return true;
  };

@@ -80,9 +76,7 @@ void Command::AddRequiredFlagList(StringPiece name, StringPiece description,
void Command::AddOptionalFlag(StringPiece name, StringPiece description,
                              std::optional<std::string>* value, uint32_t flags) {
  auto func = [value, flags](StringPiece arg, std::ostream*) -> bool {
    if (value) {
    *value = (flags & Command::kPath) ? GetSafePath(arg) : std::string(arg);
    }
    return true;
  };

@@ -93,9 +87,7 @@ void Command::AddOptionalFlag(StringPiece name, StringPiece description,
void Command::AddOptionalFlagList(StringPiece name, StringPiece description,
                                  std::vector<std::string>* value, uint32_t flags) {
  auto func = [value, flags](StringPiece arg, std::ostream*) -> bool {
    if (value) {
    value->push_back((flags & Command::kPath) ? GetSafePath(arg) : std::string(arg));
    }
    return true;
  };

@@ -106,9 +98,7 @@ void Command::AddOptionalFlagList(StringPiece name, StringPiece description,
void Command::AddOptionalFlagList(StringPiece name, StringPiece description,
                                  std::unordered_set<std::string>* value) {
  auto func = [value](StringPiece arg, std::ostream* out_error) -> bool {
    if (value) {
    value->emplace(arg);
    }
    return true;
  };

@@ -118,9 +108,7 @@ void Command::AddOptionalFlagList(StringPiece name, StringPiece description,

void Command::AddOptionalSwitch(StringPiece name, StringPiece description, bool* value) {
  auto func = [value](StringPiece arg, std::ostream* out_error) -> bool {
    if (value) {
    *value = true;
    }
    return true;
  };

+0 −18
Original line number Diff line number Diff line
@@ -159,22 +159,4 @@ TEST(CommandTest, ShortOptions) {
  ASSERT_NE(0, command.Execute({"-w"s, "2"s}, &std::cerr));
}

TEST(CommandTest, OptionsWithNullptrToAcceptValues) {
  TestCommand command;
  command.AddRequiredFlag("--rflag", "", nullptr);
  command.AddRequiredFlagList("--rlflag", "", nullptr);
  command.AddOptionalFlag("--oflag", "", nullptr);
  command.AddOptionalFlagList("--olflag", "", (std::vector<std::string>*)nullptr);
  command.AddOptionalFlagList("--olflag2", "", (std::unordered_set<std::string>*)nullptr);
  command.AddOptionalSwitch("--switch", "", nullptr);

  ASSERT_EQ(0, command.Execute({
    "--rflag"s, "1"s,
    "--rlflag"s, "1"s,
    "--oflag"s, "1"s,
    "--olflag"s, "1"s,
    "--olflag2"s, "1"s,
    "--switch"s}, &std::cerr));
}

}  // namespace aapt
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -425,6 +425,9 @@ int ConvertCommand::Action(const std::vector<std::string>& args) {
                                    << output_format_.value());
    return 1;
  }
  if (enable_sparse_encoding_) {
    table_flattener_options_.sparse_entries = SparseEntriesMode::Enabled;
  }
  if (force_sparse_encoding_) {
    table_flattener_options_.sparse_entries = SparseEntriesMode::Forced;
  }
+6 −3
Original line number Diff line number Diff line
@@ -36,9 +36,11 @@ class ConvertCommand : public Command {
        kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_);
    AddOptionalSwitch(
        "--enable-sparse-encoding",
        "[DEPRECATED] This flag is a no-op as of aapt2 v2.20. Sparse encoding is always\n"
        "enabled if minSdk of the APK is >= 32.",
        nullptr);
        "Enables encoding sparse entries using a binary search tree.\n"
        "This decreases APK size at the cost of resource retrieval performance.\n"
        "Only applies sparse encoding to Android O+ resources or all resources if minSdk of "
        "the APK is O+",
        &enable_sparse_encoding_);
    AddOptionalSwitch("--force-sparse-encoding",
                      "Enables encoding sparse entries using a binary search tree.\n"
                      "This decreases APK size at the cost of resource retrieval performance.\n"
@@ -85,6 +87,7 @@ class ConvertCommand : public Command {
  std::string output_path_;
  std::optional<std::string> output_format_;
  bool verbose_ = false;
  bool enable_sparse_encoding_ = false;
  bool force_sparse_encoding_ = false;
  bool enable_compact_entries_ = false;
  std::optional<std::string> resources_config_path_;
+3 −0
Original line number Diff line number Diff line
@@ -2505,6 +2505,9 @@ int LinkCommand::Action(const std::vector<std::string>& args) {
                << "the --merge-only flag can be only used when building a static library");
    return 1;
  }
  if (options_.use_sparse_encoding) {
    options_.table_flattener_options.sparse_entries = SparseEntriesMode::Enabled;
  }

  // The default build type.
  context.SetPackageType(PackageType::kApp);
Loading