OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "tools/gn/build_settings.h" | 6 #include "tools/gn/build_settings.h" |
7 #include "tools/gn/config.h" | 7 #include "tools/gn/config.h" |
8 #include "tools/gn/settings.h" | 8 #include "tools/gn/settings.h" |
9 #include "tools/gn/target.h" | 9 #include "tools/gn/target.h" |
10 #include "tools/gn/test_with_scope.h" | 10 #include "tools/gn/test_with_scope.h" |
11 #include "tools/gn/toolchain.h" | 11 #include "tools/gn/toolchain.h" |
12 | 12 |
13 // Tests that lib[_dir]s are inherited across deps boundaries for static | 13 // Tests that lib[_dir]s are inherited across deps boundaries for static |
14 // libraries but not executables. | 14 // libraries but not executables. |
15 TEST(Target, LibInheritance) { | 15 TEST(Target, LibInheritance) { |
16 TestWithScope setup; | 16 TestWithScope setup; |
17 Err err; | 17 Err err; |
18 | 18 |
19 const std::string lib("foo"); | 19 const std::string lib("foo"); |
20 const SourceDir libdir("/foo_dir/"); | 20 const SourceDir libdir("/foo_dir/"); |
21 | 21 |
22 // Leaf target with ldflags set. | 22 // Leaf target with ldflags set. |
23 Target z(setup.settings(), Label(SourceDir("//foo/"), "z")); | 23 TestTarget z(setup, "//foo:z", Target::STATIC_LIBRARY); |
24 z.set_output_type(Target::STATIC_LIBRARY); | |
25 z.config_values().libs().push_back(lib); | 24 z.config_values().libs().push_back(lib); |
26 z.config_values().lib_dirs().push_back(libdir); | 25 z.config_values().lib_dirs().push_back(libdir); |
27 z.visibility().SetPublic(); | |
28 z.SetToolchain(setup.toolchain()); | |
29 ASSERT_TRUE(z.OnResolved(&err)); | 26 ASSERT_TRUE(z.OnResolved(&err)); |
30 | 27 |
31 // All lib[_dir]s should be set when target is resolved. | 28 // All lib[_dir]s should be set when target is resolved. |
32 ASSERT_EQ(1u, z.all_libs().size()); | 29 ASSERT_EQ(1u, z.all_libs().size()); |
33 EXPECT_EQ(lib, z.all_libs()[0]); | 30 EXPECT_EQ(lib, z.all_libs()[0]); |
34 ASSERT_EQ(1u, z.all_lib_dirs().size()); | 31 ASSERT_EQ(1u, z.all_lib_dirs().size()); |
35 EXPECT_EQ(libdir, z.all_lib_dirs()[0]); | 32 EXPECT_EQ(libdir, z.all_lib_dirs()[0]); |
36 | 33 |
37 // Shared library target should inherit the libs from the static library | 34 // Shared library target should inherit the libs from the static library |
38 // and its own. Its own flag should be before the inherited one. | 35 // and its own. Its own flag should be before the inherited one. |
39 const std::string second_lib("bar"); | 36 const std::string second_lib("bar"); |
40 const SourceDir second_libdir("/bar_dir/"); | 37 const SourceDir second_libdir("/bar_dir/"); |
41 Target shared(setup.settings(), Label(SourceDir("//foo/"), "shared")); | 38 TestTarget shared(setup, "//foo:shared", Target::SHARED_LIBRARY); |
42 shared.set_output_type(Target::SHARED_LIBRARY); | |
43 shared.config_values().libs().push_back(second_lib); | 39 shared.config_values().libs().push_back(second_lib); |
44 shared.config_values().lib_dirs().push_back(second_libdir); | 40 shared.config_values().lib_dirs().push_back(second_libdir); |
45 shared.private_deps().push_back(LabelTargetPair(&z)); | 41 shared.private_deps().push_back(LabelTargetPair(&z)); |
46 shared.visibility().SetPublic(); | |
47 shared.SetToolchain(setup.toolchain()); | |
48 ASSERT_TRUE(shared.OnResolved(&err)); | 42 ASSERT_TRUE(shared.OnResolved(&err)); |
49 | 43 |
50 ASSERT_EQ(2u, shared.all_libs().size()); | 44 ASSERT_EQ(2u, shared.all_libs().size()); |
51 EXPECT_EQ(second_lib, shared.all_libs()[0]); | 45 EXPECT_EQ(second_lib, shared.all_libs()[0]); |
52 EXPECT_EQ(lib, shared.all_libs()[1]); | 46 EXPECT_EQ(lib, shared.all_libs()[1]); |
53 ASSERT_EQ(2u, shared.all_lib_dirs().size()); | 47 ASSERT_EQ(2u, shared.all_lib_dirs().size()); |
54 EXPECT_EQ(second_libdir, shared.all_lib_dirs()[0]); | 48 EXPECT_EQ(second_libdir, shared.all_lib_dirs()[0]); |
55 EXPECT_EQ(libdir, shared.all_lib_dirs()[1]); | 49 EXPECT_EQ(libdir, shared.all_lib_dirs()[1]); |
56 | 50 |
57 // Executable target shouldn't get either by depending on shared. | 51 // Executable target shouldn't get either by depending on shared. |
58 Target exec(setup.settings(), Label(SourceDir("//foo/"), "exec")); | 52 TestTarget exec(setup, "//foo:exec", Target::EXECUTABLE); |
59 exec.set_output_type(Target::EXECUTABLE); | |
60 exec.private_deps().push_back(LabelTargetPair(&shared)); | 53 exec.private_deps().push_back(LabelTargetPair(&shared)); |
61 exec.SetToolchain(setup.toolchain()); | |
62 ASSERT_TRUE(exec.OnResolved(&err)); | 54 ASSERT_TRUE(exec.OnResolved(&err)); |
63 EXPECT_EQ(0u, exec.all_libs().size()); | 55 EXPECT_EQ(0u, exec.all_libs().size()); |
64 EXPECT_EQ(0u, exec.all_lib_dirs().size()); | 56 EXPECT_EQ(0u, exec.all_lib_dirs().size()); |
65 } | 57 } |
66 | 58 |
67 // Test all_dependent_configs, public_config inheritance, and | 59 // Test all_dependent_configs, public_config inheritance, and |
68 // forward_dependent_configs_from | 60 // forward_dependent_configs_from |
69 TEST(Target, DependentConfigs) { | 61 TEST(Target, DependentConfigs) { |
70 TestWithScope setup; | 62 TestWithScope setup; |
71 Err err; | 63 Err err; |
72 | 64 |
73 // Set up a dependency chain of a -> b -> c | 65 // Set up a dependency chain of a -> b -> c |
74 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); | 66 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
75 a.set_output_type(Target::EXECUTABLE); | 67 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); |
76 a.visibility().SetPublic(); | 68 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); |
77 a.SetToolchain(setup.toolchain()); | |
78 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); | |
79 b.set_output_type(Target::STATIC_LIBRARY); | |
80 b.visibility().SetPublic(); | |
81 b.SetToolchain(setup.toolchain()); | |
82 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); | |
83 c.set_output_type(Target::STATIC_LIBRARY); | |
84 c.visibility().SetPublic(); | |
85 c.SetToolchain(setup.toolchain()); | |
86 a.private_deps().push_back(LabelTargetPair(&b)); | 69 a.private_deps().push_back(LabelTargetPair(&b)); |
87 b.private_deps().push_back(LabelTargetPair(&c)); | 70 b.private_deps().push_back(LabelTargetPair(&c)); |
88 | 71 |
89 // Normal non-inherited config. | 72 // Normal non-inherited config. |
90 Config config(setup.settings(), Label(SourceDir("//foo/"), "config")); | 73 Config config(setup.settings(), Label(SourceDir("//foo/"), "config")); |
91 c.configs().push_back(LabelConfigPair(&config)); | 74 c.configs().push_back(LabelConfigPair(&config)); |
92 | 75 |
93 // All dependent config. | 76 // All dependent config. |
94 Config all(setup.settings(), Label(SourceDir("//foo/"), "all")); | 77 Config all(setup.settings(), Label(SourceDir("//foo/"), "all")); |
95 c.all_dependent_configs().push_back(LabelConfigPair(&all)); | 78 c.all_dependent_configs().push_back(LabelConfigPair(&all)); |
(...skipping 12 matching lines...) Expand all Loading... | |
108 EXPECT_EQ(&direct, b.configs()[1].ptr); | 91 EXPECT_EQ(&direct, b.configs()[1].ptr); |
109 ASSERT_EQ(1u, b.all_dependent_configs().size()); | 92 ASSERT_EQ(1u, b.all_dependent_configs().size()); |
110 EXPECT_EQ(&all, b.all_dependent_configs()[0].ptr); | 93 EXPECT_EQ(&all, b.all_dependent_configs()[0].ptr); |
111 | 94 |
112 // A should have just gotten the "all" dependent config from C. | 95 // A should have just gotten the "all" dependent config from C. |
113 ASSERT_EQ(1u, a.configs().size()); | 96 ASSERT_EQ(1u, a.configs().size()); |
114 EXPECT_EQ(&all, a.configs()[0].ptr); | 97 EXPECT_EQ(&all, a.configs()[0].ptr); |
115 EXPECT_EQ(&all, a.all_dependent_configs()[0].ptr); | 98 EXPECT_EQ(&all, a.all_dependent_configs()[0].ptr); |
116 | 99 |
117 // Making an an alternate A and B with B forwarding the direct dependents. | 100 // Making an an alternate A and B with B forwarding the direct dependents. |
118 Target a_fwd(setup.settings(), Label(SourceDir("//foo/"), "a_fwd")); | 101 TestTarget a_fwd(setup, "//foo:a_fwd", Target::EXECUTABLE); |
119 a_fwd.set_output_type(Target::EXECUTABLE); | 102 TestTarget b_fwd(setup, "//foo:b_fwd", Target::STATIC_LIBRARY); |
120 a_fwd.visibility().SetPublic(); | |
121 a_fwd.SetToolchain(setup.toolchain()); | |
122 Target b_fwd(setup.settings(), Label(SourceDir("//foo/"), "b_fwd")); | |
123 b_fwd.set_output_type(Target::STATIC_LIBRARY); | |
124 b_fwd.SetToolchain(setup.toolchain()); | |
125 b_fwd.visibility().SetPublic(); | |
126 a_fwd.private_deps().push_back(LabelTargetPair(&b_fwd)); | 103 a_fwd.private_deps().push_back(LabelTargetPair(&b_fwd)); |
127 b_fwd.private_deps().push_back(LabelTargetPair(&c)); | 104 b_fwd.private_deps().push_back(LabelTargetPair(&c)); |
128 b_fwd.forward_dependent_configs().push_back(LabelTargetPair(&c)); | 105 b_fwd.forward_dependent_configs().push_back(LabelTargetPair(&c)); |
129 | 106 |
130 ASSERT_TRUE(b_fwd.OnResolved(&err)); | 107 ASSERT_TRUE(b_fwd.OnResolved(&err)); |
131 ASSERT_TRUE(a_fwd.OnResolved(&err)); | 108 ASSERT_TRUE(a_fwd.OnResolved(&err)); |
132 | 109 |
133 // A_fwd should now have both configs. | 110 // A_fwd should now have both configs. |
134 ASSERT_EQ(2u, a_fwd.configs().size()); | 111 ASSERT_EQ(2u, a_fwd.configs().size()); |
135 EXPECT_EQ(&all, a_fwd.configs()[0].ptr); | 112 EXPECT_EQ(&all, a_fwd.configs()[0].ptr); |
136 EXPECT_EQ(&direct, a_fwd.configs()[1].ptr); | 113 EXPECT_EQ(&direct, a_fwd.configs()[1].ptr); |
137 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); | 114 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); |
138 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); | 115 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); |
139 } | 116 } |
140 | 117 |
141 TEST(Target, InheritLibs) { | 118 TEST(Target, InheritLibs) { |
142 TestWithScope setup; | 119 TestWithScope setup; |
143 Err err; | 120 Err err; |
144 | 121 |
145 // Create a dependency chain: | 122 // Create a dependency chain: |
146 // A (executable) -> B (shared lib) -> C (static lib) -> D (source set) | 123 // A (executable) -> B (shared lib) -> C (static lib) -> D (source set) |
147 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); | 124 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
148 a.set_output_type(Target::EXECUTABLE); | 125 TestTarget b(setup, "//foo:b", Target::SHARED_LIBRARY); |
149 a.visibility().SetPublic(); | 126 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); |
150 a.SetToolchain(setup.toolchain()); | 127 TestTarget d(setup, "//foo:d", Target::SOURCE_SET); |
151 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); | |
152 b.set_output_type(Target::SHARED_LIBRARY); | |
153 b.visibility().SetPublic(); | |
154 b.SetToolchain(setup.toolchain()); | |
155 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); | |
156 c.set_output_type(Target::STATIC_LIBRARY); | |
157 c.visibility().SetPublic(); | |
158 c.SetToolchain(setup.toolchain()); | |
159 Target d(setup.settings(), Label(SourceDir("//foo/"), "d")); | |
160 d.set_output_type(Target::SOURCE_SET); | |
161 d.visibility().SetPublic(); | |
162 d.SetToolchain(setup.toolchain()); | |
163 a.private_deps().push_back(LabelTargetPair(&b)); | 128 a.private_deps().push_back(LabelTargetPair(&b)); |
164 b.private_deps().push_back(LabelTargetPair(&c)); | 129 b.private_deps().push_back(LabelTargetPair(&c)); |
165 c.private_deps().push_back(LabelTargetPair(&d)); | 130 c.private_deps().push_back(LabelTargetPair(&d)); |
166 | 131 |
167 ASSERT_TRUE(d.OnResolved(&err)); | 132 ASSERT_TRUE(d.OnResolved(&err)); |
168 ASSERT_TRUE(c.OnResolved(&err)); | 133 ASSERT_TRUE(c.OnResolved(&err)); |
169 ASSERT_TRUE(b.OnResolved(&err)); | 134 ASSERT_TRUE(b.OnResolved(&err)); |
170 ASSERT_TRUE(a.OnResolved(&err)); | 135 ASSERT_TRUE(a.OnResolved(&err)); |
171 | 136 |
172 // C should have D in its inherited libs. | 137 // C should have D in its inherited libs. |
(...skipping 13 matching lines...) Expand all Loading... | |
186 ASSERT_EQ(1u, a_inherited.size()); | 151 ASSERT_EQ(1u, a_inherited.size()); |
187 EXPECT_EQ(&b, a_inherited[0]); | 152 EXPECT_EQ(&b, a_inherited[0]); |
188 } | 153 } |
189 | 154 |
190 TEST(Target, InheritCompleteStaticLib) { | 155 TEST(Target, InheritCompleteStaticLib) { |
191 TestWithScope setup; | 156 TestWithScope setup; |
192 Err err; | 157 Err err; |
193 | 158 |
194 // Create a dependency chain: | 159 // Create a dependency chain: |
195 // A (executable) -> B (complete static lib) -> C (source set) | 160 // A (executable) -> B (complete static lib) -> C (source set) |
196 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); | 161 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
197 a.set_output_type(Target::EXECUTABLE); | 162 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); |
198 a.visibility().SetPublic(); | |
199 a.SetToolchain(setup.toolchain()); | |
200 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); | |
201 b.set_output_type(Target::STATIC_LIBRARY); | |
202 b.visibility().SetPublic(); | |
203 b.set_complete_static_lib(true); | 163 b.set_complete_static_lib(true); |
204 b.SetToolchain(setup.toolchain()); | 164 TestTarget c(setup, "//foo:c", Target::SOURCE_SET); |
205 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); | |
206 c.set_output_type(Target::SOURCE_SET); | |
207 c.visibility().SetPublic(); | |
208 c.SetToolchain(setup.toolchain()); | |
209 a.public_deps().push_back(LabelTargetPair(&b)); | 165 a.public_deps().push_back(LabelTargetPair(&b)); |
210 b.public_deps().push_back(LabelTargetPair(&c)); | 166 b.public_deps().push_back(LabelTargetPair(&c)); |
211 | 167 |
212 ASSERT_TRUE(c.OnResolved(&err)); | 168 ASSERT_TRUE(c.OnResolved(&err)); |
213 ASSERT_TRUE(b.OnResolved(&err)); | 169 ASSERT_TRUE(b.OnResolved(&err)); |
214 ASSERT_TRUE(a.OnResolved(&err)); | 170 ASSERT_TRUE(a.OnResolved(&err)); |
215 | 171 |
216 // B should have C in its inherited libs. | 172 // B should have C in its inherited libs. |
217 std::vector<const Target*> b_inherited = b.inherited_libraries().GetOrdered(); | 173 std::vector<const Target*> b_inherited = b.inherited_libraries().GetOrdered(); |
218 ASSERT_EQ(1u, b_inherited.size()); | 174 ASSERT_EQ(1u, b_inherited.size()); |
219 EXPECT_EQ(&c, b_inherited[0]); | 175 EXPECT_EQ(&c, b_inherited[0]); |
220 | 176 |
221 // A should have B in its inherited libs, but not any others (the complete | 177 // A should have B in its inherited libs, but not any others (the complete |
222 // static library will include the source set). | 178 // static library will include the source set). |
223 std::vector<const Target*> a_inherited = a.inherited_libraries().GetOrdered(); | 179 std::vector<const Target*> a_inherited = a.inherited_libraries().GetOrdered(); |
224 EXPECT_EQ(1u, a_inherited.size()); | 180 EXPECT_EQ(1u, a_inherited.size()); |
225 EXPECT_EQ(&b, a_inherited[0]); | 181 EXPECT_EQ(&b, a_inherited[0]); |
226 } | 182 } |
227 | 183 |
228 TEST(Target, InheritCompleteStaticLibNoDirectStaticLibDeps) { | 184 TEST(Target, InheritCompleteStaticLibNoDirectStaticLibDeps) { |
229 TestWithScope setup; | 185 TestWithScope setup; |
230 Err err; | 186 Err err; |
231 | 187 |
232 // Create a dependency chain: | 188 // Create a dependency chain: |
233 // A (complete static lib) -> B (static lib) | 189 // A (complete static lib) -> B (static lib) |
234 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); | 190 TestTarget a(setup, "//foo:a", Target::STATIC_LIBRARY); |
235 a.set_output_type(Target::STATIC_LIBRARY); | |
236 a.visibility().SetPublic(); | |
237 a.set_complete_static_lib(true); | 191 a.set_complete_static_lib(true); |
238 a.SetToolchain(setup.toolchain()); | 192 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); |
239 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); | |
240 b.set_output_type(Target::STATIC_LIBRARY); | |
241 b.visibility().SetPublic(); | |
242 b.SetToolchain(setup.toolchain()); | |
243 | 193 |
244 a.public_deps().push_back(LabelTargetPair(&b)); | 194 a.public_deps().push_back(LabelTargetPair(&b)); |
245 ASSERT_TRUE(b.OnResolved(&err)); | 195 ASSERT_TRUE(b.OnResolved(&err)); |
246 ASSERT_FALSE(a.OnResolved(&err)); | 196 ASSERT_FALSE(a.OnResolved(&err)); |
247 } | 197 } |
248 | 198 |
249 TEST(Target, InheritCompleteStaticLibNoIheritedStaticLibDeps) { | 199 TEST(Target, InheritCompleteStaticLibNoIheritedStaticLibDeps) { |
250 TestWithScope setup; | 200 TestWithScope setup; |
251 Err err; | 201 Err err; |
252 | 202 |
253 // Create a dependency chain: | 203 // Create a dependency chain: |
254 // A (complete static lib) -> B (source set) -> C (static lib) | 204 // A (complete static lib) -> B (source set) -> C (static lib) |
255 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); | 205 TestTarget a(setup, "//foo:a", Target::STATIC_LIBRARY); |
256 a.set_output_type(Target::STATIC_LIBRARY); | |
257 a.visibility().SetPublic(); | |
258 a.set_complete_static_lib(true); | 206 a.set_complete_static_lib(true); |
259 a.SetToolchain(setup.toolchain()); | 207 TestTarget b(setup, "//foo:b", Target::SOURCE_SET); |
260 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); | 208 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); |
261 b.set_output_type(Target::SOURCE_SET); | |
262 b.visibility().SetPublic(); | |
263 b.SetToolchain(setup.toolchain()); | |
264 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); | |
265 c.set_output_type(Target::STATIC_LIBRARY); | |
266 c.visibility().SetPublic(); | |
267 c.SetToolchain(setup.toolchain()); | |
268 | 209 |
269 a.public_deps().push_back(LabelTargetPair(&b)); | 210 a.public_deps().push_back(LabelTargetPair(&b)); |
270 b.public_deps().push_back(LabelTargetPair(&c)); | 211 b.public_deps().push_back(LabelTargetPair(&c)); |
271 | 212 |
272 ASSERT_TRUE(c.OnResolved(&err)); | 213 ASSERT_TRUE(c.OnResolved(&err)); |
273 ASSERT_TRUE(b.OnResolved(&err)); | 214 ASSERT_TRUE(b.OnResolved(&err)); |
274 ASSERT_FALSE(a.OnResolved(&err)); | 215 ASSERT_FALSE(a.OnResolved(&err)); |
275 } | 216 } |
276 | 217 |
277 TEST(Target, GetComputedOutputName) { | 218 TEST(Target, GetComputedOutputName) { |
278 TestWithScope setup; | 219 TestWithScope setup; |
279 Err err; | 220 Err err; |
280 | 221 |
281 // Basic target with no prefix (executable type tool in the TestWithScope has | 222 // Basic target with no prefix (executable type tool in the TestWithScope has |
282 // no prefix) or output name. | 223 // no prefix) or output name. |
283 Target basic(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 224 TestTarget basic(setup, "//foo:bar", Target::EXECUTABLE); |
284 basic.set_output_type(Target::EXECUTABLE); | |
285 basic.SetToolchain(setup.toolchain()); | |
286 ASSERT_TRUE(basic.OnResolved(&err)); | 225 ASSERT_TRUE(basic.OnResolved(&err)); |
287 EXPECT_EQ("bar", basic.GetComputedOutputName(false)); | 226 EXPECT_EQ("bar", basic.GetComputedOutputName(false)); |
288 EXPECT_EQ("bar", basic.GetComputedOutputName(true)); | 227 EXPECT_EQ("bar", basic.GetComputedOutputName(true)); |
289 | 228 |
290 // Target with no prefix but an output name. | 229 // Target with no prefix but an output name. |
291 Target with_name(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 230 TestTarget with_name(setup, "//foo:bar", Target::EXECUTABLE); |
292 with_name.set_output_type(Target::EXECUTABLE); | |
293 with_name.set_output_name("myoutput"); | 231 with_name.set_output_name("myoutput"); |
294 with_name.SetToolchain(setup.toolchain()); | |
295 ASSERT_TRUE(with_name.OnResolved(&err)); | 232 ASSERT_TRUE(with_name.OnResolved(&err)); |
296 EXPECT_EQ("myoutput", with_name.GetComputedOutputName(false)); | 233 EXPECT_EQ("myoutput", with_name.GetComputedOutputName(false)); |
297 EXPECT_EQ("myoutput", with_name.GetComputedOutputName(true)); | 234 EXPECT_EQ("myoutput", with_name.GetComputedOutputName(true)); |
298 | 235 |
299 // Target with a "lib" prefix (the static library tool in the TestWithScope | 236 // Target with a "lib" prefix (the static library tool in the TestWithScope |
300 // should specify a "lib" output prefix). | 237 // should specify a "lib" output prefix). |
301 Target with_prefix(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 238 TestTarget with_prefix(setup, "//foo:bar", Target::STATIC_LIBRARY); |
302 with_prefix.set_output_type(Target::STATIC_LIBRARY); | |
303 with_prefix.SetToolchain(setup.toolchain()); | |
304 ASSERT_TRUE(with_prefix.OnResolved(&err)); | 239 ASSERT_TRUE(with_prefix.OnResolved(&err)); |
305 EXPECT_EQ("bar", with_prefix.GetComputedOutputName(false)); | 240 EXPECT_EQ("bar", with_prefix.GetComputedOutputName(false)); |
306 EXPECT_EQ("libbar", with_prefix.GetComputedOutputName(true)); | 241 EXPECT_EQ("libbar", with_prefix.GetComputedOutputName(true)); |
307 | 242 |
308 // Target with a "lib" prefix that already has it applied. The prefix should | 243 // Target with a "lib" prefix that already has it applied. The prefix should |
309 // not duplicate something already in the target name. | 244 // not duplicate something already in the target name. |
310 Target dup_prefix(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 245 TestTarget dup_prefix(setup, "//foo:bar", Target::STATIC_LIBRARY); |
311 dup_prefix.set_output_type(Target::STATIC_LIBRARY); | |
312 dup_prefix.set_output_name("libbar"); | 246 dup_prefix.set_output_name("libbar"); |
313 dup_prefix.SetToolchain(setup.toolchain()); | |
314 ASSERT_TRUE(dup_prefix.OnResolved(&err)); | 247 ASSERT_TRUE(dup_prefix.OnResolved(&err)); |
315 EXPECT_EQ("libbar", dup_prefix.GetComputedOutputName(false)); | 248 EXPECT_EQ("libbar", dup_prefix.GetComputedOutputName(false)); |
316 EXPECT_EQ("libbar", dup_prefix.GetComputedOutputName(true)); | 249 EXPECT_EQ("libbar", dup_prefix.GetComputedOutputName(true)); |
317 } | 250 } |
318 | 251 |
319 // Test visibility failure case. | 252 // Test visibility failure case. |
320 TEST(Target, VisibilityFails) { | 253 TEST(Target, VisibilityFails) { |
321 TestWithScope setup; | 254 TestWithScope setup; |
322 Err err; | 255 Err err; |
323 | 256 |
324 Target b(setup.settings(), Label(SourceDir("//private/"), "b")); | 257 TestTarget b(setup, "//private:b", Target::STATIC_LIBRARY); |
325 b.set_output_type(Target::STATIC_LIBRARY); | |
326 b.SetToolchain(setup.toolchain()); | |
327 b.visibility().SetPrivate(b.label().dir()); | 258 b.visibility().SetPrivate(b.label().dir()); |
328 ASSERT_TRUE(b.OnResolved(&err)); | 259 ASSERT_TRUE(b.OnResolved(&err)); |
329 | 260 |
330 // Make a target depending on "b". The dependency must have an origin to mark | 261 // Make a target depending on "b". The dependency must have an origin to mark |
331 // it as user-set so we check visibility. This check should fail. | 262 // it as user-set so we check visibility. This check should fail. |
332 Target a(setup.settings(), Label(SourceDir("//app/"), "a")); | 263 TestTarget a(setup, "//app:a", Target::EXECUTABLE); |
333 a.set_output_type(Target::EXECUTABLE); | |
334 a.private_deps().push_back(LabelTargetPair(&b)); | 264 a.private_deps().push_back(LabelTargetPair(&b)); |
335 IdentifierNode origin; // Dummy origin. | 265 IdentifierNode origin; // Dummy origin. |
336 a.private_deps()[0].origin = &origin; | 266 a.private_deps()[0].origin = &origin; |
337 a.SetToolchain(setup.toolchain()); | |
338 ASSERT_FALSE(a.OnResolved(&err)); | 267 ASSERT_FALSE(a.OnResolved(&err)); |
339 } | 268 } |
340 | 269 |
341 // Test visibility with a single data_dep. | 270 // Test visibility with a single data_dep. |
342 TEST(Target, VisibilityDatadeps) { | 271 TEST(Target, VisibilityDatadeps) { |
343 TestWithScope setup; | 272 TestWithScope setup; |
344 Err err; | 273 Err err; |
345 | 274 |
346 Target b(setup.settings(), Label(SourceDir("//public/"), "b")); | 275 TestTarget b(setup, "//public:b", Target::STATIC_LIBRARY); |
347 b.set_output_type(Target::STATIC_LIBRARY); | |
348 b.SetToolchain(setup.toolchain()); | |
349 b.visibility().SetPublic(); | |
350 ASSERT_TRUE(b.OnResolved(&err)); | 276 ASSERT_TRUE(b.OnResolved(&err)); |
351 | 277 |
352 // Make a target depending on "b". The dependency must have an origin to mark | 278 // Make a target depending on "b". The dependency must have an origin to mark |
353 // it as user-set so we check visibility. This check should fail. | 279 // it as user-set so we check visibility. This check should fail. |
354 Target a(setup.settings(), Label(SourceDir("//app/"), "a")); | 280 TestTarget a(setup, "//app:a", Target::EXECUTABLE); |
355 a.set_output_type(Target::EXECUTABLE); | |
356 a.data_deps().push_back(LabelTargetPair(&b)); | 281 a.data_deps().push_back(LabelTargetPair(&b)); |
357 IdentifierNode origin; // Dummy origin. | 282 IdentifierNode origin; // Dummy origin. |
358 a.data_deps()[0].origin = &origin; | 283 a.data_deps()[0].origin = &origin; |
359 a.SetToolchain(setup.toolchain()); | |
360 ASSERT_TRUE(a.OnResolved(&err)) << err.help_text(); | 284 ASSERT_TRUE(a.OnResolved(&err)) << err.help_text(); |
361 } | 285 } |
362 | 286 |
363 // Tests that A -> Group -> B where the group is visible from A but B isn't, | 287 // Tests that A -> Group -> B where the group is visible from A but B isn't, |
364 // passes visibility even though the group's deps get expanded into A. | 288 // passes visibility even though the group's deps get expanded into A. |
365 TEST(Target, VisibilityGroup) { | 289 TEST(Target, VisibilityGroup) { |
366 TestWithScope setup; | 290 TestWithScope setup; |
367 Err err; | 291 Err err; |
368 | 292 |
369 IdentifierNode origin; // Dummy origin. | 293 IdentifierNode origin; // Dummy origin. |
370 | 294 |
371 // B has private visibility. This lets the group see it since the group is in | 295 // B has private visibility. This lets the group see it since the group is in |
372 // the same directory. | 296 // the same directory. |
373 Target b(setup.settings(), Label(SourceDir("//private/"), "b")); | 297 TestTarget b(setup, "//private:b", Target::STATIC_LIBRARY); |
374 b.set_output_type(Target::STATIC_LIBRARY); | |
375 b.SetToolchain(setup.toolchain()); | |
376 b.visibility().SetPrivate(b.label().dir()); | 298 b.visibility().SetPrivate(b.label().dir()); |
377 ASSERT_TRUE(b.OnResolved(&err)); | 299 ASSERT_TRUE(b.OnResolved(&err)); |
378 | 300 |
379 // The group has public visibility and depends on b. | 301 // The group has public visibility and depends on b. |
380 Target g(setup.settings(), Label(SourceDir("//private/"), "g")); | 302 TestTarget g(setup, "//private:g", Target::GROUP); |
scottmg
2015/05/14 23:04:05
"private" -> "public"?
| |
381 g.set_output_type(Target::GROUP); | |
382 g.SetToolchain(setup.toolchain()); | |
383 g.private_deps().push_back(LabelTargetPair(&b)); | 303 g.private_deps().push_back(LabelTargetPair(&b)); |
384 g.private_deps()[0].origin = &origin; | 304 g.private_deps()[0].origin = &origin; |
385 g.visibility().SetPublic(); | |
386 ASSERT_TRUE(b.OnResolved(&err)); | 305 ASSERT_TRUE(b.OnResolved(&err)); |
387 | 306 |
388 // Make a target depending on "g". This should succeed. | 307 // Make a target depending on "g". This should succeed. |
389 Target a(setup.settings(), Label(SourceDir("//app/"), "a")); | 308 TestTarget a(setup, "//app:a", Target::EXECUTABLE); |
390 a.set_output_type(Target::EXECUTABLE); | |
391 a.private_deps().push_back(LabelTargetPair(&g)); | 309 a.private_deps().push_back(LabelTargetPair(&g)); |
392 a.private_deps()[0].origin = &origin; | 310 a.private_deps()[0].origin = &origin; |
393 a.SetToolchain(setup.toolchain()); | |
394 ASSERT_TRUE(a.OnResolved(&err)); | 311 ASSERT_TRUE(a.OnResolved(&err)); |
395 } | 312 } |
396 | 313 |
397 // Verifies that only testonly targets can depend on other testonly targets. | 314 // Verifies that only testonly targets can depend on other testonly targets. |
398 // Many of the above dependency checking cases covered the non-testonly | 315 // Many of the above dependency checking cases covered the non-testonly |
399 // case. | 316 // case. |
400 TEST(Target, Testonly) { | 317 TEST(Target, Testonly) { |
401 TestWithScope setup; | 318 TestWithScope setup; |
402 Err err; | 319 Err err; |
403 | 320 |
404 // "testlib" is a test-only library. | 321 // "testlib" is a test-only library. |
405 Target testlib(setup.settings(), Label(SourceDir("//test/"), "testlib")); | 322 TestTarget testlib(setup, "//test:testlib", Target::STATIC_LIBRARY); |
406 testlib.set_testonly(true); | 323 testlib.set_testonly(true); |
407 testlib.set_output_type(Target::STATIC_LIBRARY); | |
408 testlib.visibility().SetPublic(); | |
409 testlib.SetToolchain(setup.toolchain()); | |
410 ASSERT_TRUE(testlib.OnResolved(&err)); | 324 ASSERT_TRUE(testlib.OnResolved(&err)); |
411 | 325 |
412 // "test" is a test-only executable depending on testlib, this is OK. | 326 // "test" is a test-only executable depending on testlib, this is OK. |
413 Target test(setup.settings(), Label(SourceDir("//test/"), "test")); | 327 TestTarget test(setup, "//test:test", Target::EXECUTABLE); |
414 test.set_testonly(true); | 328 test.set_testonly(true); |
415 test.set_output_type(Target::EXECUTABLE); | |
416 test.private_deps().push_back(LabelTargetPair(&testlib)); | 329 test.private_deps().push_back(LabelTargetPair(&testlib)); |
417 test.SetToolchain(setup.toolchain()); | |
418 ASSERT_TRUE(test.OnResolved(&err)); | 330 ASSERT_TRUE(test.OnResolved(&err)); |
419 | 331 |
420 // "product" is a non-test depending on testlib. This should fail. | 332 // "product" is a non-test depending on testlib. This should fail. |
421 Target product(setup.settings(), Label(SourceDir("//app/"), "product")); | 333 TestTarget product(setup, "//app:product", Target::EXECUTABLE); |
422 product.set_testonly(false); | 334 product.set_testonly(false); |
423 product.set_output_type(Target::EXECUTABLE); | |
424 product.private_deps().push_back(LabelTargetPair(&testlib)); | 335 product.private_deps().push_back(LabelTargetPair(&testlib)); |
425 product.SetToolchain(setup.toolchain()); | |
426 ASSERT_FALSE(product.OnResolved(&err)); | 336 ASSERT_FALSE(product.OnResolved(&err)); |
427 } | 337 } |
428 | 338 |
429 TEST(Target, PublicConfigs) { | 339 TEST(Target, PublicConfigs) { |
430 TestWithScope setup; | 340 TestWithScope setup; |
431 Err err; | 341 Err err; |
432 | 342 |
433 Label pub_config_label(SourceDir("//a/"), "pubconfig"); | 343 Label pub_config_label(SourceDir("//a/"), "pubconfig"); |
434 Config pub_config(setup.settings(), pub_config_label); | 344 Config pub_config(setup.settings(), pub_config_label); |
435 | 345 |
436 // This is the destination target that has a public config. | 346 // This is the destination target that has a public config. |
437 Target dest(setup.settings(), Label(SourceDir("//a/"), "a")); | 347 TestTarget dest(setup, "//a:a", Target::SOURCE_SET); |
438 dest.set_output_type(Target::SOURCE_SET); | |
439 dest.visibility().SetPublic(); | |
440 dest.SetToolchain(setup.toolchain()); | |
441 dest.public_configs().push_back(LabelConfigPair(&pub_config)); | 348 dest.public_configs().push_back(LabelConfigPair(&pub_config)); |
442 ASSERT_TRUE(dest.OnResolved(&err)); | 349 ASSERT_TRUE(dest.OnResolved(&err)); |
443 | 350 |
444 // This target has a public dependency on dest. | 351 // This target has a public dependency on dest. |
445 Target pub(setup.settings(), Label(SourceDir("//a/"), "pub")); | 352 TestTarget pub(setup, "//a:pub", Target::SOURCE_SET); |
446 pub.set_output_type(Target::SOURCE_SET); | |
447 pub.visibility().SetPublic(); | |
448 pub.SetToolchain(setup.toolchain()); | |
449 pub.public_deps().push_back(LabelTargetPair(&dest)); | 353 pub.public_deps().push_back(LabelTargetPair(&dest)); |
450 ASSERT_TRUE(pub.OnResolved(&err)); | 354 ASSERT_TRUE(pub.OnResolved(&err)); |
451 | 355 |
452 // Depending on the target with the public dependency should forward dest's | 356 // Depending on the target with the public dependency should forward dest's |
453 // to the current target. | 357 // to the current target. |
454 Target dep_on_pub(setup.settings(), Label(SourceDir("//a/"), "dop")); | 358 TestTarget dep_on_pub(setup, "//a:dop", Target::SOURCE_SET); |
455 dep_on_pub.set_output_type(Target::SOURCE_SET); | |
456 dep_on_pub.visibility().SetPublic(); | |
457 dep_on_pub.SetToolchain(setup.toolchain()); | |
458 dep_on_pub.private_deps().push_back(LabelTargetPair(&pub)); | 359 dep_on_pub.private_deps().push_back(LabelTargetPair(&pub)); |
459 ASSERT_TRUE(dep_on_pub.OnResolved(&err)); | 360 ASSERT_TRUE(dep_on_pub.OnResolved(&err)); |
460 ASSERT_EQ(1u, dep_on_pub.configs().size()); | 361 ASSERT_EQ(1u, dep_on_pub.configs().size()); |
461 EXPECT_EQ(&pub_config, dep_on_pub.configs()[0].ptr); | 362 EXPECT_EQ(&pub_config, dep_on_pub.configs()[0].ptr); |
462 | 363 |
463 // This target has a private dependency on dest for forwards configs. | 364 // This target has a private dependency on dest for forwards configs. |
464 Target forward(setup.settings(), Label(SourceDir("//a/"), "f")); | 365 TestTarget forward(setup, "//a:f", Target::SOURCE_SET); |
465 forward.set_output_type(Target::SOURCE_SET); | |
466 forward.visibility().SetPublic(); | |
467 forward.SetToolchain(setup.toolchain()); | |
468 forward.private_deps().push_back(LabelTargetPair(&dest)); | 366 forward.private_deps().push_back(LabelTargetPair(&dest)); |
469 forward.forward_dependent_configs().push_back(LabelTargetPair(&dest)); | 367 forward.forward_dependent_configs().push_back(LabelTargetPair(&dest)); |
470 ASSERT_TRUE(forward.OnResolved(&err)); | 368 ASSERT_TRUE(forward.OnResolved(&err)); |
471 | 369 |
472 // Depending on the forward target should apply the config. | 370 // Depending on the forward target should apply the config. |
473 Target dep_on_forward(setup.settings(), Label(SourceDir("//a/"), "dof")); | 371 TestTarget dep_on_forward(setup, "//a:dof", Target::SOURCE_SET); |
474 dep_on_forward.set_output_type(Target::SOURCE_SET); | |
475 dep_on_forward.visibility().SetPublic(); | |
476 dep_on_forward.SetToolchain(setup.toolchain()); | |
477 dep_on_forward.private_deps().push_back(LabelTargetPair(&forward)); | 372 dep_on_forward.private_deps().push_back(LabelTargetPair(&forward)); |
478 ASSERT_TRUE(dep_on_forward.OnResolved(&err)); | 373 ASSERT_TRUE(dep_on_forward.OnResolved(&err)); |
479 ASSERT_EQ(1u, dep_on_forward.configs().size()); | 374 ASSERT_EQ(1u, dep_on_forward.configs().size()); |
480 EXPECT_EQ(&pub_config, dep_on_forward.configs()[0].ptr); | 375 EXPECT_EQ(&pub_config, dep_on_forward.configs()[0].ptr); |
481 } | 376 } |
482 | 377 |
483 // Tests that different link/depend outputs work for solink tools. | 378 // Tests that different link/depend outputs work for solink tools. |
484 TEST(Target, LinkAndDepOutputs) { | 379 TEST(Target, LinkAndDepOutputs) { |
485 TestWithScope setup; | 380 TestWithScope setup; |
486 Err err; | 381 Err err; |
(...skipping 30 matching lines...) Expand all Loading... | |
517 EXPECT_EQ("./liba.so.TOC", target.dependency_output_file().value()); | 412 EXPECT_EQ("./liba.so.TOC", target.dependency_output_file().value()); |
518 } | 413 } |
519 | 414 |
520 // Shared libraries should be inherited across public shared liobrary | 415 // Shared libraries should be inherited across public shared liobrary |
521 // boundaries. | 416 // boundaries. |
522 TEST(Target, SharedInheritance) { | 417 TEST(Target, SharedInheritance) { |
523 TestWithScope setup; | 418 TestWithScope setup; |
524 Err err; | 419 Err err; |
525 | 420 |
526 // Create two leaf shared libraries. | 421 // Create two leaf shared libraries. |
527 Target pub(setup.settings(), Label(SourceDir("//foo/"), "pub")); | 422 TestTarget pub(setup, "//foo:pub", Target::SHARED_LIBRARY); |
528 pub.set_output_type(Target::SHARED_LIBRARY); | |
529 pub.visibility().SetPublic(); | |
530 pub.SetToolchain(setup.toolchain()); | |
531 ASSERT_TRUE(pub.OnResolved(&err)); | 423 ASSERT_TRUE(pub.OnResolved(&err)); |
532 | 424 |
533 Target priv(setup.settings(), Label(SourceDir("//foo/"), "priv")); | 425 TestTarget priv(setup, "//foo:priv", Target::SHARED_LIBRARY); |
534 priv.set_output_type(Target::SHARED_LIBRARY); | |
535 priv.visibility().SetPublic(); | |
536 priv.SetToolchain(setup.toolchain()); | |
537 ASSERT_TRUE(priv.OnResolved(&err)); | 426 ASSERT_TRUE(priv.OnResolved(&err)); |
538 | 427 |
539 // Intermediate shared library with the leaf shared libraries as | 428 // Intermediate shared library with the leaf shared libraries as |
540 // dependencies, one public, one private. | 429 // dependencies, one public, one private. |
541 Target inter(setup.settings(), Label(SourceDir("//foo/"), "inter")); | 430 TestTarget inter(setup, "//foo:inter", Target::SHARED_LIBRARY); |
542 inter.set_output_type(Target::SHARED_LIBRARY); | |
543 inter.visibility().SetPublic(); | |
544 inter.public_deps().push_back(LabelTargetPair(&pub)); | 431 inter.public_deps().push_back(LabelTargetPair(&pub)); |
545 inter.private_deps().push_back(LabelTargetPair(&priv)); | 432 inter.private_deps().push_back(LabelTargetPair(&priv)); |
546 inter.SetToolchain(setup.toolchain()); | |
547 ASSERT_TRUE(inter.OnResolved(&err)); | 433 ASSERT_TRUE(inter.OnResolved(&err)); |
548 | 434 |
549 // The intermediate shared library should have both "pub" and "priv" in its | 435 // The intermediate shared library should have both "pub" and "priv" in its |
550 // inherited libraries. | 436 // inherited libraries. |
551 std::vector<const Target*> inter_inherited = | 437 std::vector<const Target*> inter_inherited = |
552 inter.inherited_libraries().GetOrdered(); | 438 inter.inherited_libraries().GetOrdered(); |
553 ASSERT_EQ(2u, inter_inherited.size()); | 439 ASSERT_EQ(2u, inter_inherited.size()); |
554 EXPECT_EQ(&pub, inter_inherited[0]); | 440 EXPECT_EQ(&pub, inter_inherited[0]); |
555 EXPECT_EQ(&priv, inter_inherited[1]); | 441 EXPECT_EQ(&priv, inter_inherited[1]); |
556 | 442 |
557 // Make a toplevel executable target depending on the intermediate one. | 443 // Make a toplevel executable target depending on the intermediate one. |
558 Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe")); | 444 TestTarget exe(setup, "//foo:exe", Target::EXECUTABLE); |
scottmg
2015/05/14 23:04:04
confirm you meant to change this to EXECUTABLE
brettw
2015/05/14 23:21:03
Nice catch, although this type is basically random
| |
559 exe.set_output_type(Target::SHARED_LIBRARY); | |
560 exe.visibility().SetPublic(); | |
561 exe.private_deps().push_back(LabelTargetPair(&inter)); | 445 exe.private_deps().push_back(LabelTargetPair(&inter)); |
562 exe.SetToolchain(setup.toolchain()); | |
563 ASSERT_TRUE(exe.OnResolved(&err)); | 446 ASSERT_TRUE(exe.OnResolved(&err)); |
564 | 447 |
565 // The exe's inherited libraries should be "inter" (because it depended | 448 // The exe's inherited libraries should be "inter" (because it depended |
566 // directly on it) and "pub" (because inter depended publicly on it). | 449 // directly on it) and "pub" (because inter depended publicly on it). |
567 std::vector<const Target*> exe_inherited = | 450 std::vector<const Target*> exe_inherited = |
568 exe.inherited_libraries().GetOrdered(); | 451 exe.inherited_libraries().GetOrdered(); |
569 ASSERT_EQ(2u, exe_inherited.size()); | 452 ASSERT_EQ(2u, exe_inherited.size()); |
570 EXPECT_EQ(&inter, exe_inherited[0]); | 453 EXPECT_EQ(&inter, exe_inherited[0]); |
571 EXPECT_EQ(&pub, exe_inherited[1]); | 454 EXPECT_EQ(&pub, exe_inherited[1]); |
572 } | 455 } |
456 | |
457 TEST(Target, GeneratedInputs) { | |
458 TestWithScope setup; | |
459 Err err; | |
460 | |
461 SourceFile generated_file("//out/Debug/generated.cc"); | |
462 | |
463 // This target has a generated input and no dependency makes it. | |
464 TestTarget non_existant_generator(setup, "//foo:non_existant_generator", | |
scottmg
2015/05/14 23:04:04
"existant" -> "existent" in few places
| |
465 Target::EXECUTABLE); | |
466 non_existant_generator.sources().push_back(generated_file); | |
467 EXPECT_FALSE(non_existant_generator.OnResolved(&err)); | |
468 | |
469 // Make a target that generates the file. | |
470 TestTarget generator(setup, "//foo:generator", Target::ACTION); | |
471 generator.action_values().outputs() = | |
472 SubstitutionList::MakeForTest(generated_file.value().c_str()); | |
473 err = Err(); | |
474 EXPECT_TRUE(generator.OnResolved(&err)); | |
475 | |
476 // A target that depends on the generator that uses the file as a source | |
477 // should be OK. This uses a private dep (will be used later). | |
478 TestTarget existant_generator(setup, "//foo:existant_generator", | |
479 Target::SHARED_LIBRARY); | |
480 existant_generator.sources().push_back(generated_file); | |
481 existant_generator.private_deps().push_back(LabelTargetPair(&generator)); | |
482 EXPECT_TRUE(existant_generator.OnResolved(&err)) << err.message(); | |
483 | |
484 // A target that depends on the previous one should *not* be allowed to | |
485 // use the generated file, because existant_generator used private deps. | |
486 // This is: | |
487 // indirect_private --> existant_generator --[private]--> generator | |
488 TestTarget indirect_private(setup, "//foo:indirect_private", | |
489 Target::EXECUTABLE); | |
490 indirect_private.sources().push_back(generated_file); | |
491 indirect_private.public_deps().push_back( | |
492 LabelTargetPair(&existant_generator)); | |
493 EXPECT_FALSE(indirect_private.OnResolved(&err)); | |
494 | |
495 // Now make a chain like the above but with all public deps, it should be OK. | |
496 TestTarget existant_public(setup, "//foo:existant_public", | |
497 Target::SHARED_LIBRARY); | |
498 existant_public.public_deps().push_back(LabelTargetPair(&generator)); | |
499 EXPECT_TRUE(existant_public.OnResolved(&err)) << err.message(); | |
500 TestTarget indirect_public(setup, "//foo:indirect_public", | |
501 Target::EXECUTABLE); | |
502 indirect_public.sources().push_back(generated_file); | |
503 indirect_public.public_deps().push_back(LabelTargetPair(&existant_public)); | |
504 EXPECT_TRUE(indirect_public.OnResolved(&err)) << err.message(); | |
505 } | |
OLD | NEW |