diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-16 23:31:36 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-16 23:31:36 +0000 |
commit | b0d3ad5d934decf73838747387efc1c5348c8508 (patch) | |
tree | 0b107b8cbc50ebd18b805ce36a9be1b41a86e9c4 /tools/gn | |
parent | 3612f990aa4b0aeeb0660c2d483708b8c6f87a76 (diff) | |
download | chromium_src-b0d3ad5d934decf73838747387efc1c5348c8508.zip chromium_src-b0d3ad5d934decf73838747387efc1c5348c8508.tar.gz chromium_src-b0d3ad5d934decf73838747387efc1c5348c8508.tar.bz2 |
GN: Add logging for the location of an invocation.
I was working on the Windows build and having problems finding why a file was loaded that shouldn't have been. This adds the source of the invocation to the verbose logging so you can find this information.
I removed an assert which caused a debug assertion for random punctuation and isn't harmful (a real error will be reported).
I moved the location-to-string conversion code into the location class so I can share it for my new logging command, and moved a bunch of other logging functions to the new .cc file.
BUG=288991
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/23532076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223469 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gn')
-rw-r--r-- | tools/gn/BUILD.gn | 1 | ||||
-rw-r--r-- | tools/gn/err.cc | 18 | ||||
-rw-r--r-- | tools/gn/gn.gyp | 1 | ||||
-rw-r--r-- | tools/gn/input_file_manager.cc | 8 | ||||
-rw-r--r-- | tools/gn/location.cc | 73 | ||||
-rw-r--r-- | tools/gn/location.h | 49 | ||||
-rw-r--r-- | tools/gn/tokenizer.cc | 1 |
7 files changed, 99 insertions, 52 deletions
diff --git a/tools/gn/BUILD.gn b/tools/gn/BUILD.gn index a887696..c34e977 100644 --- a/tools/gn/BUILD.gn +++ b/tools/gn/BUILD.gn @@ -61,6 +61,7 @@ static_library("gn_lib") { "item_tree.h", "label.cc", "label.h", + "location.cc", "location.h", "ninja_binary_target_writer.cc", "ninja_binary_target_writer.h", diff --git a/tools/gn/err.cc b/tools/gn/err.cc index 326f5b3..5db3c42 100644 --- a/tools/gn/err.cc +++ b/tools/gn/err.cc @@ -161,21 +161,13 @@ void Err::InternalPrintToStdout(bool is_sub_err) const { // File name and location. const InputFile* input_file = location_.file(); - std::string loc_str; - if (input_file) { - std::string name; - if (input_file->friendly_name().empty()) - name = input_file->name().value(); - else - name = input_file->friendly_name(); - + std::string loc_str = location_.Describe(true); + if (!loc_str.empty()) { if (is_sub_err) - loc_str = "See "; + loc_str.insert(0, "See "); else - loc_str = "at "; - loc_str += name + ": " + - base::IntToString(location_.line_number()) + ":" + - base::IntToString(location_.char_offset()) + ": "; + loc_str.insert(0, "at "); + loc_str.append(": "); } OutputString(loc_str + message_ + "\n"); diff --git a/tools/gn/gn.gyp b/tools/gn/gn.gyp index 65b525b..82fa7f7 100644 --- a/tools/gn/gn.gyp +++ b/tools/gn/gn.gyp @@ -71,6 +71,7 @@ 'item_tree.h', 'label.cc', 'label.h', + 'location.cc', 'location.h', 'ninja_binary_target_writer.cc', 'ninja_binary_target_writer.h', diff --git a/tools/gn/input_file_manager.cc b/tools/gn/input_file_manager.cc index 7a009e46..1b55ea4 100644 --- a/tools/gn/input_file_manager.cc +++ b/tools/gn/input_file_manager.cc @@ -194,8 +194,12 @@ bool InputFileManager::LoadFile(const LocationRange& origin, Err* err) { // Do all of this stuff outside the lock. We should not give out file // pointers until the read is complete. - if (g_scheduler->verbose_logging()) - g_scheduler->Log("Loading", name.value()); + if (g_scheduler->verbose_logging()) { + std::string logmsg = name.value(); + if (origin.begin().file()) + logmsg += " (referenced from " + origin.begin().Describe(false) + ")"; + g_scheduler->Log("Loading", logmsg); + } // Read. base::FilePath primary_path = build_settings->GetFullPath(name); diff --git a/tools/gn/location.cc b/tools/gn/location.cc new file mode 100644 index 0000000..61f22b5 --- /dev/null +++ b/tools/gn/location.cc @@ -0,0 +1,73 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "tools/gn/location.h" + +#include "base/logging.h" +#include "base/strings/string_number_conversions.h" +#include "tools/gn/input_file.h" + +Location::Location() + : file_(NULL), + line_number_(-1), + char_offset_(-1) { +} + +Location::Location(const InputFile* file, int line_number, int char_offset) + : file_(file), + line_number_(line_number), + char_offset_(char_offset) { +} + +bool Location::operator==(const Location& other) const { + return other.file_ == file_ && + other.line_number_ == line_number_ && + other.char_offset_ == char_offset_; +} + +bool Location::operator!=(const Location& other) const { + return !operator==(other); +} + +bool Location::operator<(const Location& other) const { + DCHECK(file_ == other.file_); + if (line_number_ != other.line_number_) + return line_number_ < other.line_number_; + return char_offset_ < other.char_offset_; +} + +std::string Location::Describe(bool include_char_offset) const { + if (!file_) + return std::string(); + + std::string ret; + if (file_->friendly_name().empty()) + ret = file_->name().value(); + else + ret = file_->friendly_name(); + + ret += ":"; + ret += base::IntToString(line_number_); + if (include_char_offset) { + ret += ":"; + ret += base::IntToString(char_offset_); + } + return ret; +} + +LocationRange::LocationRange() { +} + +LocationRange::LocationRange(const Location& begin, const Location& end) + : begin_(begin), + end_(end) { + DCHECK(begin_.file() == end_.file()); +} + +LocationRange LocationRange::Union(const LocationRange& other) const { + DCHECK(begin_.file() == other.begin_.file()); + return LocationRange( + begin_ < other.begin_ ? begin_ : other.begin_, + end_ < other.end_ ? other.end_ : end_); +} diff --git a/tools/gn/location.h b/tools/gn/location.h index 2055125..aad3960 100644 --- a/tools/gn/location.h +++ b/tools/gn/location.h @@ -5,42 +5,28 @@ #ifndef TOOLS_GN_LOCATION_H_ #define TOOLS_GN_LOCATION_H_ -#include <algorithm> - -#include "base/logging.h" +#include <string> class InputFile; // Represents a place in a source file. Used for error reporting. class Location { public: - Location() - : file_(NULL), - line_number_(-1), - char_offset_(-1) { - } - Location(const InputFile* file, int line_number, int char_offset) - : file_(file), - line_number_(line_number), - char_offset_(char_offset) { - } + Location(); + Location(const InputFile* file, int line_number, int char_offset); const InputFile* file() const { return file_; } int line_number() const { return line_number_; } int char_offset() const { return char_offset_; } - bool operator==(const Location& other) const { - return other.file_ == file_ && - other.line_number_ == line_number_ && - other.char_offset_ == char_offset_; - } + bool operator==(const Location& other) const; + bool operator!=(const Location& other) const; + bool operator<(const Location& other) const; - bool operator<(const Location& other) const { - DCHECK(file_ == other.file_); - if (line_number_ != other.line_number_) - return line_number_ < other.line_number_; - return char_offset_ < other.char_offset_; - } + // Returns a string with the file, line, and (optionally) the character + // offset for this location. If this location is null, returns an empty + // string. + std::string Describe(bool include_char_offset) const; private: const InputFile* file_; // Null when unset. @@ -52,22 +38,13 @@ class Location { // The end is exclusive i.e. [begin, end) class LocationRange { public: - LocationRange() {} - LocationRange(const Location& begin, const Location& end) - : begin_(begin), - end_(end) { - DCHECK(begin_.file() == end_.file()); - } + LocationRange(); + LocationRange(const Location& begin, const Location& end); const Location& begin() const { return begin_; } const Location& end() const { return end_; } - LocationRange Union(const LocationRange& other) const { - DCHECK(begin_.file() == other.begin_.file()); - return LocationRange( - begin_ < other.begin_ ? begin_ : other.begin_, - end_ < other.end_ ? other.end_ : end_); - } + LocationRange Union(const LocationRange& other) const; private: Location begin_; diff --git a/tools/gn/tokenizer.cc b/tools/gn/tokenizer.cc index 6771927..8acabdb 100644 --- a/tools/gn/tokenizer.cc +++ b/tools/gn/tokenizer.cc @@ -64,7 +64,6 @@ Token::Type GetSpecificOperatorType(base::StringPiece value) { return Token::BOOLEAN_OR; if (value == "!") return Token::BANG; - NOTREACHED(); return Token::INVALID; } |