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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# The absolute path to the directory containing the mojo public SDK (i.e., the
# directory containing mojo/public). The build files within the Mojo public
# SDK use this variable to allow themselves to be parameterized by the location
# of the public SDK within a client repo.
mojo_root = get_path_info("../..", "abspath")
# Takes as input a "source_set" that includes dependencies that are relative to
# the parent directory of the Mojo public SDK (given in |mojo_sdk_deps|).
# Generates a source_set that has the mojo_sdk_deps added as ordinary deps
# rebased to the current directory.
# By default, restricts the entries that are given in invoker.deps and
# invoker.public_deps to be only within the same file and on a small set of
# whitelisted external dependencies. This check can be elided by setting
# restrict_external_deps to false in the invoker. DO NOT DO THIS in
# //mojo/public.
#
# Example of a mojo_sdk_source_set:
#
# mojo_sdk_source_set("foo") {
# sources = [
# "foo.h",
# "foo.cc",
# ]
#
# # Same-file deps are specified in the ordinary way. Any external
# dependencies are specified the same way (although in general there should
# be very few of these).
# deps = [
# ":bar",
# ]
#
# # Mojo SDK deps are specified relative to the containing directory of the
# SDK via mojo_sdk_deps.
# mojo_sdk_deps = [
# "mojo/public/cpp/bindings",
# "mojo/public/cpp/environment",
# "mojo/public/cpp/system",
# ]
# }
#
template("mojo_sdk_source_set") {
source_set(target_name) {
if (defined(invoker.visibility)) {
visibility = invoker.visibility
} else {
visibility = [ "*" ]
}
if (defined(invoker.mojo_sdk_visibility)) {
foreach(sdk_target, invoker.mojo_sdk_visibility) {
# Check that the SDK target was not mistakenly given as an absolute
# path.
assert(get_path_info(sdk_target, "abspath") != sdk_target)
visibility += [ rebase_path(sdk_target, ".", mojo_root) ]
}
}
if (defined(invoker.testonly)) {
testonly = invoker.testonly
}
if (defined(invoker.sources)) {
sources = invoker.sources
}
if (defined(invoker.defines)) {
defines = invoker.defines
}
if (defined(invoker.libs)) {
libs = invoker.libs
}
public_configs =
[ rebase_path("mojo/public/build/config:mojo_sdk", ".", mojo_root) ]
if (defined(invoker.public_configs)) {
public_configs += invoker.public_configs
}
if (defined(invoker.configs)) {
configs += invoker.configs
}
if (defined(invoker.allow_circular_includes_from)) {
allow_circular_includes_from = invoker.allow_circular_includes_from
}
if (defined(invoker.public_deps) || defined(invoker.deps)) {
restrict_external_deps = true
if (defined(invoker.restrict_external_deps)) {
restrict_external_deps = invoker.restrict_external_deps
}
}
public_deps = []
if (defined(invoker.public_deps)) {
foreach(dep, invoker.public_deps) {
if (restrict_external_deps) {
# The only deps that are not specified relative to the location of
# the Mojo SDK should be on targets within the same file or on a
# whitelisted set of external dependencies.
assert(get_path_info(dep, "dir") == ".")
}
public_deps += [ dep ]
}
}
if (defined(invoker.mojo_sdk_public_deps)) {
foreach(sdk_dep, invoker.mojo_sdk_public_deps) {
# Check that the SDK dep was not mistakenly given as an absolute path.
assert(get_path_info(sdk_dep, "abspath") != sdk_dep)
public_deps += [ rebase_path(sdk_dep, ".", mojo_root) ]
}
}
deps = []
if (defined(invoker.deps)) {
foreach(dep, invoker.deps) {
if (restrict_external_deps) {
# The only deps that are not specified relative to the location of
# the Mojo SDK should be on targets within the same file or on a
# whitelisted set of external dependencies.
dep_dir = get_path_info(dep, "dir")
assert(dep_dir == "." || dep == "//testing/gtest")
}
deps += [ dep ]
}
}
if (defined(invoker.mojo_sdk_deps)) {
foreach(sdk_dep, invoker.mojo_sdk_deps) {
# Check that the SDK dep was not mistakenly given as an absolute path.
assert(get_path_info(sdk_dep, "abspath") != sdk_dep)
deps += [ rebase_path(sdk_dep, ".", mojo_root) ]
}
}
}
}
|