aboutsummaryrefslogtreecommitdiff
path: root/pw_build/facade.gni
blob: d9cd7f117caaa067911fc00528a83ab2a57cb543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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)
    }
  }
}