Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/occa/utils/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ namespace occa {
json& settings();

namespace env {
extern std::string OCCA_DIR, OCCA_INSTALL_DIR, OCCA_CACHE_DIR;
extern std::string OCCA_DIR, OCCA_INSTALL_DIR, OCCA_CACHE_DIR, OCCA_SOURCE_CACHE_DIR;

void setOccaCacheDir(const std::string &path);
void setOccaBinaryCacheDir(const std::string &path);
void init();
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/occa/internal/bin/occa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,19 @@ namespace occa {
const bool promptCheck = !options["yes"];

if (options["all"] &&
safeRmrf(env::OCCA_CACHE_DIR, promptCheck)) {
safeRmrf(env::OCCA_CACHE_DIR, promptCheck) &&
safeRmrf(env::OCCA_SOURCE_CACHE_DIR, promptCheck)) {
printRemovedMessage(true);
return true;
}

bool removedSomething = false;
if (options["kernels"]) {
removedSomething |= safeRmrf(io::cachePath(), promptCheck);
removedSomething |= safeRmrf(io::sourceCachePath(), promptCheck);
}
if (options["locks"]) {
const std::string lockPath = env::OCCA_CACHE_DIR + "locks/";
const std::string lockPath = env::OCCA_SOURCE_CACHE_DIR + "locks/";
removedSomething |= safeRmrf(lockPath, promptCheck);
}

Expand Down Expand Up @@ -240,6 +242,7 @@ namespace occa {
io::stdout << " Basic:\n"
<< " - OCCA_DIR : " << envEcho("OCCA_DIR") << "\n"
<< " - OCCA_CACHE_DIR : " << envEcho("OCCA_CACHE_DIR") << "\n"
<< " - OCCA_SOURCE_CACHE_DIR : " << envEcho("OCCA_SOURCE_CACHE_DIR") << "\n"
<< " - OCCA_VERBOSE : " << envEcho("OCCA_VERBOSE") << "\n"
<< " - OCCA_UNSAFE : " << OCCA_UNSAFE << "\n"

Expand Down
3 changes: 2 additions & 1 deletion src/occa/internal/core/launchedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ namespace occa {
const bool usingOkl,
const occa::json &kernelProps) {
const std::string hashDir = io::hashDir(filename, kernelHash);
const std::string binaryHashDir = io::hashDir(filename, kernelHash, true);
std::string sourceFilename = hashDir + kc::cachedSourceFilename(filename);
const std::string binaryFilename = hashDir + kc::binaryFile;
const std::string binaryFilename = binaryHashDir + kc::binaryFile;

// Check if binary exists and is finished
const bool foundBinary = io::isFile(binaryFilename);
Expand Down
15 changes: 8 additions & 7 deletions src/occa/internal/io/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace occa {
namespace io {
bool isCached(const std::string &filename) {
bool isCached(const std::string &filename, bool binary) {
// Directory, not file
if (filename.size() == 0) {
return false;
Expand All @@ -18,19 +18,20 @@ namespace occa {
std::string expFilename = io::expandFilename(filename);

// File is already cached
const std::string &cPath = cachePath();
const std::string &cPath = binary ? cachePath() : sourceCachePath();
return startsWith(expFilename, cPath);
}

std::string hashDir(const hash_t &hash) {
return hashDir("", hash);
std::string hashDir(const hash_t &hash, bool binary) {
return hashDir("", hash, binary);
}

std::string hashDir(const std::string &filename,
const hash_t &hash) {
bool fileIsCached = isCached(filename);
const hash_t &hash,
bool binary) {
bool fileIsCached = isCached(filename, binary);

const std::string &cPath = cachePath();
const std::string &cPath = binary ? cachePath() : sourceCachePath();
std::string cacheDir = cPath;

const bool useHash = !filename.size() || !fileIsCached;
Expand Down
6 changes: 3 additions & 3 deletions src/occa/internal/io/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace occa {
class json;

namespace io {
bool isCached(const std::string &filename);
bool isCached(const std::string &filename, bool binary=false);

std::string hashDir(const hash_t &hash);
std::string hashDir(const hash_t &hash, bool binary=false);

std::string hashDir(const std::string &filename,
const hash_t &hash = hash_t());
const hash_t &hash = hash_t(), bool binary=false);

std::string cacheFile(const std::string &filename,
const std::string &cachedName,
Expand Down
13 changes: 8 additions & 5 deletions src/occa/internal/io/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ namespace occa {
return env::OCCA_CACHE_DIR + "cache/";
}

std::string sourceCachePath() {
return env::OCCA_SOURCE_CACHE_DIR + "cache/";
}

std::string libraryPath() {
return env::OCCA_CACHE_DIR + "libraries/";
}
Expand Down Expand Up @@ -290,12 +294,11 @@ namespace occa {
std::string shortname(const std::string &filename) {
std::string expFilename = io::expandFilename(filename);

if (!startsWith(expFilename, env::OCCA_CACHE_DIR)) {
return filename;
if (startsWith(expFilename, env::OCCA_CACHE_DIR) || startsWith(expFilename, env::OCCA_SOURCE_CACHE_DIR)) {
const std::string &cPath = startsWith(expFilename, env::OCCA_CACHE_DIR) ? cachePath() : sourceCachePath();
return expFilename.substr(cPath.size());
}

const std::string &cPath = cachePath();
return expFilename.substr(cPath.size());
return filename;
}

std::string findInPaths(const std::string &filename, const strVector &paths) {
Expand Down
1 change: 1 addition & 0 deletions src/occa/internal/io/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace occa {
typedef std::map<std::string, std::string> libraryPathMap_t;

std::string cachePath();
std::string sourceCachePath();
std::string libraryPath();

std::string currentWorkingDirectory();
Expand Down
3 changes: 2 additions & 1 deletion src/occa/internal/modes/serial/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ namespace occa {
const occa::json &kernelProps,
const bool isLauncherKernel) {
const std::string hashDir = io::hashDir(filename, kernelHash);
const std::string binaryHashDir = io::hashDir(filename, kernelHash, true);

const std::string &kcBinaryFile = (
isLauncherKernel
? kc::launcherBinaryFile
: kc::binaryFile
);
std::string binaryFilename = hashDir + kcBinaryFile;
std::string binaryFilename = binaryHashDir + kcBinaryFile;

// Check if binary exists and is finished
const bool foundBinary = io::isFile(binaryFilename);
Expand Down
37 changes: 28 additions & 9 deletions src/occa/internal/utils/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace occa {
std::string HOME, CWD;
std::string PATH, LD_LIBRARY_PATH;

std::string OCCA_DIR, OCCA_INSTALL_DIR, OCCA_CACHE_DIR;
std::string OCCA_DIR, OCCA_INSTALL_DIR, OCCA_CACHE_DIR, OCCA_SOURCE_CACHE_DIR;
size_t OCCA_MEM_BYTE_ALIGN;
strVector OCCA_INCLUDE_PATH;
strVector OCCA_LIBRARY_PATH;
Expand All @@ -58,12 +58,13 @@ namespace occa {
envInitializer_t::setupCachePath();
}

envInitializer_t::envInitializer_t() :
isInitialized(false) {
if (isInitialized) {
return;
}
void setOccaSourceCacheDir(const std::string &path) {
OCCA_SOURCE_CACHE_DIR = path;
envInitializer_t::setupCachePath();
}


void envInitializer_t::init() {
initSettings();
initEnvironment();
loadConfig();
Expand All @@ -73,6 +74,14 @@ namespace occa {
isInitialized = true;
}

envInitializer_t::envInitializer_t() :
isInitialized(false) {
if (isInitialized) {
return;
}
init();
}

void envInitializer_t::initSettings() {
json &settings_ = baseSettings();
settings_["version"] = OCCA_VERSION_STR;
Expand All @@ -94,8 +103,9 @@ namespace occa {
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);
OCCA_CACHE_DIR = env::var("OCCA_CACHE_DIR");
OCCA_SOURCE_CACHE_DIR = env::var("OCCA_SOURCE_CACHE_DIR");
OCCA_COLOR_ENABLED = env::get<bool>("OCCA_COLOR_ENABLED", true);

OCCA_INCLUDE_PATH = split(env::var("OCCA_INCLUDE_PATH"), ':', '\\');
OCCA_LIBRARY_PATH = split(env::var("OCCA_LIBRARY_PATH"), ':', '\\');
Expand Down Expand Up @@ -124,6 +134,7 @@ namespace occa {
io::endWithSlash(OCCA_DIR);
io::endWithSlash(OCCA_INSTALL_DIR);
io::endWithSlash(OCCA_CACHE_DIR);
io::endWithSlash(OCCA_SOURCE_CACHE_DIR);

OCCA_MEM_BYTE_ALIGN = OCCA_DEFAULT_MEM_BYTE_ALIGN;
if (env::var("OCCA_MEM_BYTE_ALIGN").size() > 0) {
Expand All @@ -142,7 +153,7 @@ namespace occa {
void envInitializer_t::loadConfig() {
const std::string configFile = (
env::get("OCCA_CONFIG",
OCCA_CACHE_DIR + "config.json")
OCCA_SOURCE_CACHE_DIR + "config.json")
);

if (!io::exists(configFile)) {
Expand Down Expand Up @@ -179,10 +190,18 @@ namespace occa {
if (!io::isDir(env::OCCA_CACHE_DIR)) {
sys::mkpath(env::OCCA_CACHE_DIR);
}

if (env::OCCA_SOURCE_CACHE_DIR.size() == 0) {
env::OCCA_SOURCE_CACHE_DIR = env::OCCA_CACHE_DIR;
}
}

envInitializer_t::~envInitializer_t() {}

envInitializer_t envInitializer;

void init() {
envInitializer.init();
}
}
}
3 changes: 3 additions & 0 deletions src/occa/internal/utils/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ namespace occa {
}

void setOccaCacheDir(const std::string &path);
void setOccaSourceCacheDir(const std::string &path);

class envInitializer_t {
public:
envInitializer_t();
~envInitializer_t();
void init();

private:
bool isInitialized;
Expand All @@ -53,6 +55,7 @@ namespace occa {
static void cleanFileOpeners();

friend void setOccaCacheDir(const std::string &path);
friend void setOccaSourceCacheDir(const std::string &path);
};

extern envInitializer_t envInitializer;
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ function(add_occa_test test_source)
# Expected defines
set_property(TEST ${cmake_test_target} APPEND PROPERTY
ENVIRONMENT OCCA_CACHE_DIR=${OCCA_BUILD_DIR}/occa)

set_property(TEST ${cmake_test_target} APPEND PROPERTY
ENVIRONMENT OCCA_SOURCE_CACHE_DIR=${OCCA_BUILD_DIR}/occa)
endfunction()

#---[ Setup Tests ]---------------------
Expand Down
1 change: 1 addition & 0 deletions tests/src/internal/io/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void testBuild();
int main(const int argc, const char **argv) {
#ifndef USE_CMAKE
occa::env::OCCA_CACHE_DIR = occa::io::dirname(__FILE__);
occa::env::OCCA_SOURCE_CACHE_DIR = occa::env::OCCA_CACHE_DIR;
#endif
srand(time(NULL));

Expand Down