| doAssignment(); | doAssignment(); | ||||
| } | } | ||||
| void BBWriter::put(char ch) { | |||||
| ch_ += 1; | |||||
| stream_ << ch; | |||||
| } | |||||
| void BBWriter::put(const std::string &str) { | |||||
| ch_ += str.size(); | |||||
| stream_ << str; | |||||
| } | |||||
| void BBWriter::newline() { | |||||
| ch_ = 1; | |||||
| line_ += 1; | |||||
| stream_ << '\n'; | |||||
| } | |||||
| void BBWriter::escape(const std::string &str) { | |||||
| put('"'); | |||||
| for (char ch: str) { | |||||
| if (ch == '$' || ch == '"' || ch == '\\') { | |||||
| put('\\'); | |||||
| } | |||||
| put(ch); | |||||
| } | |||||
| put('"'); | |||||
| } | |||||
| void BBWriter::write(const BBVariables &vars) { | |||||
| for (const auto &pair: vars) { | |||||
| put(pair.first); | |||||
| put(" :="); | |||||
| for (auto &val: pair.second) { | |||||
| if (ch_ >= 80) { | |||||
| newline(); | |||||
| put('\t'); | |||||
| } else { | |||||
| put(' '); | |||||
| } | |||||
| escape(val); | |||||
| } | |||||
| newline(); | |||||
| } | |||||
| } |
| EQUALS_PLUS, | EQUALS_PLUS, | ||||
| NONE, | NONE, | ||||
| }; | }; | ||||
| [[noreturn]] void error(std::string); | [[noreturn]] void error(std::string); | ||||
| Operator readOperator(); | Operator readOperator(); | ||||
| int ch_; | int ch_; | ||||
| std::istream &stream_; | std::istream &stream_; | ||||
| }; | }; | ||||
| class BBWriter { | |||||
| public: | |||||
| BBWriter(std::ostream &stream, int line = 1, int ch = 1): | |||||
| line_(line), ch_(ch), stream_(stream) {} | |||||
| void write(const BBVariables &vars); | |||||
| private: | |||||
| void put(char ch); | |||||
| void put(const std::string &str); | |||||
| void newline(); | |||||
| void escape(const std::string &str); | |||||
| int line_; | |||||
| int ch_; | |||||
| std::ostream &stream_; | |||||
| }; |
| return true; | return true; | ||||
| } | } | ||||
| std::string bbPath = this->bbPath(); | |||||
| std::string bbPath = this->bbPath(outDir); | |||||
| if (!sys::fileExists(bbPath)) { | if (!sys::fileExists(bbPath)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| { "command", command}, | { "command", command}, | ||||
| }; | }; | ||||
| // TODO: Write newCachedVars to bbPath() | |||||
| std::ofstream f(bbPath(outDir)); | |||||
| BBWriter writer(f); | |||||
| writer.write(newCachedVars); | |||||
| sys::mkdirp(dirPath); | sys::mkdirp(dirPath); | ||||
| sys::execute(command, nullptr, global::verbose >= 1); | sys::execute(command, nullptr, global::verbose >= 1); |
| 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 bbPath() { return path_ + ".bb"; } | |||||
| std::string bbPath(const std::string &outDir) { return outDir + '/' + path_ + ".bb"; } | |||||
| }; | }; |
| std::mutex mut; | std::mutex mut; | ||||
| std::condition_variable cond; | std::condition_variable cond; | ||||
| std::unique_lock<std::mutex> lock(mut); | |||||
| std::unique_lock<std::mutex> lock(mut, std::defer_lock); | |||||
| while (it != deps_.end()) { | while (it != deps_.end()) { | ||||
| lock.lock(); | lock.lock(); | ||||
| if (changed) { | if (changed) { |
| return true; | return true; | ||||
| } | } | ||||
| std::string bbPath = this->bbPath(); | |||||
| std::string bbPath = this->bbPath(outDir); | |||||
| if (!sys::fileExists(bbPath)) { | if (!sys::fileExists(bbPath)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| void LinkStep::doBuild(const std::string &outDir) { | void LinkStep::doBuild(const std::string &outDir) { | ||||
| logger::log("Link " + path_); | logger::log("Link " + path_); | ||||
| sys::execute(linkCommand(outDir), nullptr, global::verbose >= 1); | |||||
| std::vector<std::string> command = linkCommand(outDir); | |||||
| std::string dirPath = sys::dirname(outDir + '/' + path_); | |||||
| BBVariables newCachedVars = { | |||||
| { "command", command}, | |||||
| }; | |||||
| std::ofstream f(bbPath(outDir)); | |||||
| BBWriter writer(f); | |||||
| writer.write(newCachedVars); | |||||
| sys::mkdirp(dirPath); | |||||
| sys::execute(command, nullptr, global::verbose >= 1); | |||||
| } | } | ||||
| std::vector<std::string> &LinkStep::linkCommand(const std::string &outDir) { | std::vector<std::string> &LinkStep::linkCommand(const std::string &outDir) { |
| std::vector<std::string> linkCommand_; | std::vector<std::string> linkCommand_; | ||||
| std::vector<std::string> &linkCommand(const std::string &outDir); | std::vector<std::string> &linkCommand(const std::string &outDir); | ||||
| std::string bbPath() { return path_ + ".bb"; } | |||||
| std::string bbPath(const std::string &outDir) { return outDir + '/' + path_ + ".bb"; } | |||||
| }; | }; |
| #include <fstream> | #include <fstream> | ||||
| #include <stdexcept> | #include <stdexcept> | ||||
| #include <algorithm> | |||||
| #include <string.h> | #include <string.h> | ||||
| #include "sys.h" | #include "sys.h" | ||||
| sys::readDir(path, subpaths); | sys::readDir(path, subpaths); | ||||
| } | } | ||||
| std::sort(subpaths.begin(), subpaths.end()); | |||||
| for (auto &subpath: subpaths) { | for (auto &subpath: subpaths) { | ||||
| findDeps(path, subpath, *varsptr, deps); | findDeps(path, subpath, *varsptr, deps); | ||||
| } | } |