diff --git a/Cargo.toml b/Cargo.toml index 6c83f03..54877c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,5 +31,7 @@ local-ip-address = "0.6.1" [lints.clippy] pedantic = { level = "deny", priority = -1 } +module_name_repetitions = "allow" +similar_names = "allow" unwrap_used = "deny" expect_used = "deny" diff --git a/deny.toml b/deny.toml index 371c8e2..954a64c 100644 --- a/deny.toml +++ b/deny.toml @@ -1,5 +1,9 @@ [graph] -targets = ["x86_64-unknown-linux-musl"] +targets = [ + "x86_64-pc-windows-msvc", + "x86_64-apple-darwin", + "x86_64-unknown-linux-gnu", +] all-features = true no-default-features = false @@ -15,17 +19,9 @@ yanked = "deny" [licenses] version = 2 private = { ignore = true } -allow = [ - "MIT", - "Apache-2.0", - "MPL-2.0", - "BSD-3-Clause", - "Zlib", -] +allow = ["MIT", "Apache-2.0", "MPL-2.0", "BSD-3-Clause", "Zlib"] confidence-threshold = 0.9 -exceptions = [ - { name = "unicode-ident", allow = ["Unicode-DFS-2016"] }, -] +exceptions = [{ name = "unicode-ident", allow = ["Unicode-DFS-2016"] }] [bans] multiple-versions = "deny" @@ -37,6 +33,10 @@ allow-wildcard-paths = true skip = [ { name = "syn", version = "1.0.109", reason = "local-ip-address" }, + { name = "windows-sys", version = "0.48.0", reason = "local-ip-address and colored" }, + { name = "windows_x86_64_msvc", version = "0.48.5", reason = "local-ip-address and colored" }, + { name = "windows_x86_64_gnu", version = "0.48.5", reason = "local-ip-address and colored" }, + { name = "windows-targets", version = "0.48.5", reason = "local-ip-address and colored" }, ] [sources] diff --git a/src/check.rs b/src/check.rs index 0d7d293..f2c8d7a 100644 --- a/src/check.rs +++ b/src/check.rs @@ -8,8 +8,8 @@ use anyhow::{anyhow, Context}; use log::error; use rustc_version::Channel; -pub fn check_rust_version() { - let rust_version = rustc_version::version_meta().unwrap(); +pub fn rust_version() -> anyhow::Result<()> { + let rust_version = rustc_version::version_meta()?; if rust_version.channel > Channel::Nightly { error!( @@ -23,6 +23,8 @@ pub fn check_rust_version() { ); process::exit(1); } + + Ok(()) } pub fn set_cargo_config_env() -> anyhow::Result<()> { diff --git a/src/commands/build.rs b/src/commands/build.rs index dd0d23b..d46da0c 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -6,7 +6,7 @@ use std::{ process::{Command, Stdio}, }; -use crate::ftp; +use crate::{check, ftp}; use anyhow::{bail, Context}; use cargo_metadata::{camino::Utf8PathBuf, Artifact, Message, Package}; use clap::{Args, Subcommand}; @@ -37,7 +37,7 @@ pub struct Build { #[arg(allow_hyphen_values = true)] #[arg(global = true)] #[arg(name = "CARGO_ARGS")] - build_args: Vec, + cargo_args: Vec, } #[derive(Subcommand, Debug)] @@ -131,6 +131,8 @@ impl ExecutableArtifact { impl Executor for Build { fn execute(&self) -> anyhow::Result<()> { + check::rust_version()?; + let ctx = BuildContext::new(self)?; match &self.cmd { @@ -154,7 +156,7 @@ impl Executor for Build { if args.update { let files = ctx.eboot_uploads(&artifacts)?; - ctx.upload(&files, &args.connection.clone().required()?)?; + upload(&files, &args.connection.clone().required()?)?; } if args.run { @@ -188,7 +190,7 @@ impl Executor for Build { } if !upload_files.is_empty() { - ctx.upload(&upload_files, &args.eboot.connection.clone().required()?)?; + upload(&upload_files, &args.eboot.connection.clone().required()?)?; } if args.eboot.run { @@ -240,7 +242,7 @@ impl<'a> BuildContext<'a> { .arg(VITA_TARGET) .arg("--message-format") .arg("json-render-diagnostics") - .args(&self.command.build_args) + .args(&self.command.cargo_args) .stdin(Stdio::inherit()) .stdout(Stdio::piped()) .stderr(Stdio::inherit()); @@ -399,7 +401,7 @@ impl<'a> BuildContext<'a> { let files = WalkDir::new(&assets) .into_iter() - .filter_map(|e| e.ok()) + .filter_map(std::result::Result::ok) .filter(|e| e.file_type().is_file()); for file in files { @@ -429,6 +431,7 @@ impl<'a> BuildContext<'a> { Ok(()) } + #[allow(clippy::unused_self)] fn vpk_uploads( &self, artifacts: &[ExecutableArtifact], @@ -472,24 +475,6 @@ impl<'a> BuildContext<'a> { .collect::>>() } - fn upload(&self, files: &[(Utf8PathBuf, String)], conn: &ConnectionArgs) -> anyhow::Result<()> { - if files.is_empty() { - return Ok(()); - } - - let mut ftp = ftp::connect(conn)?; - - for (src, dest) in files { - info!("{} {src} {} {dest}", "Uploading".blue(), "file to".blue()); - - let src = File::open(src).context("Unable to open source file")?; - ftp.put_file(dest, &mut BufReader::new(src)) - .context("Failed to upload file")?; - } - - Ok(()) - } - fn run(&self, artifacts: &[ExecutableArtifact], conn: &ConnectionArgs) -> anyhow::Result<()> { if let Some(art) = artifacts.last() { let title_id = art @@ -511,6 +496,24 @@ impl<'a> BuildContext<'a> { } } +fn upload(files: &[(Utf8PathBuf, String)], conn: &ConnectionArgs) -> anyhow::Result<()> { + if files.is_empty() { + return Ok(()); + } + + let mut ftp = ftp::connect(conn)?; + + for (src, dest) in files { + info!("{} {src} {} {dest}", "Uploading".blue(), "file to".blue()); + + let src = File::open(src).context("Unable to open source file")?; + ftp.put_file(dest, &mut BufReader::new(src)) + .context("Failed to upload file")?; + } + + Ok(()) +} + trait CommandExt { fn pass_env(&mut self, key: K, default: impl Fn() -> V) -> &mut Command where diff --git a/src/commands/coredump.rs b/src/commands/coredump.rs index 1feb179..fdf14fb 100644 --- a/src/commands/coredump.rs +++ b/src/commands/coredump.rs @@ -119,7 +119,7 @@ impl Executor for Coredump { bail!("vita-parse-core failed"); } } else { - warn!("{}", "No coredump files found.".yellow()) + warn!("{}", "No coredump files found.".yellow()); } } CoredumpCmd::Clean(args) => { @@ -135,7 +135,7 @@ impl Executor for Coredump { info!("{}: {file}", "Deleting file".blue()); match ftp.rm(file) { - Ok(_) => {} + Ok(()) => {} Err(FtpError::UnexpectedResponse(e)) if String::from_utf8_lossy(&e.body).contains("226 File deleted") => {} Err(e) => return Err(e).context("Unable to delete file"), @@ -143,7 +143,7 @@ impl Executor for Coredump { } if counter == 0 { - warn!("{}", "No coredump files found.".yellow()) + warn!("{}", "No coredump files found.".yellow()); } } } diff --git a/src/commands/logs.rs b/src/commands/logs.rs index 2904d20..f3cbb71 100644 --- a/src/commands/logs.rs +++ b/src/commands/logs.rs @@ -90,9 +90,10 @@ impl PrincessLogConfig { } fn serialize(&self) -> Vec { - let flags = match self.kernel_debug { - true => NLM_CONFIG_FLAGS_BIT_QAF_DEBUG_PRINTF, - false => 0, + let flags = if self.kernel_debug { + NLM_CONFIG_FLAGS_BIT_QAF_DEBUG_PRINTF + } else { + 0 }; let mut res = Vec::with_capacity(16); @@ -120,18 +121,24 @@ impl Logs { info!("{}", "Found existing config".blue()); match PrincessLogConfig::parse(&mut file) { - Ok(c) => match c.magic == MAGIC { - true => info!( - "{} {ip}:{port} {} {kdbg}", - "Existing config has address".yellow(), - "and kernel debug print is".yellow(), - ip = c.ip, - port = c.port, - kdbg = c.kernel_debug - ), - false => warn!("{}", "Existing config has invalid magic".red()), - }, - Err(err) => warn!("{}: {err}", "Failed to parse existing config".red()), + Ok(c) => { + if c.magic == MAGIC { + info!( + "{} {ip}:{port} {} {kdbg}", + "Existing config has address".yellow(), + "and kernel debug print is".yellow(), + ip = c.ip, + port = c.port, + kdbg = c.kernel_debug + ); + } else { + warn!("{}", "Existing config has invalid magic".red()); + } + } + + Err(err) => { + warn!("{}: {err}", "Failed to parse existing config".red()); + } }; } Err(err) => { @@ -191,7 +198,7 @@ impl Logs { break; } Ok(bytes_read) => { - print!("{}", String::from_utf8_lossy(&buffer[..bytes_read])) + print!("{}", String::from_utf8_lossy(&buffer[..bytes_read])); } Err(e) => { error!("{}: {}", "Error reading from client", e); diff --git a/src/commands/upload.rs b/src/commands/upload.rs index 8c40ed3..9b8226d 100644 --- a/src/commands/upload.rs +++ b/src/commands/upload.rs @@ -60,7 +60,10 @@ impl Executor for Upload { ) .context("Uploading file failed")?; } else if source.is_dir() { - for file in WalkDir::new(source).into_iter().filter_map(|e| e.ok()) { + for file in WalkDir::new(source) + .into_iter() + .filter_map(std::result::Result::ok) + { let source_path = file.path(); let destination = format!( @@ -97,7 +100,7 @@ impl Executor for Upload { if ftp.cwd(&destination).is_err() { info!("{} {destination}", "Creating directory".blue()); match ftp.mkdir(&destination) { - Ok(_) => {} + Ok(()) => {} Err(FtpError::UnexpectedResponse(e)) if String::from_utf8_lossy(&e.body) .starts_with("226 Directory created.") => {} diff --git a/src/ftp.rs b/src/ftp.rs index 64d9b12..954a707 100644 --- a/src/ftp.rs +++ b/src/ftp.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use anyhow::Context; use colored::Colorize; use log::info; @@ -8,7 +6,7 @@ use suppaftp::FtpStream; use crate::commands::ConnectionArgs; pub fn connect(conn: &ConnectionArgs) -> anyhow::Result { - let ip = conn.vita_ip.deref(); + let ip = &*conn.vita_ip; let port = conn.ftp_port; info!("{} {ip}:{port}", "Connecting to Vita FTP server".blue()); diff --git a/src/main.rs b/src/main.rs index deb691e..a1611da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ mod ftp; mod meta; mod nc; -use check::check_rust_version; use clap::Parser; use colored::Colorize; use commands::{Cargo, Executor}; @@ -26,11 +25,9 @@ fn main() { }) .init(); - check_rust_version(); - let Cargo::Input(input) = Cargo::parse(); match input.cmd.execute() { - Ok(_) => {} + Ok(()) => {} Err(e) => { error!("{}", format!("{e:?}").red()); std::process::exit(1); diff --git a/src/meta.rs b/src/meta.rs index 1287102..6b2b722 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -92,9 +92,9 @@ pub struct PackageMetadata { impl Default for PackageMetadata { fn default() -> Self { Self { - title_id: Default::default(), - title_name: Default::default(), - assets: Default::default(), + title_id: None, + title_name: None, + assets: None, build_std: default_build_std(), vita_strip_flags: default_vita_strip_flags(), vita_make_fself_flags: default_vita_make_fself_flags(), @@ -112,7 +112,7 @@ pub fn parse_crate_metadata( let pkg = match artifact { Some(artifact) => meta.packages.iter().find(|p| p.id == artifact.package_id), - None => meta.workspace_default_packages().first().cloned(), + None => meta.workspace_default_packages().first().copied(), }; if let Some(pkg) = pkg { @@ -126,5 +126,9 @@ pub fn parse_crate_metadata( } } - Ok((Default::default(), pkg.cloned(), meta.target_directory)) + Ok(( + PackageMetadata::default(), + pkg.cloned(), + meta.target_directory, + )) } diff --git a/src/nc.rs b/src/nc.rs index b79e3e2..72167c1 100644 --- a/src/nc.rs +++ b/src/nc.rs @@ -12,7 +12,7 @@ pub fn nc(ip: &str, port: u16, command: &str) -> anyhow::Result<()> { let mut stream = TcpStream::connect((ip, port)).context("Unable to connect to command server")?; - let command = format!("{}\n", command); + let command = format!("{command}\n"); stream .write_all(command.as_bytes()) .context("Unable to write to TCP socket")?;