blob: 35c1757b58346c34257fb235eaa6703fe7e52f3a [file] [log] [blame]
# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
import("//build_overrides/pigweed.gni")
import("$dir_pw_arduino_build/arduino.gni")
import("$dir_pw_build/facade.gni")
import("$dir_pw_build/module_config.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_fuzzer/fuzzer.gni")
import("$dir_pw_unit_test/test.gni")
import("backend.gni")
declare_args() {
# The build target that overrides the default configuration options for this
# module. This should point to a source set that provides defines through a
# public config (which may -include a file or add defines directly).
pw_tokenizer_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
}
config("public_include_path") {
include_dirs = [ "public" ]
visibility = [ ":*" ]
}
config("linker_script") {
inputs = [ "pw_tokenizer_linker_sections.ld" ]
# Automatically add the tokenizer linker sections when cross-compiling or
# building for Linux. macOS and Windows executables are not supported.
if (current_os == "") {
ldflags = [
"-T",
rebase_path("pw_tokenizer_linker_sections.ld"),
]
} else if (current_os == "linux") {
# When building for Linux, the linker provides a default linker script.
# The add_tokenizer_sections_to_default_script.ld wrapper includes the
# pw_tokenizer_linker_sections.ld script in a way that appends to the the
# default linker script instead of overriding it.
ldflags = [
"-T",
rebase_path("add_tokenizer_sections_to_default_script.ld"),
"-L",
rebase_path("."),
]
inputs += [ "add_tokenizer_sections_to_default_script.ld" ]
}
visibility = [ ":*" ]
}
pw_source_set("config") {
public = [ "public/pw_tokenizer/config.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [ pw_tokenizer_CONFIG ]
}
pw_source_set("pw_tokenizer") {
public_configs = [ ":public_include_path" ]
all_dependent_configs = [ ":linker_script" ]
public_deps = [
":config",
dir_pw_preprocessor,
dir_pw_span,
]
deps = [ dir_pw_varint ]
public = [
"public/pw_tokenizer/hash.h",
"public/pw_tokenizer/tokenize.h",
]
sources = [
"encode_args.cc",
"hash.cc",
"public/pw_tokenizer/internal/argument_types.h",
"public/pw_tokenizer/internal/argument_types_macro_4_byte.h",
"public/pw_tokenizer/internal/argument_types_macro_8_byte.h",
"public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_128_hash_macro.h",
"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 (pw_tokenizer_GLOBAL_HANDLER_BACKEND == "" &&
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.
pw_source_set("test_backend") {
visibility = [ ":*" ]
}
pw_tokenizer_GLOBAL_HANDLER_BACKEND = ":test_backend"
pw_tokenizer_GLOBAL_HANDLER_WITH_PAYLOAD_BACKEND = ":test_backend"
enable_global_handler_test = true
} else {
enable_global_handler_test = false
}
pw_facade("global_handler") {
backend = pw_tokenizer_GLOBAL_HANDLER_BACKEND
public_configs = [ ":public_include_path" ]
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") {
backend = pw_tokenizer_GLOBAL_HANDLER_WITH_PAYLOAD_BACKEND
public_configs = [ ":public_include_path" ]
public = [ "public/pw_tokenizer/tokenize_to_global_handler_with_payload.h" ]
sources = [ "tokenize_to_global_handler_with_payload.cc" ]
public_deps = [ ":pw_tokenizer" ]
}
pw_source_set("base64") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_tokenizer/base64.h" ]
sources = [ "base64.cc" ]
public_deps = [
":pw_tokenizer",
dir_pw_base64,
dir_pw_preprocessor,
dir_pw_span,
]
}
pw_source_set("decoder") {
public_configs = [ ":public_include_path" ]
public_deps = [ dir_pw_span ]
deps = [ dir_pw_varint ]
public = [
"public/pw_tokenizer/detokenize.h",
"public/pw_tokenizer/token_database.h",
]
sources = [
"decode.cc",
"detokenize.cc",
"public/pw_tokenizer/internal/decode.h",
"token_database.cc",
]
friend = [ ":*" ]
}
# Executable for generating test data for the C++ and Python detokenizers. This
# target should only be built for the host.
pw_executable("generate_decoding_test_data") {
deps = [
":decoder",
":pw_tokenizer",
dir_pw_varint,
]
sources = [ "generate_decoding_test_data.cc" ]
}
# Executable for generating a test ELF file for elf_reader_test.py. A host
# version of this binary is checked in for use in elf_reader_test.py.
pw_executable("elf_reader_test_binary") {
deps = [
":pw_tokenizer",
"$dir_pw_varint",
]
sources = [ "py/elf_reader_test_binary.c" ]
ldflags = [ "-Wl,--unresolved-symbols=ignore-all" ] # main is not defined
}
pw_test_group("tests") {
tests = [
":argument_types_test",
":base64_test",
":decode_test",
":detokenize_fuzzer",
":detokenize_test",
":global_handlers_test",
":hash_test",
":simple_tokenize_test_cpp11",
":simple_tokenize_test_cpp14",
":simple_tokenize_test_cpp17",
":token_database_fuzzer",
":token_database_test",
":tokenize_test",
]
group_deps = [
"$dir_pw_preprocessor:tests",
"$dir_pw_span:tests",
]
}
pw_test("argument_types_test") {
sources = [
"argument_types_test.cc",
"argument_types_test_c.c",
"pw_tokenizer_private/argument_types_test.h",
]
deps = [ ":pw_tokenizer" ]
if (dir_pw_third_party_arduino != "") {
remove_configs = [ "$dir_pw_build:strict_warnings" ]
}
}
pw_test("base64_test") {
sources = [ "base64_test.cc" ]
deps = [ ":base64" ]
}
pw_test("decode_test") {
sources = [
"decode_test.cc",
"pw_tokenizer_private/tokenized_string_decoding_test_data.h",
"pw_tokenizer_private/varint_decoding_test_data.h",
]
deps = [
":decoder",
"$dir_pw_varint",
]
# TODO(tonymd): This fails on Teensyduino 1.54 beta core. It may be related to
# linking in stl functions. Will debug when 1.54 is released.
enable_if = pw_build_EXECUTABLE_TARGET_TYPE != "arduino_executable"
}
pw_test("detokenize_test") {
sources = [ "detokenize_test.cc" ]
deps = [ ":decoder" ]
# TODO(tonymd): This fails on Teensyduino 1.54 beta core. It may be related to
# linking in stl functions. Will debug when 1.54 is released.
enable_if = pw_build_EXECUTABLE_TARGET_TYPE != "arduino_executable"
}
pw_test("global_handlers_test") {
sources = [
"global_handlers_test.cc",
"global_handlers_test_c.c",
"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",
"pw_tokenizer_private/generated_hash_test_cases.h",
]
deps = [ ":pw_tokenizer" ]
}
# Fully test C++11 and C++14 compatibility by compiling all sources as C++11 or
# C++14.
_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/hash.h",
"public/pw_tokenizer/internal/argument_types.h",
"public/pw_tokenizer/internal/argument_types_macro_4_byte.h",
"public/pw_tokenizer/internal/argument_types_macro_8_byte.h",
"public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_128_hash_macro.h",
"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",
"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 = [
":public_include_path",
"$dir_pw_varint:default_config",
]
pw_test("simple_tokenize_test_cpp11") {
remove_configs = [ "$dir_pw_build:cpp17" ]
configs = [ "$dir_pw_build:cpp11" ] + _simple_tokenize_test_configs
sources = _simple_tokenize_test_sources
deps = [ dir_pw_preprocessor ]
}
pw_test("simple_tokenize_test_cpp14") {
remove_configs = [ "$dir_pw_build:cpp17" ]
configs = [ "$dir_pw_build:cpp14" ] + _simple_tokenize_test_configs
sources = _simple_tokenize_test_sources
deps = [ dir_pw_preprocessor ]
}
pw_test("simple_tokenize_test_cpp17") {
configs = _simple_tokenize_test_configs
sources = _simple_tokenize_test_sources
deps = [ dir_pw_preprocessor ]
}
pw_test("token_database_test") {
sources = [ "token_database_test.cc" ]
deps = [ ":decoder" ]
}
pw_test("tokenize_test") {
sources = [
"pw_tokenizer_private/tokenize_test.h",
"tokenize_test.cc",
"tokenize_test_c.c",
]
deps = [
":pw_tokenizer",
"$dir_pw_varint",
]
}
pw_fuzzer("token_database_fuzzer") {
sources = [ "token_database_fuzzer.cc" ]
deps = [
":decoder",
"$dir_pw_fuzzer",
"$dir_pw_preprocessor",
"$dir_pw_span",
]
}
pw_fuzzer("detokenize_fuzzer") {
sources = [ "detokenize_fuzzer.cc" ]
deps = [
":decoder",
"$dir_pw_fuzzer",
"$dir_pw_preprocessor",
]
}
declare_args() {
# pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS specifies the paths to use for
# building Java Native Interface libraries. If no paths are provided, targets
# that require JNI may not build correctly.
#
# Example JNI include paths for a Linux system:
#
# pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS = [
# "/usr/local/buildtools/java/jdk/include/",
# "/usr/local/buildtools/java/jdk/include/linux",
# ]
#
pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS = []
}
# Create a shared library for the tokenizer JNI wrapper. The include paths for
# the JNI headers must be available in the system or provided with the
# pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS variable.
pw_shared_library("detokenizer_jni") {
public_configs = [ ":public_include_path" ]
include_dirs = pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS
sources = [ "java/dev/pigweed/tokenizer/detokenizer.cc" ]
public_deps = [
":decoder",
"$dir_pw_preprocessor",
]
}
pw_doc_group("docs") {
sources = [ "docs.rst" ]
inputs = [ "py/pw_tokenizer/encode.py" ]
}