Browse Source

file error checking

rebrand
Martin Dørum 3 years ago
parent
commit
8dfc567b30
7 changed files with 35 additions and 14 deletions
  1. 5
    4
      src/CompileStep.cc
  2. 2
    2
      src/LinkStep.cc
  3. 2
    2
      src/build.cc
  4. 1
    1
      src/main.cc
  5. 1
    5
      src/parallel.cc
  6. 20
    0
      src/sys.cc
  7. 4
    0
      src/sys.h

+ 5
- 4
src/CompileStep.cc View File

@@ -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()) {

+ 2
- 2
src/LinkStep.cc View File

@@ -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);


+ 2
- 2
src/build.cc View File

@@ -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);
}

+ 1
- 1
src/main.cc View File

@@ -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");

+ 1
- 5
src/parallel.cc View File

@@ -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);

+ 20
- 0
src/sys.cc View File

@@ -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;
}

}

+ 4
- 0
src/sys.h View File

@@ -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);

}

Loading…
Cancel
Save