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/toolchain.h" | 10 #include "tools/gn/toolchain.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 c.OnResolved(); | 192 c.OnResolved(); |
193 b.OnResolved(); | 193 b.OnResolved(); |
194 a.OnResolved(); | 194 a.OnResolved(); |
195 | 195 |
196 // The config should now be on A, and in A's direct dependent configs. | 196 // The config should now be on A, and in A's direct dependent configs. |
197 ASSERT_EQ(1u, a.configs().size()); | 197 ASSERT_EQ(1u, a.configs().size()); |
198 ASSERT_EQ(&direct, a.configs()[0].ptr); | 198 ASSERT_EQ(&direct, a.configs()[0].ptr); |
199 ASSERT_EQ(1u, a.direct_dependent_configs().size()); | 199 ASSERT_EQ(1u, a.direct_dependent_configs().size()); |
200 ASSERT_EQ(&direct, a.direct_dependent_configs()[0].ptr); | 200 ASSERT_EQ(&direct, a.direct_dependent_configs()[0].ptr); |
201 } | 201 } |
| 202 |
| 203 TEST_F(TargetTest, InheritLibs) { |
| 204 // Create a dependency chain: |
| 205 // A (executable) -> B (shared lib) -> C (static lib) -> D (source set) |
| 206 Target a(&settings_, Label(SourceDir("//foo/"), "a")); |
| 207 a.set_output_type(Target::EXECUTABLE); |
| 208 Target b(&settings_, Label(SourceDir("//foo/"), "b")); |
| 209 b.set_output_type(Target::SHARED_LIBRARY); |
| 210 Target c(&settings_, Label(SourceDir("//foo/"), "c")); |
| 211 c.set_output_type(Target::STATIC_LIBRARY); |
| 212 Target d(&settings_, Label(SourceDir("//foo/"), "d")); |
| 213 d.set_output_type(Target::SOURCE_SET); |
| 214 a.deps().push_back(LabelTargetPair(&b)); |
| 215 b.deps().push_back(LabelTargetPair(&c)); |
| 216 c.deps().push_back(LabelTargetPair(&d)); |
| 217 |
| 218 d.OnResolved(); |
| 219 c.OnResolved(); |
| 220 b.OnResolved(); |
| 221 a.OnResolved(); |
| 222 |
| 223 // C should have D in its inherited libs. |
| 224 const std::set<const Target*>& c_inherited = c.inherited_libraries(); |
| 225 EXPECT_EQ(1u, c_inherited.size()); |
| 226 EXPECT_TRUE(c_inherited.find(&d) != c_inherited.end()); |
| 227 |
| 228 // B should have C in its inherited libs, but not D (the static library will |
| 229 // include the source sets's code). |
| 230 const std::set<const Target*>& b_inherited = b.inherited_libraries(); |
| 231 EXPECT_EQ(1u, b_inherited.size()); |
| 232 EXPECT_TRUE(b_inherited.find(&c) != b_inherited.end()); |
| 233 |
| 234 // A should have B in its inherited libs, but not any others (the shared |
| 235 // library will include the static library, which will include the source |
| 236 // set). |
| 237 const std::set<const Target*>& a_inherited = a.inherited_libraries(); |
| 238 EXPECT_EQ(1u, a_inherited.size()); |
| 239 EXPECT_TRUE(a_inherited.find(&b) != a_inherited.end()); |
| 240 } |
OLD | NEW |