forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
68 lines (56 loc) · 1.77 KB
/
utils.cpp
File metadata and controls
68 lines (56 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif // NOMINMAX
#include <windows.h>
#endif
#include <fstream>
#include <bin/tpl/whereami/whereami.h>
#include <libasr/exception.h>
#include <lpython/utils.h>
#include <libasr/string_utils.h>
namespace LFortran {
void get_executable_path(std::string &executable_path, int &dirname_length)
{
int length;
length = wai_getExecutablePath(NULL, 0, &dirname_length);
if (length > 0) {
std::string path(length+1, '\0');
wai_getExecutablePath(&path[0], length, &dirname_length);
executable_path = path;
if (executable_path[executable_path.size()-1] == '\0') {
executable_path = executable_path.substr(0,executable_path.size()-1);
}
} else {
throw LFortranException("Cannot determine executable path.");
}
}
std::string get_runtime_library_dir()
{
char *env_p = std::getenv("LFORTRAN_RUNTIME_LIBRARY_DIR");
if (env_p) return env_p;
std::string path;
int dirname_length;
get_executable_path(path, dirname_length);
std::string dirname = path.substr(0,dirname_length);
if ( endswith(dirname, "src/bin")
|| endswith(dirname, "src\\bin")
|| endswith(dirname, "SRC\\BIN")) {
// Development version
return dirname + "/../runtime";
} else if (endswith(dirname, "src/lpython/tests") ||
endswith(to_lower(dirname), "src\\lpython\\tests")) {
// CTest Tests
return dirname + "/../../runtime";
} else {
// Installed version
return dirname + "/../share/lpython/lib";
}
}
std::string get_runtime_library_header_dir()
{
char *env_p = std::getenv("LFORTRAN_RUNTIME_LIBRARY_HEADER_DIR");
if (env_p) return env_p;
return get_runtime_library_dir() + "/impure";
}
}