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_dependencies 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 public_configs = | |
74 [ rebase_path("mojo/public/build/config:mojo_sdk", ".", mojo_root) ] | |
75 if (defined(invoker.public_configs)) { | |
76 public_configs += invoker.public_configs | |
77 } | |
78 | |
79 if (defined(invoker.configs)) { | |
80 configs += invoker.configs | |
81 } | |
82 | |
83 if (defined(invoker.allow_circular_includes_from)) { | |
84 allow_circular_includes_from = invoker.allow_circular_includes_from | |
85 } | |
86 | |
87 if (defined(invoker.public_deps) || defined(invoker.deps)) { | |
88 restrict_external_deps = true | |
89 if (defined(invoker.restrict_external_deps)) { | |
90 restrict_external_deps = invoker.restrict_external_deps | |
91 } | |
92 } | |
93 | |
94 public_deps = [] | |
95 if (defined(invoker.public_deps)) { | |
96 foreach(dep, invoker.public_deps) { | |
97 if (restrict_external_deps) { | |
98 # The only deps that are not specified relative to the location of | |
99 # the Mojo SDK should be on targets within the same file or on a | |
100 # whitelisted set of external dependencies. | |
101 assert(get_path_info(dep, "dir") == ".") | |
102 } | |
103 public_deps += [ dep ] | |
104 } | |
105 } | |
106 if (defined(invoker.mojo_sdk_public_deps)) { | |
107 foreach(sdk_dep, invoker.mojo_sdk_public_deps) { | |
108 # Check that the SDK dep was not mistakenly given as an absolute path. | |
109 assert(get_path_info(sdk_dep, "abspath") != sdk_dep) | |
110 public_deps += [ rebase_path(sdk_dep, ".", mojo_root) ] | |
111 } | |
112 } | |
113 | |
114 deps = [] | |
115 if (defined(invoker.deps)) { | |
116 foreach(dep, invoker.deps) { | |
117 if (restrict_external_deps) { | |
118 # The only deps that are not specified relative to the location of | |
119 # the Mojo SDK should be on targets within the same file or on a | |
120 # whitelisted set of external dependencies. | |
121 dep_dir = get_path_info(dep, "dir") | |
122 assert(dep_dir == "." || dep == "//testing/gtest") | |
123 } | |
124 deps += [ dep ] | |
125 } | |
126 } | |
127 if (defined(invoker.mojo_sdk_deps)) { | |
128 foreach(sdk_dep, invoker.mojo_sdk_deps) { | |
129 # Check that the SDK dep was not mistakenly given as an absolute path. | |
130 assert(get_path_info(sdk_dep, "abspath") != sdk_dep) | |
131 deps += [ rebase_path(sdk_dep, ".", mojo_root) ] | |
132 } | |
133 } | |
134 } | |
135 } | |
OLD | NEW |