OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/config.h" | 8 #include "tools/gn/config.h" |
9 #include "tools/gn/header_checker.h" | 9 #include "tools/gn/header_checker.h" |
10 #include "tools/gn/scheduler.h" | 10 #include "tools/gn/scheduler.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 b_.sources().push_back(b_public); | 155 b_.sources().push_back(b_public); |
156 c_.set_all_headers_public(true); | 156 c_.set_all_headers_public(true); |
157 | 157 |
158 // Add a public and private header on C. | 158 // Add a public and private header on C. |
159 SourceFile c_public("//c_public.h"); | 159 SourceFile c_public("//c_public.h"); |
160 SourceFile c_private("//c_private.h"); | 160 SourceFile c_private("//c_private.h"); |
161 c_.sources().push_back(c_private); | 161 c_.sources().push_back(c_private); |
162 c_.public_headers().push_back(c_public); | 162 c_.public_headers().push_back(c_public); |
163 c_.set_all_headers_public(false); | 163 c_.set_all_headers_public(false); |
164 | 164 |
| 165 // Create another toolchain. |
| 166 Settings other_settings(setup_.build_settings(), "other/"); |
| 167 Toolchain other_toolchain(&other_settings, |
| 168 Label(SourceDir("//toolchain/"), "other")); |
| 169 TestWithScope::SetupToolchain(&other_toolchain); |
| 170 other_settings.set_toolchain_label(other_toolchain.label()); |
| 171 other_settings.set_default_toolchain_label(setup_.toolchain()->label()); |
| 172 |
| 173 // Add a target in the other toolchain with a header in it that is not |
| 174 // connected to any targets in the main toolchain. |
| 175 Target otc(&other_settings, Label(SourceDir("//p/"), "otc", |
| 176 other_toolchain.label().dir(), other_toolchain.label().name())); |
| 177 otc.set_output_type(Target::SOURCE_SET); |
| 178 Err err; |
| 179 EXPECT_TRUE(otc.SetToolchain(&other_toolchain, &err)); |
| 180 otc.visibility().SetPublic(); |
| 181 targets_.push_back(&otc); |
| 182 |
| 183 SourceFile otc_header("//otc_header.h"); |
| 184 otc.sources().push_back(otc_header); |
| 185 EXPECT_TRUE(otc.OnResolved(&err)); |
| 186 |
165 scoped_refptr<HeaderChecker> checker( | 187 scoped_refptr<HeaderChecker> checker( |
166 new HeaderChecker(setup_.build_settings(), targets_)); | 188 new HeaderChecker(setup_.build_settings(), targets_)); |
167 | 189 |
168 // A file in target A can't include a header from D because A has no | 190 // A file in target A can't include a header from D because A has no |
169 // dependency on D. | 191 // dependency on D. |
170 Err err; | |
171 EXPECT_FALSE(checker->CheckInclude(&a_, input_file, d_header, range, &err)); | 192 EXPECT_FALSE(checker->CheckInclude(&a_, input_file, d_header, range, &err)); |
172 EXPECT_TRUE(err.has_error()); | 193 EXPECT_TRUE(err.has_error()); |
173 | 194 |
174 // A can include the public header in B. | 195 // A can include the public header in B. |
175 err = Err(); | 196 err = Err(); |
176 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, b_public, range, &err)); | 197 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, b_public, range, &err)); |
177 EXPECT_FALSE(err.has_error()); | 198 EXPECT_FALSE(err.has_error()); |
178 | 199 |
179 // Check A depending on the public and private headers in C. | 200 // Check A depending on the public and private headers in C. |
180 err = Err(); | 201 err = Err(); |
181 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, c_public, range, &err)); | 202 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, c_public, range, &err)); |
182 EXPECT_FALSE(err.has_error()); | 203 EXPECT_FALSE(err.has_error()); |
183 EXPECT_FALSE(checker->CheckInclude(&a_, input_file, c_private, range, &err)); | 204 EXPECT_FALSE(checker->CheckInclude(&a_, input_file, c_private, range, &err)); |
184 EXPECT_TRUE(err.has_error()); | 205 EXPECT_TRUE(err.has_error()); |
185 | 206 |
186 // A can depend on a random file unknown to the build. | 207 // A can depend on a random file unknown to the build. |
187 err = Err(); | 208 err = Err(); |
188 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, SourceFile("//random.h"), | 209 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, SourceFile("//random.h"), |
189 range, &err)); | 210 range, &err)); |
190 EXPECT_FALSE(err.has_error()); | 211 EXPECT_FALSE(err.has_error()); |
| 212 |
| 213 // A can depend on a file present only in another toolchain even with no |
| 214 // dependency path. |
| 215 err = Err(); |
| 216 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, otc_header, range, &err)); |
| 217 EXPECT_FALSE(err.has_error()); |
191 } | 218 } |
192 | 219 |
193 // A public chain of dependencies should always be identified first, even if | 220 // A public chain of dependencies should always be identified first, even if |
194 // it is longer than a private one. | 221 // it is longer than a private one. |
195 TEST_F(HeaderCheckerTest, PublicFirst) { | 222 TEST_F(HeaderCheckerTest, PublicFirst) { |
196 // Now make a A -> Z -> D private dependency chain (one shorter than the | 223 // Now make a A -> Z -> D private dependency chain (one shorter than the |
197 // public one to get to D). | 224 // public one to get to D). |
198 Target z(setup_.settings(), Label(SourceDir("//a/"), "a")); | 225 Target z(setup_.settings(), Label(SourceDir("//a/"), "a")); |
199 z.set_output_type(Target::SOURCE_SET); | 226 z.set_output_type(Target::SOURCE_SET); |
200 Err err; | 227 Err err; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 EXPECT_TRUE(err.has_error()); | 281 EXPECT_TRUE(err.has_error()); |
255 | 282 |
256 // Add an allow_circular_includes_from on A that lists B. | 283 // Add an allow_circular_includes_from on A that lists B. |
257 a_.allow_circular_includes_from().insert(b_.label()); | 284 a_.allow_circular_includes_from().insert(b_.label()); |
258 | 285 |
259 // Now the include from B to A should be allowed. | 286 // Now the include from B to A should be allowed. |
260 err = Err(); | 287 err = Err(); |
261 EXPECT_TRUE(checker->CheckInclude(&b_, input_file, a_public, range, &err)); | 288 EXPECT_TRUE(checker->CheckInclude(&b_, input_file, a_public, range, &err)); |
262 EXPECT_FALSE(err.has_error()); | 289 EXPECT_FALSE(err.has_error()); |
263 } | 290 } |
OLD | NEW |