Browse Source

Fix some build errors for testing

pull/26/head
Ian Chamberlain 2 years ago
parent
commit
c2560622e8
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 19
      src/command.rs
  2. 27
      src/lib.rs
  3. 13
      src/main.rs

19
src/command.rs

@ -5,14 +5,14 @@ use clap::{Args, Parser, Subcommand};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(name = "cargo")] #[command(name = "cargo")]
#[command(bin_name = "cargo")] #[command(bin_name = "cargo")]
pub enum Command { pub enum Cargo {
#[command(name = "3ds")] #[command(name = "3ds")]
Root(Root), Input(Input),
} }
#[derive(Args, Debug)] #[derive(Args, Debug)]
#[command(version, about)] #[command(version, about)]
pub struct Root { pub struct Input {
/// The cargo command to run. This command will be forwarded to the real /// The cargo command to run. This command will be forwarded to the real
/// `cargo` with the appropriate arguments for a 3DS executable. /// `cargo` with the appropriate arguments for a 3DS executable.
#[command(subcommand)] #[command(subcommand)]
@ -20,7 +20,7 @@ pub struct Root {
/// Don't actually run any commands, just echo them to the console. /// Don't actually run any commands, just echo them to the console.
/// This is mostly intended for testing. /// This is mostly intended for testing.
#[arg(hide = true)] #[arg(long, hide = true)]
pub dry_run: bool, pub dry_run: bool,
/// Pass additional options through to the `cargo` command. /// Pass additional options through to the `cargo` command.
@ -57,9 +57,10 @@ pub enum CargoCommand {
/// This can be used with `--test` for integration tests, or `--lib` for /// This can be used with `--test` for integration tests, or `--lib` for
/// unit tests (which require a custom test runner). /// unit tests (which require a custom test runner).
Test(Test), Test(Test),
//
// TODO: this doesn't seem to work for some reason... // TODO: this doesn't seem to work for some reason...
#[command(external_subcommand)] // #[command(external_subcommand)]
Other(Vec<String>), // Other(Vec<String>),
} }
#[derive(Args, Debug)] #[derive(Args, Debug)]
@ -97,14 +98,14 @@ pub struct Run {
pub retries: Option<usize>, pub retries: Option<usize>,
} }
impl Root { impl Input {
/// Get the args to be passed to the executable itself (not `cargo`). /// Get the args to be passed to the executable itself (not `cargo`).
pub fn cargo_options(&self) -> &[String] { pub fn cargo_opts(&self) -> &[String] {
self.split_args().0 self.split_args().0
} }
/// Get the args to be passed to the executable itself (not `cargo`). /// Get the args to be passed to the executable itself (not `cargo`).
pub fn executable_args(&self) -> &[String] { pub fn exe_args(&self) -> &[String] {
self.split_args().1 self.split_args().1
} }

27
src/lib.rs

@ -22,9 +22,9 @@ pub fn get_should_link(input: &mut Input) -> bool {
// When running compile only commands, don't link the executable to the 3ds. // When running compile only commands, don't link the executable to the 3ds.
// Otherwise, link and run on the 3ds but do not run locally. // Otherwise, link and run on the 3ds but do not run locally.
match input.cmd { match input.cmd {
CargoCommand::Run => true, CargoCommand::Run(_) => true,
CargoCommand::Test if !input.cargo_opts.contains(&"--no-run".to_string()) => { CargoCommand::Test(_) if !input.cargo_opts().contains(&"--no-run".to_string()) => {
input.cargo_opts.push("--no-run".to_string()); // input.cargo_opts().push("--no-run".to_string());
true true
} }
_ => false, _ => false,
@ -36,12 +36,12 @@ pub fn get_should_link(input: &mut Input) -> bool {
pub fn get_message_format(input: &mut Input) -> String { pub fn get_message_format(input: &mut Input) -> String {
// Checks for a position within the args where '--message-format' is located // Checks for a position within the args where '--message-format' is located
if let Some(pos) = input if let Some(pos) = input
.cargo_opts .cargo_opts()
.iter() .iter()
.position(|s| s.starts_with("--message-format")) .position(|s| s.starts_with("--message-format"))
{ {
// Remove the arg from list // Remove the arg from list
let arg = input.cargo_opts.remove(pos); let arg = input.cargo_opts()[pos].clone(); // TODO
// Allows for usage of '--message-format=<format>' and also using space separation. // Allows for usage of '--message-format=<format>' and also using space separation.
// Check for a '=' delimiter and use the second half of the split as the format, // Check for a '=' delimiter and use the second half of the split as the format,
@ -49,15 +49,15 @@ pub fn get_message_format(input: &mut Input) -> String {
let format = if let Some((_, format)) = arg.split_once('=') { let format = if let Some((_, format)) = arg.split_once('=') {
format.to_string() format.to_string()
} else { } else {
input.cargo_opts.remove(pos) input.cargo_opts()[pos].clone() // TODO
}; };
// Non-json formats are not supported so the executable exits. // Non-json formats are not supported so the executable exits.
if !format.starts_with("json") { if format.starts_with("json") {
format
} else {
eprintln!("error: non-JSON `message-format` is not supported"); eprintln!("error: non-JSON `message-format` is not supported");
process::exit(1); process::exit(1);
} else {
format
} }
} else { } else {
// Default to 'json-render-diagnostics' // Default to 'json-render-diagnostics'
@ -114,10 +114,11 @@ pub fn make_cargo_build_command(
let mut command = Command::new(cargo); let mut command = Command::new(cargo);
let cmd = match cmd { let cmd = match cmd {
CargoCommand::Build | CargoCommand::Run => "build", CargoCommand::Build | CargoCommand::Run(_) => "build",
CargoCommand::Test => "test", CargoCommand::Test(_) => "test",
CargoCommand::Check => "check", CargoCommand::Check => "check",
CargoCommand::Clippy => "clippy", CargoCommand::Clippy => "clippy",
CargoCommand::Doc => "doc",
}; };
command command
@ -200,7 +201,7 @@ pub fn check_rust_version() {
/// Parses messages returned by the executed cargo command from [`build_elf`]. /// Parses messages returned by the executed cargo command from [`build_elf`].
/// The returned [`CTRConfig`] is then used for further building in and execution /// The returned [`CTRConfig`] is then used for further building in and execution
/// in [`build_smdh`], ['build_3dsx'], and [`link`]. /// in [`build_smdh`], [`build_3dsx`], and [`link`].
pub fn get_metadata(messages: &[Message]) -> CTRConfig { pub fn get_metadata(messages: &[Message]) -> CTRConfig {
let metadata = MetadataCommand::new() let metadata = MetadataCommand::new()
.exec() .exec()
@ -249,7 +250,7 @@ pub fn get_metadata(messages: &[Message]) -> CTRConfig {
}; };
let author = match package.authors.as_slice() { let author = match package.authors.as_slice() {
[name, ..] => name.to_owned(), [name, ..] => name.clone(),
[] => String::from("Unspecified Author"), // as standard with the devkitPRO toolchain [] => String::from("Unspecified Author"), // as standard with the devkitPRO toolchain
}; };

13
src/main.rs

@ -1,4 +1,3 @@
use cargo_3ds::cmd_clap4::Command;
use cargo_3ds::command::Cargo; use cargo_3ds::command::Cargo;
use cargo_3ds::{ use cargo_3ds::{
build_3dsx, build_elf, build_smdh, check_rust_version, get_message_format, get_metadata, build_3dsx, build_elf, build_smdh, check_rust_version, get_message_format, get_metadata,
@ -8,15 +7,13 @@ use clap::Parser;
use std::process; use std::process;
fn main() { fn main() {
let Command::Root(cmd) = cargo_3ds::cmd_clap4::Command::parse(); check_rust_version();
dbg!(&cmd); let Cargo::Input(mut input) = Cargo::parse();
dbg!(cmd.cargo_options());
dbg!(cmd.executable_args());
// check_rust_version(); dbg!(&input);
dbg!(input.cargo_opts());
// let Cargo::Input(mut input) = Cargo::parse(); dbg!(input.exe_args());
// let should_link = get_should_link(&mut input); // let should_link = get_should_link(&mut input);
// let message_format = get_message_format(&mut input); // let message_format = get_message_format(&mut input);

Loading…
Cancel
Save