| 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 "tools/gn/target.h" | 5 #include "tools/gn/target.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 176 |
| 177 TEST(Target, InheritCompleteStaticLib) { | 177 TEST(Target, InheritCompleteStaticLib) { |
| 178 TestWithScope setup; | 178 TestWithScope setup; |
| 179 Err err; | 179 Err err; |
| 180 | 180 |
| 181 // Create a dependency chain: | 181 // Create a dependency chain: |
| 182 // A (executable) -> B (complete static lib) -> C (source set) | 182 // A (executable) -> B (complete static lib) -> C (source set) |
| 183 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); | 183 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
| 184 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); | 184 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); |
| 185 b.set_complete_static_lib(true); | 185 b.set_complete_static_lib(true); |
| 186 |
| 187 const LibFile lib("foo"); |
| 188 const SourceDir lib_dir("/foo_dir/"); |
| 186 TestTarget c(setup, "//foo:c", Target::SOURCE_SET); | 189 TestTarget c(setup, "//foo:c", Target::SOURCE_SET); |
| 190 c.config_values().libs().push_back(lib); |
| 191 c.config_values().lib_dirs().push_back(lib_dir); |
| 192 |
| 187 a.public_deps().push_back(LabelTargetPair(&b)); | 193 a.public_deps().push_back(LabelTargetPair(&b)); |
| 188 b.public_deps().push_back(LabelTargetPair(&c)); | 194 b.public_deps().push_back(LabelTargetPair(&c)); |
| 189 | 195 |
| 190 ASSERT_TRUE(c.OnResolved(&err)); | 196 ASSERT_TRUE(c.OnResolved(&err)); |
| 191 ASSERT_TRUE(b.OnResolved(&err)); | 197 ASSERT_TRUE(b.OnResolved(&err)); |
| 192 ASSERT_TRUE(a.OnResolved(&err)); | 198 ASSERT_TRUE(a.OnResolved(&err)); |
| 193 | 199 |
| 194 // B should have C in its inherited libs. | 200 // B should have C in its inherited libs. |
| 195 std::vector<const Target*> b_inherited = b.inherited_libraries().GetOrdered(); | 201 std::vector<const Target*> b_inherited = b.inherited_libraries().GetOrdered(); |
| 196 ASSERT_EQ(1u, b_inherited.size()); | 202 ASSERT_EQ(1u, b_inherited.size()); |
| 197 EXPECT_EQ(&c, b_inherited[0]); | 203 EXPECT_EQ(&c, b_inherited[0]); |
| 198 | 204 |
| 199 // A should have B in its inherited libs, but not any others (the complete | 205 // A should have B in its inherited libs, but not any others (the complete |
| 200 // static library will include the source set). | 206 // static library will include the source set). |
| 201 std::vector<const Target*> a_inherited = a.inherited_libraries().GetOrdered(); | 207 std::vector<const Target*> a_inherited = a.inherited_libraries().GetOrdered(); |
| 202 EXPECT_EQ(1u, a_inherited.size()); | 208 ASSERT_EQ(1u, a_inherited.size()); |
| 203 EXPECT_EQ(&b, a_inherited[0]); | 209 EXPECT_EQ(&b, a_inherited[0]); |
| 210 |
| 211 // A should inherit the libs and lib_dirs from the C. |
| 212 ASSERT_EQ(1u, a.all_libs().size()); |
| 213 EXPECT_EQ(lib, a.all_libs()[0]); |
| 214 ASSERT_EQ(1u, a.all_lib_dirs().size()); |
| 215 EXPECT_EQ(lib_dir, a.all_lib_dirs()[0]); |
| 204 } | 216 } |
| 205 | 217 |
| 206 TEST(Target, InheritCompleteStaticLibNoDirectStaticLibDeps) { | 218 TEST(Target, InheritCompleteStaticLibStaticLibDeps) { |
| 207 TestWithScope setup; | 219 TestWithScope setup; |
| 208 Err err; | 220 Err err; |
| 209 | 221 |
| 210 // Create a dependency chain: | 222 // Create a dependency chain: |
| 211 // A (complete static lib) -> B (static lib) | 223 // A (executable) -> B (complete static lib) -> C (static lib) |
| 212 TestTarget a(setup, "//foo:a", Target::STATIC_LIBRARY); | 224 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
| 213 a.set_complete_static_lib(true); | |
| 214 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); | 225 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); |
| 215 | 226 b.set_complete_static_lib(true); |
| 216 a.public_deps().push_back(LabelTargetPair(&b)); | |
| 217 ASSERT_TRUE(b.OnResolved(&err)); | |
| 218 ASSERT_FALSE(a.OnResolved(&err)); | |
| 219 } | |
| 220 | |
| 221 TEST(Target, InheritCompleteStaticLibNoIheritedStaticLibDeps) { | |
| 222 TestWithScope setup; | |
| 223 Err err; | |
| 224 | |
| 225 // Create a dependency chain: | |
| 226 // A (complete static lib) -> B (source set) -> C (static lib) | |
| 227 TestTarget a(setup, "//foo:a", Target::STATIC_LIBRARY); | |
| 228 a.set_complete_static_lib(true); | |
| 229 TestTarget b(setup, "//foo:b", Target::SOURCE_SET); | |
| 230 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); | 227 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); |
| 231 | |
| 232 a.public_deps().push_back(LabelTargetPair(&b)); | 228 a.public_deps().push_back(LabelTargetPair(&b)); |
| 233 b.public_deps().push_back(LabelTargetPair(&c)); | 229 b.public_deps().push_back(LabelTargetPair(&c)); |
| 234 | 230 |
| 235 ASSERT_TRUE(c.OnResolved(&err)); | 231 ASSERT_TRUE(c.OnResolved(&err)); |
| 236 ASSERT_TRUE(b.OnResolved(&err)); | 232 ASSERT_TRUE(b.OnResolved(&err)); |
| 237 ASSERT_FALSE(a.OnResolved(&err)); | 233 ASSERT_TRUE(a.OnResolved(&err)); |
| 234 |
| 235 // B should have C in its inherited libs. |
| 236 std::vector<const Target*> b_inherited = b.inherited_libraries().GetOrdered(); |
| 237 ASSERT_EQ(1u, b_inherited.size()); |
| 238 EXPECT_EQ(&c, b_inherited[0]); |
| 239 |
| 240 // A should have B in its inherited libs, but not any others (the complete |
| 241 // static library will include the static library). |
| 242 std::vector<const Target*> a_inherited = a.inherited_libraries().GetOrdered(); |
| 243 ASSERT_EQ(1u, a_inherited.size()); |
| 244 EXPECT_EQ(&b, a_inherited[0]); |
| 245 } |
| 246 |
| 247 TEST(Target, InheritCompleteStaticLibInheritedCompleteStaticLibDeps) { |
| 248 TestWithScope setup; |
| 249 Err err; |
| 250 |
| 251 // Create a dependency chain: |
| 252 // A (executable) -> B (complete static lib) -> C (complete static lib) |
| 253 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
| 254 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); |
| 255 b.set_complete_static_lib(true); |
| 256 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); |
| 257 c.set_complete_static_lib(true); |
| 258 |
| 259 a.private_deps().push_back(LabelTargetPair(&b)); |
| 260 b.private_deps().push_back(LabelTargetPair(&c)); |
| 261 |
| 262 ASSERT_TRUE(c.OnResolved(&err)); |
| 263 ASSERT_TRUE(b.OnResolved(&err)); |
| 264 ASSERT_TRUE(a.OnResolved(&err)); |
| 265 |
| 266 // B should have C in its inherited libs. |
| 267 std::vector<const Target*> b_inherited = b.inherited_libraries().GetOrdered(); |
| 268 ASSERT_EQ(1u, b_inherited.size()); |
| 269 EXPECT_EQ(&c, b_inherited[0]); |
| 270 |
| 271 // A should have B and C in its inherited libs. |
| 272 std::vector<const Target*> a_inherited = a.inherited_libraries().GetOrdered(); |
| 273 ASSERT_EQ(2u, a_inherited.size()); |
| 274 EXPECT_EQ(&b, a_inherited[0]); |
| 275 EXPECT_EQ(&c, a_inherited[1]); |
| 238 } | 276 } |
| 239 | 277 |
| 240 TEST(Target, NoActionDepPropgation) { | 278 TEST(Target, NoActionDepPropgation) { |
| 241 TestWithScope setup; | 279 TestWithScope setup; |
| 242 Err err; | 280 Err err; |
| 243 | 281 |
| 244 // Create a dependency chain: | 282 // Create a dependency chain: |
| 245 // A (exe) -> B (action) -> C (source_set) | 283 // A (exe) -> B (action) -> C (source_set) |
| 246 { | 284 { |
| 247 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); | 285 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 ASSERT_EQ(c.bundle_data().file_rules().size(), 1u); | 914 ASSERT_EQ(c.bundle_data().file_rules().size(), 1u); |
| 877 ASSERT_EQ(c.bundle_data().file_rules()[0].sources().size(), 1u); | 915 ASSERT_EQ(c.bundle_data().file_rules()[0].sources().size(), 1u); |
| 878 ASSERT_EQ(c.bundle_data().bundle_deps().size(), 1u); | 916 ASSERT_EQ(c.bundle_data().bundle_deps().size(), 1u); |
| 879 | 917 |
| 880 // E does not have any bundle_data information but gets a list of | 918 // E does not have any bundle_data information but gets a list of |
| 881 // bundle_deps to propagate them during target resolution. | 919 // bundle_deps to propagate them during target resolution. |
| 882 ASSERT_TRUE(e.bundle_data().file_rules().empty()); | 920 ASSERT_TRUE(e.bundle_data().file_rules().empty()); |
| 883 ASSERT_TRUE(e.bundle_data().asset_catalog_sources().empty()); | 921 ASSERT_TRUE(e.bundle_data().asset_catalog_sources().empty()); |
| 884 ASSERT_EQ(e.bundle_data().bundle_deps().size(), 2u); | 922 ASSERT_EQ(e.bundle_data().bundle_deps().size(), 2u); |
| 885 } | 923 } |
| OLD | NEW |