| #include "DepNode.h" | #include "DepNode.h" | ||||
| #include "BXParser.h" | #include "BXParser.h" | ||||
| #include "sys.h" | |||||
| #include "toolchain.h" | #include "toolchain.h" | ||||
| class CompileStep: public DepNode { | class CompileStep: public DepNode { | ||||
| std::vector<std::string> compileCommand_; | std::vector<std::string> compileCommand_; | ||||
| std::vector<std::string> &compileCommand(const std::string &outDir); | 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"; | |||||
| } | |||||
| }; | }; |
| static thread_local std::unordered_set<std::string> mkdirp_set; | 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 fileInfo(const std::string &path) { | ||||
| FileInfo finfo; | FileInfo finfo; | ||||
| } | } | ||||
| }; | }; | ||||
| std::string sanitizePath(const std::string &path); | |||||
| FileInfo fileInfo(const std::string &path); | FileInfo fileInfo(const std::string &path); | ||||
| bool fileExists(const std::string &path); | bool fileExists(const std::string &path); | ||||
| void mkdirp(const std::string &path); | void mkdirp(const std::string &path); |
| } | } | ||||
| std::string objectFilePath(const std::string &path, const std::string &outDir) { | std::string objectFilePath(const std::string &path, const std::string &outDir) { | ||||
| return outDir + '/' + path + ".o"; | |||||
| return outDir + '/' + sys::sanitizePath(path) + ".o"; | |||||
| } | } | ||||
| std::string targetFilePath( | std::string targetFilePath( | ||||
| TargetType type, | TargetType type, | ||||
| const std::string &path, | const std::string &path, | ||||
| const std::string &outDir) { | const std::string &outDir) { | ||||
| std::string base = outDir + '/' + path; | |||||
| std::string base = outDir + '/' + sys::sanitizePath(path); | |||||
| switch (type) { | switch (type) { | ||||
| case TargetType::BINARY: | case TargetType::BINARY: |