Skip to content

Commit

Permalink
WIP: rework xtask
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Maslowski <[email protected]>
  • Loading branch information
orangecms committed Oct 23, 2024
1 parent 76e70fc commit c51fef4
Showing 1 changed file with 163 additions and 8 deletions.
171 changes: 163 additions & 8 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,126 @@ enum XCommand {
/// Build release version
#[arg(short, long, conflicts_with = "debug")]
release: bool,
/// Build debug version
#[arg(short, long, conflicts_with = "release")]
debug: bool,
/// Print commands being executed
#[arg(short, long)]
verbose: bool,
/// Target architecture
#[arg(short, long)]
arch: Arch,
/// Configuration file to use, CONFIG in <ARCH>/lib/config_<CONFIG>.toml
#[arg(short, long, default_value = "default")]
config: String,
},

/// Expand r9 macros
#[clap(verbatim_doc_comment)]
Expand {
/// Build release version
#[arg(short, long, conflicts_with = "debug")]
release: bool,
/// Build debug version
#[arg(short, long, conflicts_with = "release")]
debug: bool,
/// Print commands being executed
#[arg(short, long)]
verbose: bool,
/// Target architecture
#[arg(short, long)]
arch: Arch,
/// Configuration file to use, CONFIG in <ARCH>/lib/config_<CONFIG>.toml
#[arg(short, long, default_value = "default")]
config: String,
},

/// Emit r9 assembler
#[clap(verbatim_doc_comment)]
Kasm {
/// Build release version
#[arg(short, long, conflicts_with = "debug")]
release: bool,
/// Build debug version
#[arg(short, long, conflicts_with = "release")]
debug: bool,
/// Print commands being executed
#[arg(short, long)]
verbose: bool,
/// Target architecture
#[arg(short, long)]
arch: Arch,
/*
#[arg(index = 1, value_parser=clap_num::maybe_hex::<u32>)]
address: u32,
/// Configuration file to use, CONFIG in <ARCH>/lib/config_<CONFIG>.toml
#[arg(short, long, default_value = "default")]
config: String,
},

#[arg(index = 2, default_value_t = 4)]
count: u8,
*/
/// Build a multibootable r9 image
#[clap(verbatim_doc_comment)]
Dist {
/// Build release version
#[arg(short, long, conflicts_with = "debug")]
release: bool,
/// Build debug version
#[arg(short, long, conflicts_with = "release")]
debug: bool,
/// Print commands being executed
#[arg(short, long)]
verbose: bool,
/// Target architecture
#[arg(short, long)]
arch: Arch,
/// Configuration file to use, CONFIG in <ARCH>/lib/config_<CONFIG>.toml
#[arg(short, long, default_value = "default")]
config: String,
},

/// Run unit tests
#[clap(verbatim_doc_comment)]
Test {
/// Build release version
#[arg(short, long, conflicts_with = "debug")]
release: bool,
/// Build debug version
#[arg(short, long, conflicts_with = "release")]
debug: bool,
/// Print commands being executed
#[arg(short, long)]
verbose: bool,
/// Output messages as JSON
#[arg(short, long)]
json: bool,
},

/// Run clippy
#[clap(verbatim_doc_comment)]
Clippy {
/// Build release version
#[arg(short, long, conflicts_with = "debug")]
release: bool,
/// Build debug version
#[arg(short, long, conflicts_with = "release")]
debug: bool,
/// Print commands being executed
#[arg(short, long)]
verbose: bool,
/// Target architecture
#[arg(short, long)]
arch: Arch,
/// Configuration file to use, CONFIG in <ARCH>/lib/config_<CONFIG>.toml
#[arg(short, long, default_value = "default")]
config: String,
},

/// Run check
#[clap(verbatim_doc_comment)]
Check {
/// Print commands being executed
#[arg(short, long)]
verbose: bool,
/// Output messages as JSON
#[arg(short, long)]
json: bool,
},

/// Run r9 under QEMU
Expand All @@ -170,10 +275,17 @@ enum XCommand {
/// Wait for gdb connection on start
#[arg(short, long)]
gdb: bool,
/// Run with KVM
#[arg(short, long)]
kvm: bool,
/// Dump the DTB from QEMU to a file
#[arg(long, value_name = "path/to/foo.dtb")]
dump_dtb: Option<String>,
},

/// Cargo clean
#[clap(verbatim_doc_comment)]
Clean,
}

/// r9 build system
Expand All @@ -188,15 +300,57 @@ struct Cli {
fn main() {
let cmd = Cli::parse().cmd;
match cmd {
XCommand::Build { debug, release, arch } => {
XCommand::Build { debug, release, verbose, arch, config } => {
println!("{arch:?} {debug}/{release}");
}
XCommand::Expand { debug, release, verbose, arch, config } => {
println!("{arch:?} {debug}/{release}");
}
XCommand::Qemu { debug, release, verbose, arch, config, gdb, dump_dtb } => {
XCommand::Kasm { debug, release, verbose, arch, config } => {
println!("{arch:?} {debug}/{release}");
}
XCommand::Dist { debug, release, verbose, arch, config } => {
println!("{arch:?} {debug}/{release}");
}
XCommand::Test { debug, release, verbose, json } => {
println!("{json:?} {debug}/{release}");
}
XCommand::Clippy { debug, release, verbose, arch, config } => {
println!("{arch:?} {debug}/{release}");
}
XCommand::Check { verbose, json } => {
println!("{json:?} {verbose}");
}
XCommand::Qemu { debug, release, verbose, arch, config, gdb, kvm, dump_dtb } => {
println!("{arch:?} {config} {debug}/{release}/{verbose}");
println!("{gdb} {dump_dtb:?}");
let cfg = Configuration::load(format!(
"{}/{}/lib/config_{}.toml",
workspace().display(),
arch.to_string().to_lowercase(),
config
));
let profile = if release { Profile::Release } else { Profile::Debug };
let dump_dtb = dump_dtb.unwrap_or("".to_string());
let s1 = BuildStep { arch, config: cfg, verbose, profile };
let s2 = DistStep { arch, verbose, profile };
let cfg = Configuration::load(format!(
"{}/{}/lib/config_{}.toml",
workspace().display(),
arch.to_string().to_lowercase(),
config
));
let s3 =
QemuStep { arch, config: cfg, verbose, profile, kvm, dump_dtb, wait_for_gdb: gdb };
s1.run().and_then(|_| s2.run()).and_then(|_| s3.run()).unwrap();
return;
}
XCommand::Clean => {
println!("clean");
}
}

/*
let matches = clap::Command::new("xtask")
.version("0.1.0")
.author("The r9 Authors")
Expand Down Expand Up @@ -309,6 +463,7 @@ fn main() {
eprintln!("{e}");
process::exit(1);
}
*/
}

fn env_or(var: &str, default: &str) -> String {
Expand Down

0 comments on commit c51fef4

Please sign in to comment.