Skip to content

Commit

Permalink
Run: argument prop
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Dec 16, 2023
1 parent f89fd2e commit ee054b8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
22 changes: 11 additions & 11 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct ObjTargetInfo {
};

// Returns the directory where the Makefile is generated.
String emitMakefile(const Vec<String>& args) {
String emitMakefile(const String& profile) {
if (!fs::exists("src")) {
throw std::runtime_error("src directory not found");
}
Expand All @@ -188,18 +188,18 @@ String emitMakefile(const Vec<String>& args) {
}

bool debug = true;
if (!args.empty()) {
if (args[0] == "-d" || args[0] == "--debug") {
// Do nothing
} else if (args[0] == "-r" || args[0] == "--release") {
debug = false;
OUT_DIR = "poac-out/release";
} else {
throw std::runtime_error(
"invalid option: `" + args[0] + "`\n\n"
if (profile == "") {
// Do nothing
} else if (profile == "-d" || profile == "--debug") {
// Do nothing
} else if (profile == "-r" || profile == "--release") {
debug = false;
OUT_DIR = "poac-out/release";
} else {
throw std::runtime_error(
"invalid option: `" + profile + "`\n\n"
" run `poac help build` for a list of options"
);
}
}
if (!fs::exists(OUT_DIR)) {
fs::create_directories(OUT_DIR);
Expand Down
2 changes: 1 addition & 1 deletion src/BuildConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ static inline const HashSet<String> HEADER_FILE_EXTS{
".h", ".h++", ".hh", ".hpp", ".hxx"
};

String emitMakefile(const Vec<String>&);
String emitMakefile(const String&);
2 changes: 1 addition & 1 deletion src/Cmd/Build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <iostream>

int build(Vec<String> args) {
const String outDir = emitMakefile(args);
const String outDir = emitMakefile(args.empty() ? "" : args[0]);
return std::system(("make -C " + outDir).c_str());
}

Expand Down
19 changes: 17 additions & 2 deletions src/Cmd/Run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@
#include <iostream>

int run(Vec<String> args) {
const String outDir = emitMakefile(args);
String profile;
usize argsConsumed = 0;
if (!args.empty()) {
if (args[0] == "-d" || args[0] == "--debug" || args[0] == "-r"
|| args[0] == "--release") {
profile = args[0];
++argsConsumed;
}
}

const String outDir = emitMakefile(profile);
const int exitCode = std::system(("make -C " + outDir).c_str());
if (exitCode != EXIT_SUCCESS) {
Logger::error("Build failed with exit code ", exitCode);
return exitCode;
}

String projectArgs;
for (usize i = argsConsumed; i < args.size(); ++i) {
projectArgs += " " + args[i];
}

const String projectName = "poac"; // TODO: get from poac.toml
return std::system((outDir + "/" + projectName).c_str());
return std::system((outDir + "/" + projectName + projectArgs).c_str());
}

void runHelp() {
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <iostream>

int test(Vec<String> args) {
const String outDir = emitMakefile(args);
const String outDir = emitMakefile(args.empty() ? "" : args[0]);
return std::system(("make -C " + outDir + " test").c_str());
}

Expand Down

0 comments on commit ee054b8

Please sign in to comment.