diff --git a/Makefile b/Makefile index b19b0df6..b8440c56 100644 --- a/Makefile +++ b/Makefile @@ -144,10 +144,14 @@ ktest: initramfs $(CARGO_OSDK) (cd $$dir && cargo osdk test) || exit 1; \ done -.PHONY: docs -docs: - @cargo doc # Build Rust docs - @echo "" # Add a blank line +docs: $(CARGO_OSDK) + @for dir in $(NON_OSDK_CRATES); do \ + (cd $$dir && cargo doc --no-deps) || exit 1; \ + done + @for dir in $(OSDK_CRATES); do \ + (cd $$dir && cargo osdk doc --no-deps) || exit 1; \ + done + @echo "" # Add a blank line @cd docs && mdbook build # Build mdBook .PHONY: format @@ -169,7 +173,7 @@ check: $(CARGO_OSDK) (cd $$dir && cargo clippy -- -D warnings) || exit 1; \ done @for dir in $(OSDK_CRATES); do \ - (cd $$dir && cargo osdk clippy) || exit 1; \ + (cd $$dir && cargo osdk clippy -- -- -D warnings) || exit 1; \ done .PHONY: clean diff --git a/osdk/src/cli.rs b/osdk/src/cli.rs index 14e7a1c5..73ca5d56 100644 --- a/osdk/src/cli.rs +++ b/osdk/src/cli.rs @@ -6,8 +6,8 @@ use clap::{crate_version, Args, Parser}; use crate::{ commands::{ - execute_build_command, execute_check_command, execute_clippy_command, execute_new_command, - execute_run_command, execute_test_command, + execute_build_command, execute_forwarded_command, execute_new_command, execute_run_command, + execute_test_command, }, config_manager::{ boot::{BootLoader, BootProtocol}, @@ -37,8 +37,9 @@ pub fn main() { let test_config = TestConfig::parse(test_args); execute_test_command(&test_config); } - OsdkSubcommand::Check => execute_check_command(), - OsdkSubcommand::Clippy => execute_clippy_command(), + OsdkSubcommand::Check(args) => execute_forwarded_command("check", &args.args), + OsdkSubcommand::Clippy(args) => execute_forwarded_command("clippy", &args.args), + OsdkSubcommand::Doc(args) => execute_forwarded_command("doc", &args.args), } } @@ -68,10 +69,22 @@ pub enum OsdkSubcommand { Run(RunArgs), #[command(about = "Execute kernel mode unit test by starting a VMM")] Test(TestArgs), - #[command(about = "Analyze the current package and report errors")] - Check, - #[command(about = "Check the current package and catch common mistakes")] - Clippy, + #[command(about = "Check a local package and all of its dependencies for errors")] + Check(ForwardedArguments), + #[command(about = "Checks a package to catch common mistakes and improve your Rust code")] + Clippy(ForwardedArguments), + #[command(about = "Build a package's documentation")] + Doc(ForwardedArguments), +} + +#[derive(Debug, Parser)] +pub struct ForwardedArguments { + #[arg( + help = "The full set of Cargo arguments", + trailing_var_arg = true, + allow_hyphen_values = true + )] + pub args: Vec, } #[derive(Debug, Parser)] diff --git a/osdk/src/commands/check.rs b/osdk/src/commands/check.rs deleted file mode 100644 index c27c6510..00000000 --- a/osdk/src/commands/check.rs +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 - -use std::process; - -use super::util::{cargo, COMMON_CARGO_ARGS}; -use crate::{error::Errno, error_msg}; - -pub fn execute_check_command() { - let mut command = cargo(); - command - .arg("check") - .arg("--target") - .arg("x86_64-unknown-none"); - command.args(COMMON_CARGO_ARGS); - let status = command.status().unwrap(); - if !status.success() { - error_msg!("Check failed"); - process::exit(Errno::ExecuteCommand as _); - } -} diff --git a/osdk/src/commands/clippy.rs b/osdk/src/commands/clippy.rs deleted file mode 100644 index f873c191..00000000 --- a/osdk/src/commands/clippy.rs +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 - -use std::process; - -use super::util::{cargo, COMMON_CARGO_ARGS}; -use crate::{error::Errno, error_msg}; - -pub fn execute_clippy_command() { - let mut command = cargo(); - command - .arg("clippy") - .arg("-h") - .arg("--target") - .arg("x86_64-unknown-none") - .args(COMMON_CARGO_ARGS); - info!("Running `cargo clippy -h`"); - let output = command.output().unwrap(); - if !output.status.success() { - let stderr = String::from_utf8_lossy(&output.stderr); - eprintln!("{}", &stderr); - error_msg!("Cargo clippy failed"); - process::exit(Errno::ExecuteCommand as _); - } - - let mut command = cargo(); - command - .arg("clippy") - .arg("--target") - .arg("x86_64-unknown-none") - .args(COMMON_CARGO_ARGS); - // TODO: Add support for custom clippy args using OSDK commandline rather than hardcode it. - command.args(["--", "-D", "warnings"]); - let status = command.status().unwrap(); - if !status.success() { - error_msg!("Cargo clippy failed"); - process::exit(Errno::ExecuteCommand as _); - } -} diff --git a/osdk/src/commands/mod.rs b/osdk/src/commands/mod.rs index 82977bf6..426e2904 100644 --- a/osdk/src/commands/mod.rs +++ b/osdk/src/commands/mod.rs @@ -3,14 +3,25 @@ //! This module contains subcommands of cargo-osdk. mod build; -mod check; -mod clippy; mod new; mod run; mod test; mod util; pub use self::{ - build::execute_build_command, check::execute_check_command, clippy::execute_clippy_command, - new::execute_new_command, run::execute_run_command, test::execute_test_command, + build::execute_build_command, new::execute_new_command, run::execute_run_command, + test::execute_test_command, }; + +/// Execute the forwarded cargo command with args containing the subcommand and its arguments. +pub fn execute_forwarded_command(subcommand: &str, args: &Vec) -> ! { + let mut cargo = util::cargo(); + cargo + .arg(subcommand) + .args(util::COMMON_CARGO_ARGS) + .arg("--target") + .arg("x86_64-unknown-none") + .args(args); + let status = cargo.status().expect("Failed to execute cargo"); + std::process::exit(status.code().unwrap_or(1)); +}