third_party.pigweed.src/pw_build/facade.gni
Armando Montanez 04c56ae138 pw_build: Add pw_facade template
Introduces a pw_facade template that provides a useful error message
when a backend is used but not properly set. This change also changes
pigweed to build pw_docs and module tests by default.

Change-Id: Ie78a0e291782592289baa94d06fd06e493c56956
2019-12-13 11:26:08 -08:00

60 lines
1.7 KiB
Plaintext

# Copyright 2019 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("$dir_pw_build/python_script.gni")
# Declare a facade.
# A Pigweed facade is an API layer that has a single implementation it must link
# against. Typically this will be done by pointing `dir_pw_[module]_backend` at
# a backend implementation for that module.
#
# Example facade:
#
# pw_facade("module_name") {
# backend = dir_module_name_backend
# public_deps = [
# ":module_api_layer"
# ]
# }
#
# Args:
# - backend: the dependency that implements this facade
#
template("pw_facade") {
if (invoker.backend == "") {
# If backend is not set to anything, emit an error.
pw_python_script(target_name) {
stamp = true
script = "$dir_pw_build/py/null_backend.py"
args = [ target_name ]
not_needed(invoker, "*")
}
} else {
source_set(target_name) {
# If the backend is set, create a new source_set.
_ignore_vars = [
"backend",
"deps",
]
if (defined(invoker.deps)) {
deps = invoker.deps
} else {
deps = []
}
deps += [ invoker.backend ]
forward_variables_from(invoker, "*", _ignore_vars)
}
}
}