@@ -2,6 +2,7 @@ | |||
#include "DepNode.h" | |||
#include "BXParser.h" | |||
#include "sys.h" | |||
#include "toolchain.h" | |||
class CompileStep: public DepNode { | |||
@@ -32,5 +33,7 @@ private: | |||
std::vector<std::string> compileCommand_; | |||
std::vector<std::string> &compileCommand(const std::string &outDir); | |||
std::string confPath(const std::string &outDir) { return outDir + '/' + path_ + ".bx"; } | |||
std::string confPath(const std::string &outDir) { | |||
return outDir + '/' + sys::sanitizePath(path_) + ".bx"; | |||
} | |||
}; |
@@ -20,6 +20,27 @@ namespace sys { | |||
static thread_local std::unordered_set<std::string> mkdirp_set; | |||
std::string sanitizePath(const std::string &path) { | |||
std::string npath; | |||
size_t idx = 0; | |||
while (idx < path.size()) { | |||
if (idx >= path.size() - 2) { | |||
npath += path[idx++]; | |||
} else if (path[idx] == '.' && path[idx + 1] == '.' && path[idx + 2] == '/') { | |||
npath += "__parent__/"; | |||
idx += 3; | |||
} else { | |||
npath += path[idx++]; | |||
} | |||
} | |||
if (npath[npath.size() - 1] == '.' && npath[npath.size() - 2] == '.') { | |||
npath.replace(npath.size() - 2, 2, "__parent__"); | |||
} | |||
return npath; | |||
} | |||
FileInfo fileInfo(const std::string &path) { | |||
FileInfo finfo; | |||
@@ -17,6 +17,7 @@ struct FileInfo { | |||
} | |||
}; | |||
std::string sanitizePath(const std::string &path); | |||
FileInfo fileInfo(const std::string &path); | |||
bool fileExists(const std::string &path); | |||
void mkdirp(const std::string &path); |
@@ -103,14 +103,14 @@ static void parseWhitespaceSeparated( | |||
} | |||
std::string objectFilePath(const std::string &path, const std::string &outDir) { | |||
return outDir + '/' + path + ".o"; | |||
return outDir + '/' + sys::sanitizePath(path) + ".o"; | |||
} | |||
std::string targetFilePath( | |||
TargetType type, | |||
const std::string &path, | |||
const std::string &outDir) { | |||
std::string base = outDir + '/' + path; | |||
std::string base = outDir + '/' + sys::sanitizePath(path); | |||
switch (type) { | |||
case TargetType::BINARY: |