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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 a.private_deps().push_back(LabelTargetPair(&b)); | 163 a.private_deps().push_back(LabelTargetPair(&b)); |
164 b.private_deps().push_back(LabelTargetPair(&c)); | 164 b.private_deps().push_back(LabelTargetPair(&c)); |
165 c.private_deps().push_back(LabelTargetPair(&d)); | 165 c.private_deps().push_back(LabelTargetPair(&d)); |
166 | 166 |
167 ASSERT_TRUE(d.OnResolved(&err)); | 167 ASSERT_TRUE(d.OnResolved(&err)); |
168 ASSERT_TRUE(c.OnResolved(&err)); | 168 ASSERT_TRUE(c.OnResolved(&err)); |
169 ASSERT_TRUE(b.OnResolved(&err)); | 169 ASSERT_TRUE(b.OnResolved(&err)); |
170 ASSERT_TRUE(a.OnResolved(&err)); | 170 ASSERT_TRUE(a.OnResolved(&err)); |
171 | 171 |
172 // C should have D in its inherited libs. | 172 // C should have D in its inherited libs. |
173 const UniqueVector<const Target*>& c_inherited = c.inherited_libraries(); | 173 std::vector<const Target*> c_inherited = c.inherited_libraries().GetOrdered(); |
174 EXPECT_EQ(1u, c_inherited.size()); | 174 ASSERT_EQ(1u, c_inherited.size()); |
175 EXPECT_TRUE(c_inherited.IndexOf(&d) != static_cast<size_t>(-1)); | 175 EXPECT_EQ(&d, c_inherited[0]); |
176 | 176 |
177 // B should have C and D in its inherited libs. | 177 // B should have C and D in its inherited libs. |
178 const UniqueVector<const Target*>& b_inherited = b.inherited_libraries(); | 178 std::vector<const Target*> b_inherited = b.inherited_libraries().GetOrdered(); |
179 EXPECT_EQ(2u, b_inherited.size()); | 179 ASSERT_EQ(2u, b_inherited.size()); |
180 EXPECT_TRUE(b_inherited.IndexOf(&c) != static_cast<size_t>(-1)); | 180 EXPECT_EQ(&c, b_inherited[0]); |
181 EXPECT_TRUE(b_inherited.IndexOf(&d) != static_cast<size_t>(-1)); | 181 EXPECT_EQ(&d, b_inherited[1]); |
182 | 182 |
183 // A should have B in its inherited libs, but not any others (the shared | 183 // A should have B in its inherited libs, but not any others (the shared |
184 // library will include the static library and source set). | 184 // library will include the static library and source set). |
185 const UniqueVector<const Target*>& a_inherited = a.inherited_libraries(); | 185 std::vector<const Target*> a_inherited = a.inherited_libraries().GetOrdered(); |
186 EXPECT_EQ(1u, a_inherited.size()); | 186 ASSERT_EQ(1u, a_inherited.size()); |
187 EXPECT_TRUE(a_inherited.IndexOf(&b) != static_cast<size_t>(-1)); | 187 EXPECT_EQ(&b, a_inherited[0]); |
188 } | 188 } |
189 | 189 |
190 TEST(Target, InheritCompleteStaticLib) { | 190 TEST(Target, InheritCompleteStaticLib) { |
191 TestWithScope setup; | 191 TestWithScope setup; |
192 Err err; | 192 Err err; |
193 | 193 |
194 // Create a dependency chain: | 194 // Create a dependency chain: |
195 // A (executable) -> B (complete static lib) -> C (source set) | 195 // A (executable) -> B (complete static lib) -> C (source set) |
196 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); | 196 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); |
197 a.set_output_type(Target::EXECUTABLE); | 197 a.set_output_type(Target::EXECUTABLE); |
198 a.visibility().SetPublic(); | 198 a.visibility().SetPublic(); |
199 a.SetToolchain(setup.toolchain()); | 199 a.SetToolchain(setup.toolchain()); |
200 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); | 200 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); |
201 b.set_output_type(Target::STATIC_LIBRARY); | 201 b.set_output_type(Target::STATIC_LIBRARY); |
202 b.visibility().SetPublic(); | 202 b.visibility().SetPublic(); |
203 b.set_complete_static_lib(true); | 203 b.set_complete_static_lib(true); |
204 b.SetToolchain(setup.toolchain()); | 204 b.SetToolchain(setup.toolchain()); |
205 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); | 205 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); |
206 c.set_output_type(Target::SOURCE_SET); | 206 c.set_output_type(Target::SOURCE_SET); |
207 c.visibility().SetPublic(); | 207 c.visibility().SetPublic(); |
208 c.SetToolchain(setup.toolchain()); | 208 c.SetToolchain(setup.toolchain()); |
209 a.public_deps().push_back(LabelTargetPair(&b)); | 209 a.public_deps().push_back(LabelTargetPair(&b)); |
210 b.public_deps().push_back(LabelTargetPair(&c)); | 210 b.public_deps().push_back(LabelTargetPair(&c)); |
211 | 211 |
212 ASSERT_TRUE(c.OnResolved(&err)); | 212 ASSERT_TRUE(c.OnResolved(&err)); |
213 ASSERT_TRUE(b.OnResolved(&err)); | 213 ASSERT_TRUE(b.OnResolved(&err)); |
214 ASSERT_TRUE(a.OnResolved(&err)); | 214 ASSERT_TRUE(a.OnResolved(&err)); |
215 | 215 |
216 // B should have C in its inherited libs. | 216 // B should have C in its inherited libs. |
217 const UniqueVector<const Target*>& b_inherited = b.inherited_libraries(); | 217 std::vector<const Target*> b_inherited = b.inherited_libraries().GetOrdered(); |
218 EXPECT_EQ(1u, b_inherited.size()); | 218 ASSERT_EQ(1u, b_inherited.size()); |
219 EXPECT_TRUE(b_inherited.IndexOf(&c) != static_cast<size_t>(-1)); | 219 EXPECT_EQ(&c, b_inherited[0]); |
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 std::vector<const Target*> a_inherited = a.inherited_libraries().GetOrdered(); |
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_EQ(&b, a_inherited[0]); |
226 } | 226 } |
227 | 227 |
228 TEST(Target, InheritCompleteStaticLibNoDirectStaticLibDeps) { | 228 TEST(Target, InheritCompleteStaticLibNoDirectStaticLibDeps) { |
229 TestWithScope setup; | 229 TestWithScope setup; |
230 Err err; | 230 Err err; |
231 | 231 |
232 // Create a dependency chain: | 232 // Create a dependency chain: |
233 // A (complete static lib) -> B (static lib) | 233 // A (complete static lib) -> B (static lib) |
234 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); | 234 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); |
235 a.set_output_type(Target::STATIC_LIBRARY); | 235 a.set_output_type(Target::STATIC_LIBRARY); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 toolchain.SetTool(Toolchain::TYPE_SOLINK, solink_tool.Pass()); | 509 toolchain.SetTool(Toolchain::TYPE_SOLINK, solink_tool.Pass()); |
510 | 510 |
511 Target target(setup.settings(), Label(SourceDir("//a/"), "a")); | 511 Target target(setup.settings(), Label(SourceDir("//a/"), "a")); |
512 target.set_output_type(Target::SHARED_LIBRARY); | 512 target.set_output_type(Target::SHARED_LIBRARY); |
513 target.SetToolchain(&toolchain); | 513 target.SetToolchain(&toolchain); |
514 ASSERT_TRUE(target.OnResolved(&err)); | 514 ASSERT_TRUE(target.OnResolved(&err)); |
515 | 515 |
516 EXPECT_EQ("./liba.so", target.link_output_file().value()); | 516 EXPECT_EQ("./liba.so", target.link_output_file().value()); |
517 EXPECT_EQ("./liba.so.TOC", target.dependency_output_file().value()); | 517 EXPECT_EQ("./liba.so.TOC", target.dependency_output_file().value()); |
518 } | 518 } |
| 519 |
| 520 // Shared libraries should be inherited across public shared liobrary |
| 521 // boundaries. |
| 522 TEST(Target, SharedInheritance) { |
| 523 TestWithScope setup; |
| 524 Err err; |
| 525 |
| 526 // Create two leaf shared libraries. |
| 527 Target pub(setup.settings(), Label(SourceDir("//foo/"), "pub")); |
| 528 pub.set_output_type(Target::SHARED_LIBRARY); |
| 529 pub.visibility().SetPublic(); |
| 530 pub.SetToolchain(setup.toolchain()); |
| 531 ASSERT_TRUE(pub.OnResolved(&err)); |
| 532 |
| 533 Target priv(setup.settings(), Label(SourceDir("//foo/"), "priv")); |
| 534 priv.set_output_type(Target::SHARED_LIBRARY); |
| 535 priv.visibility().SetPublic(); |
| 536 priv.SetToolchain(setup.toolchain()); |
| 537 ASSERT_TRUE(priv.OnResolved(&err)); |
| 538 |
| 539 // Intermediate shared library with the leaf shared libraries as |
| 540 // dependencies, one public, one private. |
| 541 Target inter(setup.settings(), Label(SourceDir("//foo/"), "inter")); |
| 542 inter.set_output_type(Target::SHARED_LIBRARY); |
| 543 inter.visibility().SetPublic(); |
| 544 inter.public_deps().push_back(LabelTargetPair(&pub)); |
| 545 inter.private_deps().push_back(LabelTargetPair(&priv)); |
| 546 inter.SetToolchain(setup.toolchain()); |
| 547 ASSERT_TRUE(inter.OnResolved(&err)); |
| 548 |
| 549 // The intermediate shared library should have both "pub" and "priv" in its |
| 550 // inherited libraries. |
| 551 std::vector<const Target*> inter_inherited = |
| 552 inter.inherited_libraries().GetOrdered(); |
| 553 ASSERT_EQ(2u, inter_inherited.size()); |
| 554 EXPECT_EQ(&pub, inter_inherited[0]); |
| 555 EXPECT_EQ(&priv, inter_inherited[1]); |
| 556 |
| 557 // Make a toplevel executable target depending on the intermediate one. |
| 558 Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe")); |
| 559 exe.set_output_type(Target::SHARED_LIBRARY); |
| 560 exe.visibility().SetPublic(); |
| 561 exe.private_deps().push_back(LabelTargetPair(&inter)); |
| 562 exe.SetToolchain(setup.toolchain()); |
| 563 ASSERT_TRUE(exe.OnResolved(&err)); |
| 564 |
| 565 // The exe's inherited libraries should be "inter" (because it depended |
| 566 // directly on it) and "pub" (because inter depended publicly on it). |
| 567 std::vector<const Target*> exe_inherited = |
| 568 exe.inherited_libraries().GetOrdered(); |
| 569 ASSERT_EQ(2u, exe_inherited.size()); |
| 570 EXPECT_EQ(&inter, exe_inherited[0]); |
| 571 EXPECT_EQ(&pub, exe_inherited[1]); |
| 572 } |
OLD | NEW |