| @@ -36,7 +36,7 @@ bool CompileStep::checkHasChanged(const std::string &outDir) { | |||
| BBVariables cachedVariables; | |||
| try { | |||
| std::ifstream f(bbPath); | |||
| std::ifstream f = sys::ifstream(bbPath); | |||
| BBParser parser(f, BBParser::FLAG_NONE); | |||
| parser.parse(cachedVariables); | |||
| } catch (BBParseError &err) { | |||
| @@ -90,11 +90,12 @@ void CompileStep::doBuild(const std::string &outDir) { | |||
| { "command", command}, | |||
| }; | |||
| std::ofstream f(bbPath(outDir)); | |||
| sys::mkdirp(dirPath); | |||
| std::ofstream f = sys::ofstream(bbPath(outDir)); | |||
| BBWriter writer(f); | |||
| writer.write(newCachedVars); | |||
| sys::mkdirp(dirPath); | |||
| sys::execute(command, nullptr, global::verbose >= 1); | |||
| } | |||
| @@ -140,7 +141,7 @@ BBVariables &CompileStep::variables() { | |||
| return variables_; | |||
| } | |||
| std::ifstream f(path_); | |||
| std::ifstream f = sys::ifstream(path_); | |||
| BBParser parser(f, BBParser::FLAG_ONE_LINE); | |||
| while (f.good()) { | |||
| @@ -21,7 +21,7 @@ bool LinkStep::checkHasChanged(const std::string &outDir) { | |||
| BBVariables cachedVariables; | |||
| try { | |||
| std::ifstream f(bbPath); | |||
| std::ifstream f = sys::ifstream(bbPath); | |||
| BBParser parser(f, BBParser::FLAG_NONE); | |||
| parser.parse(cachedVariables); | |||
| } catch (BBParseError &err) { | |||
| @@ -51,7 +51,7 @@ void LinkStep::doBuild(const std::string &outDir) { | |||
| { "command", command}, | |||
| }; | |||
| std::ofstream f(bbPath(outDir)); | |||
| std::ofstream f = sys::ofstream(bbPath(outDir)); | |||
| BBWriter writer(f); | |||
| writer.write(newCachedVars); | |||
| @@ -63,7 +63,7 @@ static void findDeps( | |||
| subvars = variables; | |||
| varsptr = &subvars; | |||
| std::ifstream stream("build.bb"); | |||
| std::ifstream stream = sys::ifstream("build.bb"); | |||
| BBParser parser(stream, BBParser::FLAG_NONE); | |||
| parser.parse(subvars); | |||
| @@ -101,7 +101,7 @@ static std::string findTargetName(const BBVariables &variables) { | |||
| std::unique_ptr<DepNode> buildDepTree(const std::string &outDir, BBVariables variables) { | |||
| // Read config from file | |||
| if (sys::fileExists("build.bb")) { | |||
| std::ifstream stream("build.bb"); | |||
| std::ifstream stream = sys::ifstream("build.bb"); | |||
| BBParser parser(stream, BBParser::FLAG_NONE); | |||
| parser.parse(variables); | |||
| } | |||
| @@ -113,7 +113,7 @@ int main(int argc, char **argv) { | |||
| sys::mkdirp(outDir); | |||
| { | |||
| std::ofstream f(outDir + "/compile_commands.json"); | |||
| std::ofstream f = sys::ofstream(outDir + "/compile_commands.json"); | |||
| compdb::Writer writer(f); | |||
| root->writeCompDB(outDir, writer); | |||
| sys::symlink(outDir + "/compile_commands.json", "compile_commands.json"); | |||
| @@ -31,11 +31,7 @@ static void workerFunc(Worker *w) { | |||
| if (!w->running) | |||
| break; | |||
| try { | |||
| w->func(); | |||
| } catch (...) { | |||
| std::terminate(); | |||
| } | |||
| w->func(); | |||
| w->func = nullptr; | |||
| std::unique_lock<std::mutex> workers_lock(workers_mut); | |||
| @@ -205,4 +205,24 @@ std::string dirname(const std::string &path) { | |||
| 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; | |||
| } | |||
| } | |||
| @@ -2,6 +2,7 @@ | |||
| #include <string> | |||
| #include <vector> | |||
| #include <fstream> | |||
| namespace sys { | |||
| @@ -26,4 +27,7 @@ std::string cwd(); | |||
| void symlink(const std::string &from, const std::string &to); | |||
| std::string dirname(const std::string &path); | |||
| std::ofstream ofstream(const std::string &path); | |||
| std::ifstream ifstream(const std::string &path); | |||
| } | |||