| 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/scheduler.h" | 8 #include "tools/gn/scheduler.h" |
| 9 #include "tools/gn/settings.h" | 9 #include "tools/gn/settings.h" |
| 10 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 // Tests that lib[_dir]s are inherited across deps boundaries for static | 32 // Tests that lib[_dir]s are inherited across deps boundaries for static |
| 33 // libraries but not executables. | 33 // libraries but not executables. |
| 34 TEST(Target, LibInheritance) { | 34 TEST(Target, LibInheritance) { |
| 35 TestWithScope setup; | 35 TestWithScope setup; |
| 36 Err err; | 36 Err err; |
| 37 | 37 |
| 38 const std::string lib("foo"); | 38 const LibFile lib("foo"); |
| 39 const SourceDir libdir("/foo_dir/"); | 39 const SourceDir libdir("/foo_dir/"); |
| 40 | 40 |
| 41 // Leaf target with ldflags set. | 41 // Leaf target with ldflags set. |
| 42 TestTarget z(setup, "//foo:z", Target::STATIC_LIBRARY); | 42 TestTarget z(setup, "//foo:z", Target::STATIC_LIBRARY); |
| 43 z.config_values().libs().push_back(lib); | 43 z.config_values().libs().push_back(lib); |
| 44 z.config_values().lib_dirs().push_back(libdir); | 44 z.config_values().lib_dirs().push_back(libdir); |
| 45 ASSERT_TRUE(z.OnResolved(&err)); | 45 ASSERT_TRUE(z.OnResolved(&err)); |
| 46 | 46 |
| 47 // All lib[_dir]s should be set when target is resolved. | 47 // All lib[_dir]s should be set when target is resolved. |
| 48 ASSERT_EQ(1u, z.all_libs().size()); | 48 ASSERT_EQ(1u, z.all_libs().size()); |
| 49 EXPECT_EQ(lib, z.all_libs()[0]); | 49 EXPECT_EQ(lib, z.all_libs()[0]); |
| 50 ASSERT_EQ(1u, z.all_lib_dirs().size()); | 50 ASSERT_EQ(1u, z.all_lib_dirs().size()); |
| 51 EXPECT_EQ(libdir, z.all_lib_dirs()[0]); | 51 EXPECT_EQ(libdir, z.all_lib_dirs()[0]); |
| 52 | 52 |
| 53 // Shared library target should inherit the libs from the static library | 53 // Shared library target should inherit the libs from the static library |
| 54 // and its own. Its own flag should be before the inherited one. | 54 // and its own. Its own flag should be before the inherited one. |
| 55 const std::string second_lib("bar"); | 55 const LibFile second_lib("bar"); |
| 56 const SourceDir second_libdir("/bar_dir/"); | 56 const SourceDir second_libdir("/bar_dir/"); |
| 57 TestTarget shared(setup, "//foo:shared", Target::SHARED_LIBRARY); | 57 TestTarget shared(setup, "//foo:shared", Target::SHARED_LIBRARY); |
| 58 shared.config_values().libs().push_back(second_lib); | 58 shared.config_values().libs().push_back(second_lib); |
| 59 shared.config_values().lib_dirs().push_back(second_libdir); | 59 shared.config_values().lib_dirs().push_back(second_libdir); |
| 60 shared.private_deps().push_back(LabelTargetPair(&z)); | 60 shared.private_deps().push_back(LabelTargetPair(&z)); |
| 61 ASSERT_TRUE(shared.OnResolved(&err)); | 61 ASSERT_TRUE(shared.OnResolved(&err)); |
| 62 | 62 |
| 63 ASSERT_EQ(2u, shared.all_libs().size()); | 63 ASSERT_EQ(2u, shared.all_libs().size()); |
| 64 EXPECT_EQ(second_lib, shared.all_libs()[0]); | 64 EXPECT_EQ(second_lib, shared.all_libs()[0]); |
| 65 EXPECT_EQ(lib, shared.all_libs()[1]); | 65 EXPECT_EQ(lib, shared.all_libs()[1]); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 product.private_deps().push_back(LabelTargetPair(&testlib)); | 379 product.private_deps().push_back(LabelTargetPair(&testlib)); |
| 380 ASSERT_FALSE(product.OnResolved(&err)); | 380 ASSERT_FALSE(product.OnResolved(&err)); |
| 381 } | 381 } |
| 382 | 382 |
| 383 TEST(Target, PublicConfigs) { | 383 TEST(Target, PublicConfigs) { |
| 384 TestWithScope setup; | 384 TestWithScope setup; |
| 385 Err err; | 385 Err err; |
| 386 | 386 |
| 387 Label pub_config_label(SourceDir("//a/"), "pubconfig"); | 387 Label pub_config_label(SourceDir("//a/"), "pubconfig"); |
| 388 Config pub_config(setup.settings(), pub_config_label); | 388 Config pub_config(setup.settings(), pub_config_label); |
| 389 std::string lib_name("testlib"); | 389 LibFile lib_name("testlib"); |
| 390 pub_config.own_values().libs().push_back(lib_name); | 390 pub_config.own_values().libs().push_back(lib_name); |
| 391 ASSERT_TRUE(pub_config.OnResolved(&err)); | 391 ASSERT_TRUE(pub_config.OnResolved(&err)); |
| 392 | 392 |
| 393 // This is the destination target that has a public config. | 393 // This is the destination target that has a public config. |
| 394 TestTarget dest(setup, "//a:a", Target::SOURCE_SET); | 394 TestTarget dest(setup, "//a:a", Target::SOURCE_SET); |
| 395 dest.public_configs().push_back(LabelConfigPair(&pub_config)); | 395 dest.public_configs().push_back(LabelConfigPair(&pub_config)); |
| 396 ASSERT_TRUE(dest.OnResolved(&err)); | 396 ASSERT_TRUE(dest.OnResolved(&err)); |
| 397 | 397 |
| 398 // This target has a public dependency on dest. | 398 // This target has a public dependency on dest. |
| 399 TestTarget pub(setup, "//a:pub", Target::SOURCE_SET); | 399 TestTarget pub(setup, "//a:pub", Target::SOURCE_SET); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 "\n" | 633 "\n" |
| 634 "From //foo:bar\n" | 634 "From //foo:bar\n" |
| 635 " header: pch.h\n" | 635 " header: pch.h\n" |
| 636 " source: //pcs.cc\n" | 636 " source: //pcs.cc\n" |
| 637 "\n" | 637 "\n" |
| 638 "From //foo:c2\n" | 638 "From //foo:c2\n" |
| 639 " header: pch2.h\n" | 639 " header: pch2.h\n" |
| 640 " source: //pcs2.cc", | 640 " source: //pcs2.cc", |
| 641 err.help_text()); | 641 err.help_text()); |
| 642 } | 642 } |
| OLD | NEW |