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

27
src/lib.rs

@ -22,9 +22,9 @@ pub fn get_should_link(input: &mut Input) -> bool { @@ -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.
// Otherwise, link and run on the 3ds but do not run locally.
match input.cmd {
CargoCommand::Run => true,
CargoCommand::Test if !input.cargo_opts.contains(&"--no-run".to_string()) => {
input.cargo_opts.push("--no-run".to_string());
CargoCommand::Run(_) => true,
CargoCommand::Test(_) if !input.cargo_opts().contains(&"--no-run".to_string()) => {
// input.cargo_opts().push("--no-run".to_string());
true
}
_ => false,
@ -36,12 +36,12 @@ pub fn get_should_link(input: &mut Input) -> bool { @@ -36,12 +36,12 @@ pub fn get_should_link(input: &mut Input) -> bool {
pub fn get_message_format(input: &mut Input) -> String {
// Checks for a position within the args where '--message-format' is located
if let Some(pos) = input
.cargo_opts
.cargo_opts()
.iter()
.position(|s| s.starts_with("--message-format"))
{
// 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.
// 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 { @@ -49,15 +49,15 @@ pub fn get_message_format(input: &mut Input) -> String {
let format = if let Some((_, format)) = arg.split_once('=') {
format.to_string()
} else {
input.cargo_opts.remove(pos)
input.cargo_opts()[pos].clone() // TODO
};
// 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");
process::exit(1);
} else {
format
}
} else {
// Default to 'json-render-diagnostics'
@ -114,10 +114,11 @@ pub fn make_cargo_build_command( @@ -114,10 +114,11 @@ pub fn make_cargo_build_command(
let mut command = Command::new(cargo);
let cmd = match cmd {
CargoCommand::Build | CargoCommand::Run => "build",
CargoCommand::Test => "test",
CargoCommand::Build | CargoCommand::Run(_) => "build",
CargoCommand::Test(_) => "test",
CargoCommand::Check => "check",
CargoCommand::Clippy => "clippy",
CargoCommand::Doc => "doc",
};
command
@ -200,7 +201,7 @@ pub fn check_rust_version() { @@ -200,7 +201,7 @@ pub fn check_rust_version() {
/// Parses messages returned by the executed cargo command from [`build_elf`].
/// 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 {
let metadata = MetadataCommand::new()
.exec()
@ -249,7 +250,7 @@ pub fn get_metadata(messages: &[Message]) -> CTRConfig { @@ -249,7 +250,7 @@ pub fn get_metadata(messages: &[Message]) -> CTRConfig {
};
let author = match package.authors.as_slice() {
[name, ..] => name.to_owned(),
[name, ..] => name.clone(),
[] => String::from("Unspecified Author"), // as standard with the devkitPRO toolchain
};

13
src/main.rs

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

Loading…
Cancel
Save