From f48c13fde026442adc3d65bacea515ccf5f4e6b3 Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Mon, 17 Oct 2016 18:07:20 -0400 Subject: [PATCH] Change GTestSrcDir to not require our directory be called 'src'. --- pagespeed/kernel/base/gtest.cc | 46 ++++++++++------------------------ 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/pagespeed/kernel/base/gtest.cc b/pagespeed/kernel/base/gtest.cc index 40e1686dc..0f97453c0 100644 --- a/pagespeed/kernel/base/gtest.cc +++ b/pagespeed/kernel/base/gtest.cc @@ -31,44 +31,24 @@ namespace net_instaweb { GoogleString GTestSrcDir() { - // Climb up the directory hierarchy till we find "src". - // TODO(jmarantz): check to make sure we are not in a subdirectory of - // our top-level 'src' named src. - char cwd[kStackBufferSize]; CHECK(getcwd(cwd, sizeof(cwd)) != NULL); - StringPieceVector components; - SplitStringPieceToVector(cwd, "/", &components, true); - int level = components.size(); - bool found = false; - GoogleString src_dir; - for (int i = level - 1; i >= 0; --i) { - if (components[i] == "src") { - level = i + 1; - found = true; - break; - } - } - if (found) { - for (int i = 0; i < level; ++i) { - src_dir += "/"; - components[i].AppendToString(&src_dir); - } - } else { - // Try going down the directory structure to see if we can find "src". - // Just go down one layer, in case there are multiple clients with - // multiple src dirs from where you are. - src_dir += cwd; - src_dir += "/src"; + + // This needs to return the root of the git checkout. In practice all the + // tests are run automatically from there, so we just stat a few directories + // to make sure it looks good and return getcwd(). An alternative might + // be to return the value of $(git rev-parse --show-toplevel). + + bool found = true; + for (const char* dir : {"third_party", "pagespeed"}) { struct stat file_info; - // Attempt to get the file attributes - int ret = stat(src_dir.c_str(), &file_info); - if (ret == 0 && S_ISDIR(file_info.st_mode)) { - found = true; + int ret = stat(dir, &file_info); + if (ret != 0 || !S_ISDIR(file_info.st_mode)) { + found = false; } } - CHECK(found) << "Cannot find 'src' directory from cwd=" << cwd; - return src_dir; + CHECK(found) << "You must run this test from the root of the checkout"; + return cwd; } GoogleString GTestTempDir() {