Loading tools/aapt2/cmd/Command.cpp +18 −6 Original line number Diff line number Diff line Loading @@ -54,7 +54,9 @@ 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; }; Loading @@ -65,7 +67,9 @@ 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; }; Loading @@ -76,7 +80,9 @@ 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; }; Loading @@ -87,7 +93,9 @@ 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; }; Loading @@ -98,7 +106,9 @@ 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; }; Loading @@ -108,7 +118,9 @@ 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; }; Loading tools/aapt2/cmd/Command_test.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -159,4 +159,22 @@ 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 tools/aapt2/cmd/Convert.cpp +0 −3 Original line number Diff line number Diff line Loading @@ -425,9 +425,6 @@ 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; } Loading tools/aapt2/cmd/Convert.h +3 −6 Original line number Diff line number Diff line Loading @@ -36,11 +36,9 @@ class ConvertCommand : public Command { kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_); AddOptionalSwitch( "--enable-sparse-encoding", "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_); "[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); 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" Loading Loading @@ -87,7 +85,6 @@ 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_; Loading tools/aapt2/cmd/Link.cpp +0 −3 Original line number Diff line number Diff line Loading @@ -2504,9 +2504,6 @@ 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 Loading
tools/aapt2/cmd/Command.cpp +18 −6 Original line number Diff line number Diff line Loading @@ -54,7 +54,9 @@ 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; }; Loading @@ -65,7 +67,9 @@ 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; }; Loading @@ -76,7 +80,9 @@ 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; }; Loading @@ -87,7 +93,9 @@ 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; }; Loading @@ -98,7 +106,9 @@ 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; }; Loading @@ -108,7 +118,9 @@ 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; }; Loading
tools/aapt2/cmd/Command_test.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -159,4 +159,22 @@ 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
tools/aapt2/cmd/Convert.cpp +0 −3 Original line number Diff line number Diff line Loading @@ -425,9 +425,6 @@ 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; } Loading
tools/aapt2/cmd/Convert.h +3 −6 Original line number Diff line number Diff line Loading @@ -36,11 +36,9 @@ class ConvertCommand : public Command { kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_); AddOptionalSwitch( "--enable-sparse-encoding", "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_); "[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); 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" Loading Loading @@ -87,7 +85,6 @@ 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_; Loading
tools/aapt2/cmd/Link.cpp +0 −3 Original line number Diff line number Diff line Loading @@ -2504,9 +2504,6 @@ 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