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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ASSERT_TRUE(b_fwd.OnResolved(&err)); | 130 ASSERT_TRUE(b_fwd.OnResolved(&err)); |
131 ASSERT_TRUE(a_fwd.OnResolved(&err)); | 131 ASSERT_TRUE(a_fwd.OnResolved(&err)); |
132 | 132 |
133 // A_fwd should now have both configs. | 133 // A_fwd should now have both configs. |
134 ASSERT_EQ(1u, a_fwd.configs().size()); | 134 ASSERT_EQ(1u, a_fwd.configs().size()); |
135 EXPECT_EQ(&all, a_fwd.configs()[0].ptr); | 135 EXPECT_EQ(&all, a_fwd.configs()[0].ptr); |
136 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); | 136 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); |
137 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); | 137 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); |
138 } | 138 } |
139 | 139 |
| 140 // Tests that dependent configs don't propagate between toolchains. |
| 141 TEST(Target, NoDependentConfigsBetweenToolchains) { |
| 142 TestWithScope setup; |
| 143 Err err; |
| 144 |
| 145 // Create another toolchain. |
| 146 Toolchain other_toolchain(setup.settings(), |
| 147 Label(SourceDir("//other/"), "toolchain")); |
| 148 TestWithScope::SetupToolchain(&other_toolchain); |
| 149 |
| 150 // Set up a dependency chain of |a| -> |b| -> |c| where |a| has a different |
| 151 // toolchain. |
| 152 Target a(setup.settings(), |
| 153 Label(SourceDir("//foo/"), "a", other_toolchain.label().dir(), |
| 154 other_toolchain.label().name())); |
| 155 a.set_output_type(Target::EXECUTABLE); |
| 156 EXPECT_TRUE(a.SetToolchain(&other_toolchain, &err)); |
| 157 TestTarget b(setup, "//foo:b", Target::EXECUTABLE); |
| 158 TestTarget c(setup, "//foo:c", Target::SOURCE_SET); |
| 159 a.private_deps().push_back(LabelTargetPair(&b)); |
| 160 b.private_deps().push_back(LabelTargetPair(&c)); |
| 161 |
| 162 // All dependent config. |
| 163 Config all_dependent(setup.settings(), Label(SourceDir("//foo/"), "all")); |
| 164 ASSERT_TRUE(all_dependent.OnResolved(&err)); |
| 165 c.all_dependent_configs().push_back(LabelConfigPair(&all_dependent)); |
| 166 |
| 167 // Public config. |
| 168 Config public_config(setup.settings(), Label(SourceDir("//foo/"), "public")); |
| 169 ASSERT_TRUE(public_config.OnResolved(&err)); |
| 170 c.public_configs().push_back(LabelConfigPair(&public_config)); |
| 171 |
| 172 // Another public config. |
| 173 Config public_config2(setup.settings(), |
| 174 Label(SourceDir("//foo/"), "public2")); |
| 175 ASSERT_TRUE(public_config2.OnResolved(&err)); |
| 176 b.public_configs().push_back(LabelConfigPair(&public_config2)); |
| 177 |
| 178 ASSERT_TRUE(c.OnResolved(&err)); |
| 179 ASSERT_TRUE(b.OnResolved(&err)); |
| 180 ASSERT_TRUE(a.OnResolved(&err)); |
| 181 |
| 182 // B should have gotten the configs from C. |
| 183 ASSERT_EQ(3u, b.configs().size()); |
| 184 EXPECT_EQ(&public_config2, b.configs()[0].ptr); |
| 185 EXPECT_EQ(&all_dependent, b.configs()[1].ptr); |
| 186 EXPECT_EQ(&public_config, b.configs()[2].ptr); |
| 187 ASSERT_EQ(1u, b.all_dependent_configs().size()); |
| 188 EXPECT_EQ(&all_dependent, b.all_dependent_configs()[0].ptr); |
| 189 |
| 190 // A should not have gotten any configs from B or C. |
| 191 ASSERT_EQ(0u, a.configs().size()); |
| 192 ASSERT_EQ(0u, a.all_dependent_configs().size()); |
| 193 } |
| 194 |
140 TEST(Target, InheritLibs) { | 195 TEST(Target, InheritLibs) { |
141 TestWithScope setup; | 196 TestWithScope setup; |
142 Err err; | 197 Err err; |
143 | 198 |
144 // Create a dependency chain: | 199 // Create a dependency chain: |
145 // A (executable) -> B (shared lib) -> C (static lib) -> D (source set) | 200 // A (executable) -> B (shared lib) -> C (static lib) -> D (source set) |
146 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); | 201 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
147 TestTarget b(setup, "//foo:b", Target::SHARED_LIBRARY); | 202 TestTarget b(setup, "//foo:b", Target::SHARED_LIBRARY); |
148 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); | 203 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); |
149 TestTarget d(setup, "//foo:d", Target::SOURCE_SET); | 204 TestTarget d(setup, "//foo:d", Target::SOURCE_SET); |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 ASSERT_EQ(c.bundle_data().file_rules().size(), 1u); | 1042 ASSERT_EQ(c.bundle_data().file_rules().size(), 1u); |
988 ASSERT_EQ(c.bundle_data().file_rules()[0].sources().size(), 1u); | 1043 ASSERT_EQ(c.bundle_data().file_rules()[0].sources().size(), 1u); |
989 ASSERT_EQ(c.bundle_data().bundle_deps().size(), 1u); | 1044 ASSERT_EQ(c.bundle_data().bundle_deps().size(), 1u); |
990 | 1045 |
991 // E does not have any bundle_data information but gets a list of | 1046 // E does not have any bundle_data information but gets a list of |
992 // bundle_deps to propagate them during target resolution. | 1047 // bundle_deps to propagate them during target resolution. |
993 ASSERT_TRUE(e.bundle_data().file_rules().empty()); | 1048 ASSERT_TRUE(e.bundle_data().file_rules().empty()); |
994 ASSERT_TRUE(e.bundle_data().assets_catalog_sources().empty()); | 1049 ASSERT_TRUE(e.bundle_data().assets_catalog_sources().empty()); |
995 ASSERT_EQ(e.bundle_data().bundle_deps().size(), 2u); | 1050 ASSERT_EQ(e.bundle_data().bundle_deps().size(), 2u); |
996 } | 1051 } |
OLD | NEW |