Reworked the builder code to setup for more async running of the build.
This commit is contained in:
parent
bc3790efd3
commit
50c0ee3424
3 changed files with 44 additions and 27 deletions
6
Makefile
6
Makefile
|
@ -1,13 +1,15 @@
|
|||
|
||||
|
||||
all: build test
|
||||
|
||||
patch:
|
||||
cp .\patches\process.h .\subprojects\libgit2-1.8.1\src\util\process.h
|
||||
|
||||
build:
|
||||
meson compile -j 4 -C builddir
|
||||
|
||||
test:
|
||||
meson test -C builddir --suite turings_tarpit
|
||||
|
||||
# make an install for real maybe copy dll and .exe to dir and zip?
|
||||
install: build test
|
||||
powershell "cp builddir/escape_turings_tarpit.exe ."
|
||||
|
||||
|
|
54
builder.cpp
54
builder.cpp
|
@ -39,14 +39,12 @@ Builder::Builder(GUI &g, GameEngine &engine)
|
|||
FILE *start_command(string &build_cmd) {
|
||||
FILE *build_out = popen(build_cmd.c_str(), "r");
|
||||
dbc::check(build_out != nullptr, "Failed to run command.");
|
||||
|
||||
return build_out;
|
||||
}
|
||||
|
||||
string read_line(FILE *build_out, bool &done_out) {
|
||||
char buffer[BUF_MAX];
|
||||
char *res = fgets(buffer, BUF_MAX, build_out);
|
||||
//!!! exception if res == nullptr
|
||||
done_out = res == nullptr;
|
||||
|
||||
if(!done_out) {
|
||||
|
@ -56,33 +54,28 @@ string read_line(FILE *build_out, bool &done_out) {
|
|||
}
|
||||
}
|
||||
|
||||
void end_build(FILE *build_out, GUI &gui, string &build_cmd) {
|
||||
bool end_build(FILE *build_out, GUI &gui, string &build_cmd) {
|
||||
int rc = pclose(build_out);
|
||||
|
||||
if(rc == 0) {
|
||||
gui.build_works();
|
||||
} else {
|
||||
// BUG: make it not play two sounds
|
||||
gui.build_failed(true, build_cmd);
|
||||
}
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
void Builder::run_build(const string &line) {
|
||||
MatchResult Builder::parse_line(const string &line) {
|
||||
std::regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*");
|
||||
|
||||
std::smatch err;
|
||||
bool match = std::regex_match(line, err, err_re);
|
||||
|
||||
if(match) {
|
||||
string file_name = err[1].str();
|
||||
string lnumber = err[2].str();
|
||||
string col = err[3].str();
|
||||
string type = err[4].str();
|
||||
string message = err[5].str();
|
||||
|
||||
gui.output(format("HIT WITH {} @ {}:{}:{} {}", type, file_name, lnumber, col, message));
|
||||
|
||||
game.hit(type);
|
||||
return {
|
||||
.match = true,
|
||||
.file_name = err[1].str(),
|
||||
.lnumber = err[2].str(),
|
||||
.col = err[3].str(),
|
||||
.type = err[4].str(),
|
||||
.message = err[5].str(),
|
||||
};
|
||||
} else {
|
||||
return { .match = false };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,20 +123,33 @@ void Builder::run() {
|
|||
case BUILDING: {
|
||||
// check if there's output
|
||||
string line = read_line(build_out, build_done);
|
||||
|
||||
if(build_done) {
|
||||
end_build(build_out, gui, build_cmd);
|
||||
bool good = end_build(build_out, gui, build_cmd);
|
||||
|
||||
if(good) {
|
||||
gui.build_works();
|
||||
} else {
|
||||
// BUG: make it not play two sounds
|
||||
gui.build_failed(true, build_cmd);
|
||||
}
|
||||
|
||||
build_out = NULL;
|
||||
state = DONE;
|
||||
} else {
|
||||
// get the command line
|
||||
// run the build if it's available
|
||||
run_build(line);
|
||||
auto m = parse_line(line);
|
||||
|
||||
if(m.match) {
|
||||
gui.output(format("HIT WITH {} @ {}:{}:{} {}", m.type, m.file_name, m.lnumber, m.col, m.message));
|
||||
game.hit(m.type);
|
||||
}
|
||||
state = BUILDING;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DONE: {
|
||||
|
||||
game.end_round();
|
||||
|
||||
if(game.is_dead()) {
|
||||
|
|
11
builder.hpp
11
builder.hpp
|
@ -5,6 +5,15 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
struct MatchResult {
|
||||
bool match = false;
|
||||
string file_name = "";
|
||||
string lnumber = "";
|
||||
string col = "";
|
||||
string type = "";
|
||||
string message = "";
|
||||
};
|
||||
|
||||
class Builder {
|
||||
GUI gui;
|
||||
GameEngine game;
|
||||
|
@ -15,7 +24,7 @@ class Builder {
|
|||
|
||||
Builder(GUI &g, GameEngine &engine);
|
||||
|
||||
void run_build(const string &line);
|
||||
MatchResult parse_line(const string &line);
|
||||
|
||||
void run();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue