Commit 5321951e authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Change "gn check" to report all incorrect include

Fixing "gn check" errors can be frustrating after a coding
session as it only reports the first #include violation in
each file.

Change HeaderChecker to instead record all errors that are
found when checking a file and report all of them.

Bug: none
Change-Id: I2e077090ad176300c570583acecbf34192a9963e
Reviewed-on: https://chromium-review.googlesource.com/1107992Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569187}
parent 4b9611c3
...@@ -182,10 +182,10 @@ void HeaderChecker::RunCheckOverFiles(const FileMap& files, bool force_check) { ...@@ -182,10 +182,10 @@ void HeaderChecker::RunCheckOverFiles(const FileMap& files, bool force_check) {
} }
void HeaderChecker::DoWork(const Target* target, const SourceFile& file) { void HeaderChecker::DoWork(const Target* target, const SourceFile& file) {
Err err; std::vector<Err> errors;
if (!CheckFile(target, file, &err)) { if (!CheckFile(target, file, &errors)) {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
errors_.push_back(err); errors_.insert(errors_.end(), errors.begin(), errors.end());
} }
if (!task_count_.Decrement()) { if (!task_count_.Decrement()) {
...@@ -264,7 +264,7 @@ SourceFile HeaderChecker::SourceFileForInclude( ...@@ -264,7 +264,7 @@ SourceFile HeaderChecker::SourceFileForInclude(
bool HeaderChecker::CheckFile(const Target* from_target, bool HeaderChecker::CheckFile(const Target* from_target,
const SourceFile& file, const SourceFile& file,
Err* err) const { std::vector<Err>* errors) const {
ScopedTrace trace(TraceItem::TRACE_CHECK_HEADER, file.value()); ScopedTrace trace(TraceItem::TRACE_CHECK_HEADER, file.value());
// Sometimes you have generated source files included as sources in another // Sometimes you have generated source files included as sources in another
...@@ -277,10 +277,11 @@ bool HeaderChecker::CheckFile(const Target* from_target, ...@@ -277,10 +277,11 @@ bool HeaderChecker::CheckFile(const Target* from_target,
base::FilePath path = build_settings_->GetFullPath(file); base::FilePath path = build_settings_->GetFullPath(file);
std::string contents; std::string contents;
if (!base::ReadFileToString(path, &contents)) { if (!base::ReadFileToString(path, &contents)) {
*err = Err(from_target->defined_from(), "Source file not found.", errors->emplace_back(from_target->defined_from(), "Source file not found.",
"The target:\n " + from_target->label().GetUserVisibleName(false) + "The target:\n " +
"\nhas a source file:\n " + file.value() + from_target->label().GetUserVisibleName(false) +
"\nwhich was not found."); "\nhas a source file:\n " + file.value() +
"\nwhich was not found.");
return false; return false;
} }
...@@ -296,19 +297,23 @@ bool HeaderChecker::CheckFile(const Target* from_target, ...@@ -296,19 +297,23 @@ bool HeaderChecker::CheckFile(const Target* from_target,
target_include_dirs.end()); target_include_dirs.end());
} }
bool has_errors = false;
CIncludeIterator iter(&input_file); CIncludeIterator iter(&input_file);
base::StringPiece current_include; base::StringPiece current_include;
LocationRange range; LocationRange range;
while (iter.GetNextIncludeString(&current_include, &range)) { while (iter.GetNextIncludeString(&current_include, &range)) {
Err err;
SourceFile include = SourceFileForInclude(current_include, include_dirs, SourceFile include = SourceFileForInclude(current_include, include_dirs,
input_file, range, err); input_file, range, &err);
if (!include.is_null()) { if (!include.is_null()) {
if (!CheckInclude(from_target, input_file, include, range, err)) if (!CheckInclude(from_target, input_file, include, range, &err)) {
return false; errors->emplace_back(std::move(err));
has_errors = true;
}
} }
} }
return true; return !has_errors;
} }
// If the file exists: // If the file exists:
......
...@@ -120,7 +120,7 @@ class HeaderChecker : public base::RefCountedThreadSafe<HeaderChecker> { ...@@ -120,7 +120,7 @@ class HeaderChecker : public base::RefCountedThreadSafe<HeaderChecker> {
// error messages. // error messages.
bool CheckFile(const Target* from_target, bool CheckFile(const Target* from_target,
const SourceFile& file, const SourceFile& file,
Err* err) const; std::vector<Err>* errors) const;
// Checks that the given file in the given target can include the given // Checks that the given file in the given target can include the given
// include file. If disallowed, returns false and sets the error. The // include file. If disallowed, returns false and sets the error. The
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment