Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CTest support #310

Merged
merged 11 commits into from
Apr 10, 2020
Prev Previous commit
Next Next commit
[Fix] Replace PWD with getcwd
PWD is not always the same as current working directory.

This is a problem when calling tests from ctest: the working directory
is changed, but the value of env::PWD is then incorrect.
Kernel files are then not found.

Using this system call the directory is correctly returned.
  • Loading branch information
SFrijters committed Apr 9, 2020
commit 70f940b8b8422b676d3a64f2b515a7c2c40292ca
2 changes: 2 additions & 0 deletions include/occa/io/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace occa {
const std::string& cachePath();
const std::string& libraryPath();

std::string currentWorkingDirectory();

void endWithSlash(std::string &dir);
std::string endWithSlash(const std::string &dir);

Expand Down
2 changes: 1 addition & 1 deletion include/occa/tools/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace occa {
properties& settings();

namespace env {
extern std::string HOME, PWD;
extern std::string HOME, CWD;
extern std::string PATH, LD_LIBRARY_PATH;

extern std::string OCCA_DIR, OCCA_CACHE_DIR;
Expand Down
12 changes: 11 additions & 1 deletion src/io/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ namespace occa {
return path;
}

std::string currentWorkingDirectory() {
char cwdBuff[FILENAME_MAX];
#if (OCCA_OS == OCCA_WINDOWS_OS)
_getcwd(cwdBuff, sizeof(cwdBuff));
#else
getcwd(cwdBuff, sizeof(cwdBuff));
#endif
return endWithSlash(std::string(cwdBuff));
}

void endWithSlash(std::string &dir) {
const int chars = (int) dir.size();
if ((0 < chars) &&
Expand Down Expand Up @@ -167,7 +177,7 @@ namespace occa {
expFilename = fo.expand(expFilename);

if (makeAbsolute && !isAbsolutePath(expFilename)) {
expFilename = env::PWD + expFilename;
SFrijters marked this conversation as resolved.
Show resolved Hide resolved
expFilename = env::CWD + expFilename;
}
return expFilename;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lang/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ namespace occa {
header = path + header;
break;
} else if (i == (pathCount - 1)) {
header = env::PWD + header;
header = env::CWD + header;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/tools/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace occa {
}

namespace env {
std::string HOME, PWD;
std::string HOME, CWD;
std::string PATH, LD_LIBRARY_PATH;

std::string OCCA_DIR, OCCA_CACHE_DIR;
Expand Down Expand Up @@ -72,15 +72,15 @@ namespace occa {
// Standard environment variables
#if (OCCA_OS & (OCCA_LINUX_OS | OCCA_MACOS_OS))
HOME = env::var("HOME");
PWD = env::var("PWD");
CWD = occa::io::currentWorkingDirectory();
PATH = env::var("PATH");
LD_LIBRARY_PATH = env::var("LD_LIBRARY_PATH");

OCCA_CACHE_DIR = env::var("OCCA_CACHE_DIR");
OCCA_COLOR_ENABLED = env::get<bool>("OCCA_COLOR_ENABLED", true);

io::endWithSlash(HOME);
io::endWithSlash(PWD);
io::endWithSlash(CWD);
io::endWithSlash(PATH);
#endif

Expand Down
4 changes: 2 additions & 2 deletions tests/src/io/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void testPathMethods() {
"b");

ASSERT_EQ(occa::io::dirname("b.okl"),
occa::env::PWD);
occa::env::CWD);
ASSERT_EQ(occa::io::dirname("/a/b.okl"),
"/a/");
ASSERT_EQ(occa::io::dirname("/a"),
Expand Down Expand Up @@ -143,7 +143,7 @@ void testDirMethods() {
}

void testIOMethods() {
const std::string test_foo = occa::env::PWD + "test_foo";
const std::string test_foo = occa::env::CWD + "test_foo";

std::string content = "start";
for (int i = 0; i < 100; ++i) {
Expand Down