pw_tokenizer: Use facades for global handlers
Previously, pw_tokenizer conditionally enabled the global handlers with
macros. The default was that they were enabled, which meant handlers had
to be defined, even if they weren't used.
This change moves the two global handlers from the core pw_tokenizer
library to separate facades. This allows projects to define only the
global handlers they need.
Change-Id: Ic8598d9e62921b706fa0b76032b2a14265669360
diff --git a/pw_tokenizer/BUILD.gn b/pw_tokenizer/BUILD.gn
index 619e760..7853a27 100644
--- a/pw_tokenizer/BUILD.gn
+++ b/pw_tokenizer/BUILD.gn
@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations under
# the License.
+import("$dir_pw_build/facade.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_fuzzer/fuzzer.gni")
import("$dir_pw_unit_test/test.gni")
@@ -23,15 +24,16 @@
source_set("pw_tokenizer") {
public_configs = [ ":default_config" ]
public_deps = [
- "$dir_pw_preprocessor",
- "$dir_pw_span",
+ dir_pw_preprocessor,
+ dir_pw_span,
]
- deps = [ "$dir_pw_varint" ]
+ deps = [ dir_pw_varint ]
public = [
"public/pw_tokenizer/pw_tokenizer_65599_fixed_length_hash.h",
"public/pw_tokenizer/tokenize.h",
]
sources = [
+ "encode_args.cc",
"public/pw_tokenizer/config.h",
"public/pw_tokenizer/internal/argument_types.h",
"public/pw_tokenizer/internal/argument_types_macro_4_byte.h",
@@ -40,26 +42,66 @@
"public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_80_hash_macro.h",
"public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_96_hash_macro.h",
"public/pw_tokenizer/internal/tokenize_string.h",
+ "pw_tokenizer_private/encode_args.h",
"tokenize.cc",
]
friend = [ ":*" ]
}
+# As a temporary workaround, if no backend is set, use an empty test backend so
+# that the test can define the handler function.
+# TODO(hepler): Switch this to a facade test when available.
+if (dir_pw_tokenizer_global_handler_backend == "" &&
+ dir_pw_tokenizer_global_handler_with_payload_backend == "") {
+ # This is an empty library to use as the backend for global_handler and
+ # global_handler_with_payload tests.
+ source_set("test_backend") {
+ visibility = [ ":*" ]
+ }
+
+ dir_pw_tokenizer_global_handler_backend = ":test_backend"
+ dir_pw_tokenizer_global_handler_with_payload_backend = ":test_backend"
+
+ enable_global_handler_test = true
+} else {
+ enable_global_handler_test = false
+}
+
+pw_facade("global_handler") {
+ facade_name = "global_handler_facade"
+ backend = dir_pw_tokenizer_global_handler_backend
+
+ public_configs = [ ":default_config" ]
+ public = [ "public/pw_tokenizer/tokenize_to_global_handler.h" ]
+ sources = [ "tokenize_to_global_handler.cc" ]
+ public_deps = [ ":pw_tokenizer" ]
+}
+
+pw_facade("global_handler_with_payload") {
+ facade_name = "global_handler_with_payload_facade"
+ backend = dir_pw_tokenizer_global_handler_with_payload_backend
+
+ public_configs = [ ":default_config" ]
+ public = [ "public/pw_tokenizer/tokenize_to_global_handler_with_payload.h" ]
+ sources = [ "tokenize_to_global_handler_with_payload.cc" ]
+ public_deps = [ ":pw_tokenizer" ]
+}
+
source_set("base64") {
public_configs = [ ":default_config" ]
public = [ "public/pw_tokenizer/base64.h" ]
sources = [ "base64.cc" ]
public_deps = [
- "$dir_pw_preprocessor",
- "$dir_pw_span",
+ dir_pw_preprocessor,
+ dir_pw_span,
]
- deps = [ "$dir_pw_base64" ]
+ deps = [ dir_pw_base64 ]
}
source_set("decoder") {
public_configs = [ ":default_config" ]
- public_deps = [ "$dir_pw_span" ]
- deps = [ "$dir_pw_varint" ]
+ public_deps = [ dir_pw_span ]
+ deps = [ dir_pw_varint ]
public = [
"public/pw_tokenizer/detokenize.h",
"public/pw_tokenizer/token_database.h",
@@ -79,7 +121,7 @@
deps = [
":decoder",
":pw_tokenizer",
- "$dir_pw_varint",
+ dir_pw_varint,
]
sources = [
"generate_decoding_test_data.cc",
@@ -105,6 +147,7 @@
":decode_test",
":detokenize_fuzzer",
":detokenize_test",
+ ":global_handlers_test",
":hash_test",
":simple_tokenize_test_cpp11",
":simple_tokenize_test_cpp14",
@@ -152,6 +195,21 @@
deps = [ ":decoder" ]
}
+pw_test("global_handlers_test") {
+ sources = [
+ "global_handlers_test.c",
+ "global_handlers_test.cc",
+ "pw_tokenizer_private/tokenize_test.h",
+ ]
+ deps = [
+ ":global_handler",
+ ":global_handler_with_payload",
+ ]
+
+ # TODO(hepler): Switch this to a facade test when available.
+ enable_if = enable_global_handler_test
+}
+
pw_test("hash_test") {
sources = [
"hash_test.cc",
@@ -166,6 +224,7 @@
_simple_tokenize_test_sources = [
"$dir_pw_varint/public/pw_varint/varint.h",
"$dir_pw_varint/varint.cc",
+ "encode_args.cc",
"public/pw_tokenizer/config.h",
"public/pw_tokenizer/internal/argument_types.h",
"public/pw_tokenizer/internal/argument_types_macro_4_byte.h",
@@ -176,8 +235,13 @@
"public/pw_tokenizer/internal/tokenize_string.h",
"public/pw_tokenizer/pw_tokenizer_65599_fixed_length_hash.h",
"public/pw_tokenizer/tokenize.h",
+ "public/pw_tokenizer/tokenize_to_global_handler.h",
+ "public/pw_tokenizer/tokenize_to_global_handler_with_payload.h",
+ "pw_tokenizer_private/encode_args.h",
"simple_tokenize_test.cc",
"tokenize.cc",
+ "tokenize_to_global_handler.cc",
+ "tokenize_to_global_handler_with_payload.cc",
]
_simple_tokenize_test_configs = [
":default_config",