| 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 "tools/gn/header_checker.h" | 5 #include "tools/gn/header_checker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 while (iter.GetNextIncludeString(¤t_include, &range)) { | 291 while (iter.GetNextIncludeString(¤t_include, &range)) { |
| 292 SourceFile include = SourceFileForInclude(current_include); | 292 SourceFile include = SourceFileForInclude(current_include); |
| 293 if (!CheckInclude(from_target, input_file, include, range, err)) | 293 if (!CheckInclude(from_target, input_file, include, range, err)) |
| 294 return false; | 294 return false; |
| 295 } | 295 } |
| 296 | 296 |
| 297 return true; | 297 return true; |
| 298 } | 298 } |
| 299 | 299 |
| 300 // If the file exists: | 300 // If the file exists: |
| 301 // - It must be in one or more dependencies of the given target. | 301 // - The header must be in the public section of a target, or it must |
| 302 // - Those dependencies must have visibility from the source file. | 302 // be in the sources with no public list (everything is implicitly public). |
| 303 // - The header must be in the public section of those dependeices. | 303 // - The dependency path to the included target must follow only public_deps. |
| 304 // - Those dependencies must either have no direct dependent configs with | 304 // - If there are multiple targets with the header in it, only one need be |
| 305 // flags that affect the compiler, or those direct dependent configs apply | 305 // valid for the check to pass. |
| 306 // to the "from_target" (it's one "hop" away). This ensures that if the | |
| 307 // include file needs needs compiler settings to compile it, that those | |
| 308 // settings are applied to the file including it. | |
| 309 bool HeaderChecker::CheckInclude(const Target* from_target, | 306 bool HeaderChecker::CheckInclude(const Target* from_target, |
| 310 const InputFile& source_file, | 307 const InputFile& source_file, |
| 311 const SourceFile& include_file, | 308 const SourceFile& include_file, |
| 312 const LocationRange& range, | 309 const LocationRange& range, |
| 313 Err* err) const { | 310 Err* err) const { |
| 314 // Assume if the file isn't declared in our sources that we don't need to | 311 // Assume if the file isn't declared in our sources that we don't need to |
| 315 // check it. It would be nice if we could give an error if this happens, but | 312 // check it. It would be nice if we could give an error if this happens, but |
| 316 // our include finder is too primitive and returns all includes, even if | 313 // our include finder is too primitive and returns all includes, even if |
| 317 // they're in a #if not executed in the current build. In that case, it's | 314 // they're in a #if not executed in the current build. In that case, it's |
| 318 // not unusual for the buildfiles to not specify that header at all. | 315 // not unusual for the buildfiles to not specify that header at all. |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 if (targets_with_other_toolchains.size() + | 574 if (targets_with_other_toolchains.size() + |
| 578 targets_with_matching_toolchains.size() > 1) | 575 targets_with_matching_toolchains.size() > 1) |
| 579 msg += "at least one of "; | 576 msg += "at least one of "; |
| 580 msg += "which should somehow be reachable."; | 577 msg += "which should somehow be reachable."; |
| 581 | 578 |
| 582 // Danger: must call CreatePersistentRange to put in Err. | 579 // Danger: must call CreatePersistentRange to put in Err. |
| 583 return Err(CreatePersistentRange(source_file, range), | 580 return Err(CreatePersistentRange(source_file, range), |
| 584 "Include not allowed.", msg); | 581 "Include not allowed.", msg); |
| 585 } | 582 } |
| 586 | 583 |
| OLD | NEW |