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" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 EXPECT_EQ(1u, b_inherited.size()); | 218 EXPECT_EQ(1u, b_inherited.size()); |
219 EXPECT_TRUE(b_inherited.IndexOf(&c) != static_cast<size_t>(-1)); | 219 EXPECT_TRUE(b_inherited.IndexOf(&c) != static_cast<size_t>(-1)); |
220 | 220 |
221 // A should have B in its inherited libs, but not any others (the complete | 221 // A should have B in its inherited libs, but not any others (the complete |
222 // static library will include the source set). | 222 // static library will include the source set). |
223 const UniqueVector<const Target*>& a_inherited = a.inherited_libraries(); | 223 const UniqueVector<const Target*>& a_inherited = a.inherited_libraries(); |
224 EXPECT_EQ(1u, a_inherited.size()); | 224 EXPECT_EQ(1u, a_inherited.size()); |
225 EXPECT_TRUE(a_inherited.IndexOf(&b) != static_cast<size_t>(-1)); | 225 EXPECT_TRUE(a_inherited.IndexOf(&b) != static_cast<size_t>(-1)); |
226 } | 226 } |
227 | 227 |
| 228 TEST(Target, InheritCompleteStaticLibNoDirectStaticLibDeps) { |
| 229 TestWithScope setup; |
| 230 Err err; |
| 231 |
| 232 // Create a dependency chain: |
| 233 // A (complete static lib) -> B (static lib) |
| 234 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); |
| 235 a.set_output_type(Target::STATIC_LIBRARY); |
| 236 a.visibility().SetPublic(); |
| 237 a.set_complete_static_lib(true); |
| 238 a.SetToolchain(setup.toolchain()); |
| 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 |
| 244 a.public_deps().push_back(LabelTargetPair(&b)); |
| 245 ASSERT_TRUE(b.OnResolved(&err)); |
| 246 ASSERT_FALSE(a.OnResolved(&err)); |
| 247 } |
| 248 |
| 249 TEST(Target, InheritCompleteStaticLibNoIheritedStaticLibDeps) { |
| 250 TestWithScope setup; |
| 251 Err err; |
| 252 |
| 253 // Create a dependency chain: |
| 254 // A (complete static lib) -> B (source set) -> C (static lib) |
| 255 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); |
| 256 a.set_output_type(Target::STATIC_LIBRARY); |
| 257 a.visibility().SetPublic(); |
| 258 a.set_complete_static_lib(true); |
| 259 a.SetToolchain(setup.toolchain()); |
| 260 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); |
| 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 |
| 269 a.public_deps().push_back(LabelTargetPair(&b)); |
| 270 b.public_deps().push_back(LabelTargetPair(&c)); |
| 271 |
| 272 ASSERT_TRUE(c.OnResolved(&err)); |
| 273 ASSERT_TRUE(b.OnResolved(&err)); |
| 274 ASSERT_FALSE(a.OnResolved(&err)); |
| 275 } |
| 276 |
228 TEST(Target, GetComputedOutputName) { | 277 TEST(Target, GetComputedOutputName) { |
229 TestWithScope setup; | 278 TestWithScope setup; |
230 Err err; | 279 Err err; |
231 | 280 |
232 // Basic target with no prefix (executable type tool in the TestWithScope has | 281 // Basic target with no prefix (executable type tool in the TestWithScope has |
233 // no prefix) or output name. | 282 // no prefix) or output name. |
234 Target basic(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 283 Target basic(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
235 basic.set_output_type(Target::EXECUTABLE); | 284 basic.set_output_type(Target::EXECUTABLE); |
236 basic.SetToolchain(setup.toolchain()); | 285 basic.SetToolchain(setup.toolchain()); |
237 ASSERT_TRUE(basic.OnResolved(&err)); | 286 ASSERT_TRUE(basic.OnResolved(&err)); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 // Depending on the forward target should apply the config. | 472 // Depending on the forward target should apply the config. |
424 Target dep_on_forward(setup.settings(), Label(SourceDir("//a/"), "dof")); | 473 Target dep_on_forward(setup.settings(), Label(SourceDir("//a/"), "dof")); |
425 dep_on_forward.set_output_type(Target::SOURCE_SET); | 474 dep_on_forward.set_output_type(Target::SOURCE_SET); |
426 dep_on_forward.visibility().SetPublic(); | 475 dep_on_forward.visibility().SetPublic(); |
427 dep_on_forward.SetToolchain(setup.toolchain()); | 476 dep_on_forward.SetToolchain(setup.toolchain()); |
428 dep_on_forward.private_deps().push_back(LabelTargetPair(&forward)); | 477 dep_on_forward.private_deps().push_back(LabelTargetPair(&forward)); |
429 ASSERT_TRUE(dep_on_forward.OnResolved(&err)); | 478 ASSERT_TRUE(dep_on_forward.OnResolved(&err)); |
430 ASSERT_EQ(1u, dep_on_forward.configs().size()); | 479 ASSERT_EQ(1u, dep_on_forward.configs().size()); |
431 EXPECT_EQ(&pub_config, dep_on_forward.configs()[0].ptr); | 480 EXPECT_EQ(&pub_config, dep_on_forward.configs()[0].ptr); |
432 } | 481 } |
OLD | NEW |