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.
diff --git a/find.cc b/find.cc
index 5d9cab6..0860847 100644
--- a/find.cc
+++ b/find.cc
@@ -150,7 +150,7 @@
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 @@
: 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
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 @@
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;
}