Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build only command for debugging support #69

Open
wants to merge 1 commit into
base: v0.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions cargo-aoc/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl AOCApp {
Ok(())
}

pub fn execute_default(&self, args: &ArgMatches) -> Result<(), Box<dyn error::Error>> {
fn generate_subproject(&self, args: &ArgMatches) -> Result<(), Box<dyn error::Error>> {
let day: Option<Day> = args
.value_of("day")
.map(|d| d.parse().expect("Failed to parse day"));
Expand Down Expand Up @@ -221,8 +221,12 @@ impl AOCApp {
fs::write("target/aoc/aoc-autobuild/src/main.rs", &main_content)
.expect("failed to write src/main.rs");

Ok(())
}

fn cargo_exec(args: &[&str]) {
let status = process::Command::new("cargo")
.args(&["run", "--release"])
.args(args)
.current_dir("target/aoc/aoc-autobuild")
.spawn()
.expect("Failed to run cargo")
Expand All @@ -232,6 +236,18 @@ impl AOCApp {
if !status.success() {
process::exit(status.code().unwrap_or(-1));
}
}

pub fn execute_build(&self, args: &ArgMatches) -> Result<(), Box<dyn error::Error>> {
self.generate_subproject(args)?;
Self::cargo_exec(&["build"]);

Ok(())
}

pub fn execute_default(&self, args: &ArgMatches) -> Result<(), Box<dyn error::Error>> {
self.generate_subproject(args)?;
Self::cargo_exec(&["run", "--release"]);

Ok(())
}
Expand Down
32 changes: 30 additions & 2 deletions cargo-aoc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ fn main() {
.takes_value(true),
),
)
.subcommand(
SubCommand::with_name("build")
.about("Builds the subproject for debugging purposes")
.arg(
Arg::with_name("day")
.short("d")
.help("Specifies the day. Defaults to today's date.")
.takes_value(true),
)
.arg(
Arg::with_name("year")
.short("y")
.help("Specifies the year. Defaults to the current year.")
.takes_value(true),
)
.arg(
Arg::with_name("input")
.short("i")
.help("Use an alternate input file.")
.takes_value(true),
)
)
.get_matches();

// Creates an AOCApp that we'll use to launch actions (commands)
Expand All @@ -122,14 +144,20 @@ fn main() {
("input", Some(m)) => app.execute_input(&m),
("bench", Some(m)) => {
if let Err(e) = app.execute_bench(&m) {
eprintln!("An error occurs : {}", e.description());
eprintln!("An error occurs : {}", e);
std::process::exit(-1);
}
}
("build", Some(m)) => {
if let Err(e) = app.execute_build(&m) {
eprintln!("An error occurs : {}", e);
std::process::exit(-1);
}
}
(c, Some(_)) => panic!("Unknown command `{}`", c),
_ => {
if let Err(e) = app.execute_default(&matches) {
eprintln!("An error occurs : {}", e.description());
eprintln!("An error occurs : {}", e);
std::process::exit(-1);
}
}
Expand Down