OLD | NEW |
| (Empty) |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 # The absolute path to the directory containing the mojo public SDK (i.e., the | |
6 # directory containing mojo/public). The build files within the Mojo public | |
7 # SDK use this variable to allow themselves to be parameterized by the location | |
8 # of the public SDK within a client repo. | |
9 mojo_root = get_path_info("../..", "abspath") | |
10 | |
11 # Takes as input a "source_set" that includes dependencies that are relative to | |
12 # the parent directory of the Mojo public SDK (given in |mojo_sdk_deps|). | |
13 # Generates a source_set that has the mojo_sdk_deps added as ordinary deps | |
14 # rebased to the current directory. | |
15 # By default, restricts the entries that are given in invoker.deps and | |
16 # invoker.public_deps to be only within the same file and on a small set of | |
17 # whitelisted external dependencies. This check can be elided by setting | |
18 # restrict_external_deps to false in the invoker. DO NOT DO THIS in | |
19 # //mojo/public. | |
20 # | |
21 # Example of a mojo_sdk_source_set: | |
22 # | |
23 # mojo_sdk_source_set("foo") { | |
24 # sources = [ | |
25 # "foo.h", | |
26 # "foo.cc", | |
27 # ] | |
28 # | |
29 # # Same-file deps are specified in the ordinary way. Any external | |
30 # dependencies are specified the same way (although in general there should | |
31 # be very few of these). | |
32 # deps = [ | |
33 # ":bar", | |
34 # ] | |
35 # | |
36 # # Mojo SDK deps are specified relative to the containing directory of the | |
37 # SDK via mojo_sdk_deps. | |
38 # mojo_sdk_deps = [ | |
39 # "mojo/public/cpp/bindings", | |
40 # "mojo/public/cpp/environment", | |
41 # "mojo/public/cpp/system", | |
42 # ] | |
43 # } | |
44 # | |
45 template("mojo_sdk_source_set") { | |
46 source_set(target_name) { | |
47 if (defined(invoker.visibility)) { | |
48 visibility = invoker.visibility | |
49 } else { | |
50 visibility = [ "*" ] | |
51 } | |
52 if (defined(invoker.mojo_sdk_visibility)) { | |
53 foreach(sdk_target, invoker.mojo_sdk_visibility) { | |
54 # Check that the SDK target was not mistakenly given as an absolute | |
55 # path. | |
56 assert(get_path_info(sdk_target, "abspath") != sdk_target) | |
57 visibility += [ rebase_path(sdk_target, ".", mojo_root) ] | |
58 } | |
59 } | |
60 | |
61 if (defined(invoker.testonly)) { | |
62 testonly = invoker.testonly | |
63 } | |
64 | |
65 if (defined(invoker.sources)) { | |
66 sources = invoker.sources | |
67 } | |
68 | |
69 if (defined(invoker.defines)) { | |
70 defines = invoker.defines | |
71 } | |
72 | |
73 if (defined(invoker.libs)) { | |
74 libs = invoker.libs | |
75 } | |
76 | |
77 public_configs = | |
78 [ rebase_path("mojo/public/build/config:mojo_sdk", ".", mojo_root) ] | |
79 if (defined(invoker.public_configs)) { | |
80 public_configs += invoker.public_configs | |
81 } | |
82 | |
83 if (defined(invoker.configs)) { | |
84 configs += invoker.configs | |
85 } | |
86 | |
87 if (defined(invoker.allow_circular_includes_from)) { | |
88 allow_circular_includes_from = invoker.allow_circular_includes_from | |
89 } | |
90 | |
91 if (defined(invoker.public_deps) || defined(invoker.deps)) { | |
92 restrict_external_deps = true | |
93 if (defined(invoker.restrict_external_deps)) { | |
94 restrict_external_deps = invoker.restrict_external_deps | |
95 } | |
96 } | |
97 | |
98 public_deps = [] | |
99 if (defined(invoker.public_deps)) { | |
100 foreach(dep, invoker.public_deps) { | |
101 if (restrict_external_deps) { | |
102 # The only deps that are not specified relative to the location of | |
103 # the Mojo SDK should be on targets within the same file or on a | |
104 # whitelisted set of external dependencies. | |
105 assert(get_path_info(dep, "dir") == ".") | |
106 } | |
107 public_deps += [ dep ] | |
108 } | |
109 } | |
110 if (defined(invoker.mojo_sdk_public_deps)) { | |
111 foreach(sdk_dep, invoker.mojo_sdk_public_deps) { | |
112 # Check that the SDK dep was not mistakenly given as an absolute path. | |
113 assert(get_path_info(sdk_dep, "abspath") != sdk_dep) | |
114 public_deps += [ rebase_path(sdk_dep, ".", mojo_root) ] | |
115 } | |
116 } | |
117 | |
118 deps = [] | |
119 if (defined(invoker.deps)) { | |
120 foreach(dep, invoker.deps) { | |
121 if (restrict_external_deps) { | |
122 # The only deps that are not specified relative to the location of | |
123 # the Mojo SDK should be on targets within the same file or on a | |
124 # whitelisted set of external dependencies. | |
125 dep_dir = get_path_info(dep, "dir") | |
126 assert(dep_dir == "." || dep == "//testing/gtest") | |
127 } | |
128 deps += [ dep ] | |
129 } | |
130 } | |
131 if (defined(invoker.mojo_sdk_deps)) { | |
132 foreach(sdk_dep, invoker.mojo_sdk_deps) { | |
133 # Check that the SDK dep was not mistakenly given as an absolute path. | |
134 assert(get_path_info(sdk_dep, "abspath") != sdk_dep) | |
135 deps += [ rebase_path(sdk_dep, ".", mojo_root) ] | |
136 } | |
137 } | |
138 } | |
139 } | |
OLD | NEW |