25 #include <boost/property_tree/ptree.hpp> 26 #include <boost/property_tree/xml_parser.hpp> 34 #elif defined(__linux__) 37 #elif defined(__APPLE__) 38 #include <mach-o/dyld.h> 42 const auto empty_path = filesys::path();
54 filesys::path p = output_prefix;
70 if (GetCurrentDir().compare(GetRootDir()) != 0) {
72 logger(
"Current working dir not install root!");
76 if (GetConfigDir().empty()) {
78 logger(
"Config dir not present in install root!");
82 if (GetDataDir().empty()) {
84 logger(
"Data dir not present in install root!");
88 if (GetTestsDir().empty()) {
90 logger(
"Tests dir not present in install root!");
98 static Dirs dirs = Initialize();
108 char exePath[MAX_PATH];
109 HMODULE hModule = GetModuleHandle(NULL);
110 if (GetModuleFileName(NULL, exePath,
sizeof(exePath)) != 0)
113 dirs.
m_exec_path = canonical(filesys::absolute(exePath));
115 #elif defined(__linux__) 116 char exePath[PATH_MAX];
117 auto size =
static_cast<std::size_t
>(::readlink(
"/proc/self/exe", exePath,
sizeof(exePath)));
118 if (size > 0 && size <
sizeof(exePath)) {
119 exePath[size] =
'\0';
120 dirs.
m_exec_path = canonical(filesys::absolute(exePath));
122 #elif defined(__APPLE__) 123 char exePath[PATH_MAX];
124 uint32_t size =
sizeof(exePath);
125 if (_NSGetExecutablePath(exePath, &size) == 0) {
126 dirs.
m_exec_path = canonical(filesys::absolute(exePath));
133 filesys::path exec_dir = dirs.
m_exec_path.parent_path();
136 if (exec_dir.filename().string() ==
"MacOS") {
145 if (
ToLower(exec_dir.filename().string()) ==
"debug" ||
146 ToLower(exec_dir.filename().string()) ==
"release") {
152 dirs.
m_root_dir = exec_dir.parent_path().parent_path();
155 if (exec_dir.filename().string() !=
"bin") {
172 dirs.
m_current_dir = filesys::absolute(filesys::current_path());
195 const auto n = s.find(
'/');
196 return n != string::npos;
201 if (std::regex_match(s, std::regex(
".*/$"))) {
203 s = std::regex_replace(s, std::regex(
"\\/$"),
"");
205 return filesys::create_directories(filesys::current_path() / s);
211 if (!exists(f_p) || !is_regular_file(f_p)) {
212 const string s =
"FileSys::ReadPtreeFile> Abort! File " + f_p.string() +
" not present.";
214 throw runtime_error(s);
217 read_xml(canonical(f_p).
string(), ret, xml_parser::trim_whitespace);
218 }
catch (xml_parser_error& e) {
219 const string s =
"FileSys::ReadPtreeFile> Abort! Error reading " + f_p.string();
221 throw runtime_error(s);
232 write_xml(f_p.string(), pt, std::locale(), xml_writer_make_settings<ptree::key_type>(
' ', 8));
233 }
catch (xml_parser_error& e) {
234 const string s =
"FileSys::ReadPtreeFile> Abort! Error reading " + f_p.string();
236 throw runtime_error(s);
242 WritePtreeFile(filesys::absolute(f_n), pt);
static Dirs Initialize()
Initialize all paths.
filesys::path m_config_dir
static bool CreateDirectory(std::string s)
Create a directory relative to the current directory with the given path, returns if it was succesful...
static boost::property_tree::ptree ReadPtreeFile(const filesys::path &f_p)
Read ptree from file at path.
static Dirs & Get()
Return paths.
filesys::path m_exec_path
static bool CheckInstallEnv(std::function< void(const std::string &)> logger=std::function< void(const std::string &)>())
Verify that current dir is root dir and all install dirs are present.
static filesys::path BuildPath(const std::string &output_prefix, const std::string &filename)
Interpret prefix (directory or filename prefix) and return appropriate path.
filesys::path m_tests_dir
static void WritePtreeFile(const filesys::path &f_p, const boost::property_tree::ptree &pt)
Write ptree to file at path.
static bool IsDirectoryString(const std::string &s)
String represents a directory path (relative or absolute) iff it contains at least one / (may be a tr...
Miscellaneous string utilities.
Interface for install directory queries.
Namespace for the simulator and related classes.
filesys::path m_current_dir
Using this to avoid global variables & their initialization.
std::string ToLower(const std::string &source)
Builds a string with lower case characters only.