diff options
author | Dan Willemsen <dwillemsen@google.com> | 2017-02-22 15:38:33 -0800 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2017-02-22 22:42:02 -0800 |
commit | 692e64ebf83bc87baca6e3c90c3d0b2849655d75 (patch) | |
tree | 1b666b46ac573692d5031690650a533c64a5d903 | |
parent | e41c7556c22bda359c2b97cd98d59082110add95 (diff) | |
download | kati-692e64ebf83bc87baca6e3c90c3d0b2849655d75.tar.gz |
Pass a Loc into FindEmulator for better warnings
Before this change, we'd only get a warning from FindEmulator, with no
idea which makefile caused it:
FindEmulator: find: `tests': No such file or directory
With this change, we'll get a better idea of which line triggered that
problem:
cts/tests/tests/content/Android.mk:43: FindEmulator: find: `test': No such file or directory
And it will be colorized like any other location-based warning with the
previous patch if --color_warnings is turned on.
-rw-r--r-- | find.cc | 40 | ||||
-rw-r--r-- | find.h | 3 | ||||
-rw-r--r-- | find_test.cc | 2 | ||||
-rw-r--r-- | func.cc | 9 |
4 files changed, 27 insertions, 27 deletions
@@ -150,7 +150,7 @@ class DirentNode { virtual const DirentNode* FindDir(StringPiece) const { return NULL; } - virtual bool RunFind(const FindCommand& fc, int d, + virtual bool RunFind(const FindCommand& fc, const Loc& loc, int d, string* path, unordered_map<const DirentNode*, string>* cur_read_dirs, vector<string>& out) const = 0; @@ -185,7 +185,7 @@ class DirentFileNode : public DirentNode { : DirentNode(name), type_(type) { } - virtual bool RunFind(const FindCommand& fc, int d, + virtual bool RunFind(const FindCommand& fc, const Loc&, int d, string* path, unordered_map<const DirentNode*, string>*, vector<string>& out) const override { @@ -255,15 +255,15 @@ class DirentDirNode : public DirentNode { return NULL; } - virtual bool RunFind(const FindCommand& fc, int d, + virtual bool RunFind(const FindCommand& fc, const Loc& loc, int d, string* path, unordered_map<const DirentNode*, string>* cur_read_dirs, vector<string>& out) const override { ScopedReadDirTracker srdt(this, *path, cur_read_dirs); if (!srdt.ok()) { - fprintf(stderr, "FindEmulator: find: File system loop detected; `%s' is " - "part of the same file system loop as `%s'.\n", - path->c_str(), srdt.conflicted().c_str()); + WARN_LOC(loc, "FindEmulator: find: File system loop detected; `%s' " + "is part of the same file system loop as `%s'.", + path->c_str(), srdt.conflicted().c_str()); return true; } @@ -292,7 +292,7 @@ class DirentDirNode : public DirentNode { if ((*path)[path->size()-1] != '/') *path += '/'; *path += c->base(); - if (!c->RunFind(fc, d + 1, path, cur_read_dirs, out)) + if (!c->RunFind(fc, loc, d + 1, path, cur_read_dirs, out)) return false; path->resize(orig_path_size); } @@ -320,7 +320,7 @@ class DirentDirNode : public DirentNode { if ((*path)[path->size()-1] != '/') *path += '/'; *path += c->base(); - if (!c->RunFind(fc, d + 1, path, cur_read_dirs, out)) + if (!c->RunFind(fc, loc, d + 1, path, cur_read_dirs, out)) return false; path->resize(orig_path_size); } @@ -330,7 +330,7 @@ class DirentDirNode : public DirentNode { if ((*path)[path->size()-1] != '/') *path += '/'; *path += c->base(); - if (!c->RunFind(fc, d + 1, path, cur_read_dirs, out)) + if (!c->RunFind(fc, loc, d + 1, path, cur_read_dirs, out)) return false; path->resize(orig_path_size); } @@ -360,7 +360,7 @@ class DirentSymlinkNode : public DirentNode { return NULL; } - virtual bool RunFind(const FindCommand& fc, int d, + virtual bool RunFind(const FindCommand& fc, const Loc& loc, int d, string* path, unordered_map<const DirentNode*, string>* cur_read_dirs, vector<string>& out) const override { @@ -368,8 +368,8 @@ class DirentSymlinkNode : public DirentNode { if (fc.follows_symlinks && errno_ != ENOENT) { if (errno_) { if (fc.type != FindCommandType::FINDLEAVES) { - fprintf(stderr, "FindEmulator: find: `%s': %s\n", - path->c_str(), strerror(errno_)); + WARN_LOC(loc, "FindEmulator: find: `%s': %s", + path->c_str(), strerror(errno_)); } return true; } @@ -379,7 +379,7 @@ class DirentSymlinkNode : public DirentNode { return false; } - return to_->RunFind(fc, d, path, cur_read_dirs, out); + return to_->RunFind(fc, loc, d, path, cur_read_dirs, out); } PrintIfNecessary(fc, *path, type, d, out); return true; @@ -783,7 +783,7 @@ class FindEmulatorImpl : public FindEmulator { } virtual bool HandleFind(const string& cmd UNUSED, const FindCommand& fc, - string* out) override { + const Loc& loc, string* out) override { if (!CanHandle(fc.chdir)) { LOG("FindEmulator: Cannot handle chdir (%.*s): %s", SPF(fc.chdir), cmd.c_str()); @@ -823,9 +823,8 @@ class FindEmulatorImpl : public FindEmulator { if (should_fallback) return false; if (!fc.redirect_to_devnull) { - fprintf(stderr, - "FindEmulator: cd: %.*s: No such file or directory\n", - SPF(fc.chdir)); + WARN_LOC(loc, "FindEmulator: cd: %.*s: No such file or directory", + SPF(fc.chdir)); } return true; } @@ -848,16 +847,15 @@ class FindEmulatorImpl : public FindEmulator { return false; } if (!fc.redirect_to_devnull) { - fprintf(stderr, - "FindEmulator: find: `%s': No such file or directory\n", - ConcatDir(fc.chdir, finddir).c_str()); + WARN_LOC(loc, "FindEmulator: find: `%s': No such file or directory", + ConcatDir(fc.chdir, finddir).c_str()); } continue; } string path = finddir; unordered_map<const DirentNode*, string> cur_read_dirs; - if (!base->RunFind(fc, 0, &path, &cur_read_dirs, results)) { + if (!base->RunFind(fc, loc, 0, &path, &cur_read_dirs, results)) { LOG("FindEmulator: RunFind failed: %s", cmd.c_str()); return false; } @@ -20,6 +20,7 @@ #include <unordered_set> #include <vector> +#include "loc.h" #include "string_piece.h" using namespace std; @@ -62,7 +63,7 @@ class FindEmulator { virtual ~FindEmulator() = default; virtual bool HandleFind(const string& cmd, const FindCommand& fc, - string* out) = 0; + const Loc& loc, string* out) = 0; static FindEmulator* Get(); diff --git a/find_test.cc b/find_test.cc index 1ba451a..ebdfa98 100644 --- a/find_test.cc +++ b/find_test.cc @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) { return 1; } string out; - if (!FindEmulator::Get()->HandleFind(cmd, fc, &out)) { + if (!FindEmulator::Get()->HandleFind(cmd, fc, Loc(), &out)) { fprintf(stderr, "Find emulator does not support this command\n"); return 1; } @@ -494,7 +494,8 @@ static bool HasNoIoInShellScript(const string& cmd) { } static void ShellFuncImpl(const string& shell, const string& shellflag, - const string& cmd, string* s, FindCommand** fc) { + const string& cmd, const Loc& loc, string* s, + FindCommand** fc) { LOG("ShellFunc: %s", cmd.c_str()); #ifdef TEST_FIND_EMULATOR @@ -505,11 +506,11 @@ static void ShellFuncImpl(const string& shell, const string& shellflag, *fc = new FindCommand(); if ((*fc)->Parse(cmd)) { #ifdef TEST_FIND_EMULATOR - if (FindEmulator::Get()->HandleFind(cmd, **fc, &out2)) { + if (FindEmulator::Get()->HandleFind(cmd, **fc, loc, &out2)) { need_check = true; } #else - if (FindEmulator::Get()->HandleFind(cmd, **fc, s)) { + if (FindEmulator::Get()->HandleFind(cmd, **fc, loc, s)) { return; } #endif @@ -571,7 +572,7 @@ void ShellFunc(const vector<Value*>& args, Evaluator* ev, string* s) { string out; FindCommand* fc = NULL; - ShellFuncImpl(shell, shellflag, cmd, &out, &fc); + ShellFuncImpl(shell, shellflag, cmd, ev->loc(), &out, &fc); if (ShouldStoreCommandResult(cmd)) { CommandResult* cr = new CommandResult(); cr->op = (fc == NULL) ? CommandOp::SHELL : CommandOp::FIND, |