| BBVariables cachedVariables; | BBVariables cachedVariables; | ||||
| try { | try { | ||||
| std::ifstream f(bbPath); | |||||
| std::ifstream f = sys::ifstream(bbPath); | |||||
| BBParser parser(f, BBParser::FLAG_NONE); | BBParser parser(f, BBParser::FLAG_NONE); | ||||
| parser.parse(cachedVariables); | parser.parse(cachedVariables); | ||||
| } catch (BBParseError &err) { | } catch (BBParseError &err) { | ||||
| { "command", command}, | { "command", command}, | ||||
| }; | }; | ||||
| std::ofstream f(bbPath(outDir)); | |||||
| sys::mkdirp(dirPath); | |||||
| std::ofstream f = sys::ofstream(bbPath(outDir)); | |||||
| BBWriter writer(f); | BBWriter writer(f); | ||||
| writer.write(newCachedVars); | writer.write(newCachedVars); | ||||
| sys::mkdirp(dirPath); | |||||
| sys::execute(command, nullptr, global::verbose >= 1); | sys::execute(command, nullptr, global::verbose >= 1); | ||||
| } | } | ||||
| return variables_; | return variables_; | ||||
| } | } | ||||
| std::ifstream f(path_); | |||||
| std::ifstream f = sys::ifstream(path_); | |||||
| BBParser parser(f, BBParser::FLAG_ONE_LINE); | BBParser parser(f, BBParser::FLAG_ONE_LINE); | ||||
| while (f.good()) { | while (f.good()) { |
| BBVariables cachedVariables; | BBVariables cachedVariables; | ||||
| try { | try { | ||||
| std::ifstream f(bbPath); | |||||
| std::ifstream f = sys::ifstream(bbPath); | |||||
| BBParser parser(f, BBParser::FLAG_NONE); | BBParser parser(f, BBParser::FLAG_NONE); | ||||
| parser.parse(cachedVariables); | parser.parse(cachedVariables); | ||||
| } catch (BBParseError &err) { | } catch (BBParseError &err) { | ||||
| { "command", command}, | { "command", command}, | ||||
| }; | }; | ||||
| std::ofstream f(bbPath(outDir)); | |||||
| std::ofstream f = sys::ofstream(bbPath(outDir)); | |||||
| BBWriter writer(f); | BBWriter writer(f); | ||||
| writer.write(newCachedVars); | writer.write(newCachedVars); | ||||
| subvars = variables; | subvars = variables; | ||||
| varsptr = &subvars; | varsptr = &subvars; | ||||
| std::ifstream stream("build.bb"); | |||||
| std::ifstream stream = sys::ifstream("build.bb"); | |||||
| BBParser parser(stream, BBParser::FLAG_NONE); | BBParser parser(stream, BBParser::FLAG_NONE); | ||||
| parser.parse(subvars); | parser.parse(subvars); | ||||
| std::unique_ptr<DepNode> buildDepTree(const std::string &outDir, BBVariables variables) { | std::unique_ptr<DepNode> buildDepTree(const std::string &outDir, BBVariables variables) { | ||||
| // Read config from file | // Read config from file | ||||
| if (sys::fileExists("build.bb")) { | if (sys::fileExists("build.bb")) { | ||||
| std::ifstream stream("build.bb"); | |||||
| std::ifstream stream = sys::ifstream("build.bb"); | |||||
| BBParser parser(stream, BBParser::FLAG_NONE); | BBParser parser(stream, BBParser::FLAG_NONE); | ||||
| parser.parse(variables); | parser.parse(variables); | ||||
| } | } |
| sys::mkdirp(outDir); | sys::mkdirp(outDir); | ||||
| { | { | ||||
| std::ofstream f(outDir + "/compile_commands.json"); | |||||
| std::ofstream f = sys::ofstream(outDir + "/compile_commands.json"); | |||||
| compdb::Writer writer(f); | compdb::Writer writer(f); | ||||
| root->writeCompDB(outDir, writer); | root->writeCompDB(outDir, writer); | ||||
| sys::symlink(outDir + "/compile_commands.json", "compile_commands.json"); | sys::symlink(outDir + "/compile_commands.json", "compile_commands.json"); |
| if (!w->running) | if (!w->running) | ||||
| break; | break; | ||||
| try { | |||||
| w->func(); | |||||
| } catch (...) { | |||||
| std::terminate(); | |||||
| } | |||||
| w->func(); | |||||
| w->func = nullptr; | w->func = nullptr; | ||||
| std::unique_lock<std::mutex> workers_lock(workers_mut); | std::unique_lock<std::mutex> workers_lock(workers_mut); |
| return std::string(dir); | return std::string(dir); | ||||
| } | } | ||||
| std::ofstream ofstream(const std::string &path) { | |||||
| std::ofstream f; | |||||
| f.exceptions(std::ofstream::badbit); | |||||
| f.open(path); | |||||
| if (!f.good()) { | |||||
| throw std::system_error(errno, std::generic_category(), path); | |||||
| } | |||||
| return f; | |||||
| } | |||||
| std::ifstream ifstream(const std::string &path) { | |||||
| std::ifstream f; | |||||
| f.exceptions(std::ifstream::badbit); | |||||
| f.open(path); | |||||
| if (!f.good()) { | |||||
| throw std::system_error(errno, std::generic_category(), path); | |||||
| } | |||||
| return f; | |||||
| } | |||||
| } | } |
| #include <string> | #include <string> | ||||
| #include <vector> | #include <vector> | ||||
| #include <fstream> | |||||
| namespace sys { | namespace sys { | ||||
| void symlink(const std::string &from, const std::string &to); | void symlink(const std::string &from, const std::string &to); | ||||
| std::string dirname(const std::string &path); | std::string dirname(const std::string &path); | ||||
| std::ofstream ofstream(const std::string &path); | |||||
| std::ifstream ifstream(const std::string &path); | |||||
| } | } |