Working config file also configures the build and git dir.
This commit is contained in:
parent
90f4f727ba
commit
eb6c7b0e33
6 changed files with 29 additions and 28 deletions
23
builder.cpp
23
builder.cpp
|
@ -19,13 +19,24 @@
|
|||
#include <thread> // for sleep_for
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace fmt;
|
||||
using namespace nlohmann;
|
||||
|
||||
#define BUF_MAX 1024
|
||||
|
||||
void Builder::run_build(GameEngine &game, const char* command) {
|
||||
Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) {
|
||||
ifstream infile(".tarpit.json");
|
||||
json config = json::parse(infile);
|
||||
|
||||
config["git_path"].template get_to<string>(git_path);
|
||||
config["build_cmd"].template get_to<string>(build_cmd);
|
||||
}
|
||||
|
||||
void Builder::run_build() {
|
||||
regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*");
|
||||
|
||||
char buffer[BUF_MAX]; // BUF_MAX is a define already?
|
||||
|
@ -37,7 +48,7 @@ void Builder::run_build(GameEngine &game, const char* command) {
|
|||
dbc::pre("simple test", [&]() { return stats_out.good(); });
|
||||
|
||||
// need to catch the error message when the command is bad
|
||||
FILE *build_out = popen(command, "r");
|
||||
FILE *build_out = popen(build_cmd.c_str(), "r");
|
||||
dbc::check(build_out != nullptr, "Failed to run command.");
|
||||
|
||||
game.start_round();
|
||||
|
@ -77,14 +88,14 @@ void Builder::run_build(GameEngine &game, const char* command) {
|
|||
if(rc == 0) {
|
||||
gui.build_works();
|
||||
} else {
|
||||
gui.build_failed(command);
|
||||
gui.build_failed(build_cmd);
|
||||
}
|
||||
|
||||
stats_out.close();
|
||||
dbc::post("a post test", [&]() { return !stats_out.is_open(); });
|
||||
}
|
||||
|
||||
void Builder::run(const char *git_path, const char *build_cmd) {
|
||||
void Builder::run() {
|
||||
git_repository* repo = nullptr;
|
||||
|
||||
try {
|
||||
|
@ -94,7 +105,7 @@ void Builder::run(const char *git_path, const char *build_cmd) {
|
|||
|
||||
git_libgit2_init();
|
||||
|
||||
int err = git_repository_open(&repo, git_path);
|
||||
int err = git_repository_open(&repo, git_path.c_str());
|
||||
dbc::check(err == 0, git_error_last()->message);
|
||||
|
||||
UpdateListener* listener = new UpdateListener(repo);
|
||||
|
@ -110,7 +121,7 @@ void Builder::run(const char *git_path, const char *build_cmd) {
|
|||
gui.building();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
gui.output(format("CHANGES! Running build {}", build_cmd));
|
||||
run_build(game, build_cmd);
|
||||
run_build();
|
||||
|
||||
if(game.is_dead()) {
|
||||
gui.output("!!!! YOU DIED! !!!! Learn to code luser.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue