diff --git a/xtask/src/cargo.rs b/xtask/src/cargo.rs index 3bc45930421..8ebd2cd7cf7 100644 --- a/xtask/src/cargo.rs +++ b/xtask/src/cargo.rs @@ -113,6 +113,17 @@ impl CargoArgsBuilder { self } + #[must_use] + pub fn args(mut self, args: &[S]) -> Self + where + S: Clone + Into, + { + for arg in args { + self.args.push(arg.clone().into()); + } + self + } + pub fn add_arg(&mut self, arg: S) -> &mut Self where S: Into, diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 8da10fbd4bd..a2d46e663d6 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -42,6 +42,8 @@ enum Cli { GenerateEfuseFields(GenerateEfuseFieldsArgs), /// Lint all packages in the workspace with clippy LintPackages(LintPackagesArgs), + /// Attempt to publish the specified package. + Publish(PublishArgs), /// Run doctests for specified chip and package. #[clap(alias = "run-doc-test")] RunDocTests(ExampleArgs), @@ -151,6 +153,17 @@ struct LintPackagesArgs { fix: bool, } +#[derive(Debug, Args)] +struct PublishArgs { + /// Package to publish (performs a dry-run by default). + #[arg(value_enum)] + package: Package, + + /// Do not pass the `--dry-run` argument, actually try to publish. + #[arg(long)] + no_dry_run: bool, +} + #[derive(Debug, Args)] struct RunElfArgs { /// Which chip to run the tests for. @@ -164,9 +177,7 @@ struct RunElfArgs { // Application fn main() -> Result<()> { - env_logger::Builder::new() - .filter_module("xtask", log::LevelFilter::Info) - .init(); + env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); let workspace = std::env::current_dir()?; @@ -180,6 +191,7 @@ fn main() -> Result<()> { Cli::FmtPackages(args) => fmt_packages(&workspace, args), Cli::GenerateEfuseFields(args) => generate_efuse_src(&workspace, args), Cli::LintPackages(args) => lint_packages(&workspace, args), + Cli::Publish(args) => publish(&workspace, args), Cli::RunDocTests(args) => run_doc_tests(&workspace, args), Cli::RunElfs(args) => run_elfs(args), Cli::RunExample(args) => examples(&workspace, args, CargoAction::Run), @@ -770,6 +782,42 @@ fn lint_package(path: &Path, args: &[&str], fix: bool) -> Result<()> { xtask::cargo::run(&cargo_args, path) } +fn publish(workspace: &Path, args: PublishArgs) -> Result<()> { + let package_name = args.package.to_string(); + let package_path = xtask::windows_safe_path(&workspace.join(&package_name)); + + use Package::*; + let mut publish_args = match args.package { + Examples | HilTest => { + bail!( + "Invalid package '{}' specified, this package should not be published!", + args.package + ) + } + + EspBacktrace | EspHal | EspHalEmbassy | EspIeee802154 | EspLpHal | EspPrintln + | EspStorage | EspWifi | XtensaLxRt => vec!["--no-verify"], + + _ => vec![], + }; + + if !args.no_dry_run { + publish_args.push("--dry-run"); + } + + let builder = CargoArgsBuilder::default() + .subcommand("publish") + .args(&publish_args); + + let args = builder.build(); + log::debug!("{args:#?}"); + + // Execute `cargo publish --dry-run` from the package root: + xtask::cargo::run(&args, &package_path)?; + + Ok(()) +} + fn run_elfs(args: RunElfArgs) -> Result<()> { let mut failed: Vec = Vec::new(); for elf in fs::read_dir(&args.path)? {