Change GTestSrcDir to not require our directory be called 'src'.
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user