Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Unified Diff: net/test/python_utils.cc

Issue 969313002: Simplify GetPyProtoPath. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/python_utils.cc
diff --git a/net/test/python_utils.cc b/net/test/python_utils.cc
index bd0e5654beabb0032fd3c836029da10bb4c6bf3d..9de1e7de8646b4c3cc30706932cd398a92e2b521 100644
--- a/net/test/python_utils.cc
+++ b/net/test/python_utils.cc
@@ -42,31 +42,6 @@ void AppendToPythonPath(const base::FilePath& dir) {
}
}
-namespace {
-
-#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
-// Search for |to_try|, rolling up the directory tree from
-// |start_dir|. If found, return true and put the path to |to_try| in
-// |out_dir|. If not, return false and leave |out_dir| untouched.
-bool TryRelativeToDir(const base::FilePath& start_dir,
- const base::FilePath& to_try,
- base::FilePath* out_dir) {
- base::FilePath dir(start_dir);
- while (!base::DirectoryExists(dir.Append(to_try))) {
- base::FilePath parent = dir.DirName();
- if (parent == dir) {
- // We hit the root directory.
- return false;
- }
- dir = parent;
- }
- *out_dir = dir;
- return true;
-}
-#endif // defined(OS_MACOSX) || defined(OS_CHROMEOS)
-
-} // namespace
-
bool GetPyProtoPath(base::FilePath* dir) {
// Locate the Python code generated by the protocol buffers compiler.
base::FilePath generated_code_dir;
@@ -77,32 +52,19 @@ bool GetPyProtoPath(base::FilePath* dir) {
const base::FilePath kPyProto(FILE_PATH_LITERAL("pyproto"));
-#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
- base::FilePath source_dir;
- if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_dir)) {
- LOG(ERROR) << "Can't find " << source_dir.value();
- return false;
- }
- // On Mac, and possibly Chrome OS, DIR_EXE might be pointing deep
- // into the Release/ (or Debug/) directory and we can't depend on
- // how far down it goes. So we walk upwards from DIR_EXE until we
- // find a likely looking spot.
- if (!TryRelativeToDir(generated_code_dir, kPyProto, dir)) {
- LOG(WARNING) << "Can't find " << kPyProto.value()
- << " next to " << generated_code_dir.value();
- // On Chrome OS, we may have installed the test binaries and support tools
- // in a wholly separate location, relative to DIR_SOURCE_ROOT. We'll want
- // to do a similar investigation from that point as well.
- generated_code_dir = source_dir
- .Append(FILE_PATH_LITERAL("out"))
- .Append(FILE_PATH_LITERAL("Release"));
- if (!TryRelativeToDir(generated_code_dir, kPyProto, dir)) {
- LOG(WARNING) << "Can't find " << kPyProto.value()
- << " next to " << generated_code_dir.value();
+#if defined(OS_MACOSX)
+ // On Mac, DIR_EXE might be pointing deep into the Release/ (or Debug/)
+ // directory and we can't depend on how far down it goes. So we walk upwards
+ // from DIR_EXE until we find a likely looking spot.
+ while (!base::DirectoryExists(generated_code_dir.Append(kPyProto))) {
+ base::FilePath parent = generated_code_dir.DirName();
+ if (parent == generated_code_dir) {
+ // We hit the root directory. Maybe we didn't build any targets which
+ // produced Python protocol buffers.
return false;
}
+ generated_code_dir = parent;
}
- generated_code_dir = *dir;
#endif
*dir = generated_code_dir.Append(kPyProto);
VLOG(2) << "Found " << kPyProto.value() << " in " << dir->value();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698