From 84e7214c86d4014dd2376805487e46618a3e4de6 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Thu, 14 Nov 2024 10:40:56 +0100 Subject: [PATCH 1/3] Update and reorganize xtask dependencies --- xtask/Cargo.toml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 830a5fdace8..dd1c37e47e9 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -5,16 +5,16 @@ edition = "2021" publish = false [dependencies] -anyhow = "1.0.89" -basic-toml = "0.1.9" -chrono = "0.4.38" -clap = { version = "4.5.19", features = ["derive"] } -csv = "1.3.0" -env_logger = "0.11.5" -log = "0.4.22" -minijinja = "2.3.1" -semver = { version = "1.0.23", features = ["serde"] } -serde = { version = "1.0.210", features = ["derive"] } -strum = { version = "0.26.3", features = ["derive"] } -toml_edit = "0.22.22" +anyhow = "1.0.93" +basic-toml = "0.1.9" +chrono = "0.4.38" +clap = { version = "4.5.20", features = ["derive", "wrap_help"] } +csv = "1.3.1" +env_logger = "0.11.5" esp-metadata = { path = "../esp-metadata", features = ["clap"] } +log = "0.4.22" +minijinja = "2.5.0" +semver = { version = "1.0.23", features = ["serde"] } +serde = { version = "1.0.215", features = ["derive"] } +strum = { version = "0.26.3", features = ["derive"] } +toml_edit = "0.22.22" From 5daa43dc15822272397447f360431dbd1dc9ece3 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Thu, 14 Nov 2024 11:33:28 +0100 Subject: [PATCH 2/3] Add a publish subcommand (which performs a dry run by default) --- xtask/src/cargo.rs | 11 ++++++++++ xtask/src/main.rs | 54 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 3 deletions(-) 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)? { From fb7b20510957e7dbc456223b8cae7181e8462f9e Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Thu, 14 Nov 2024 03:12:26 -0800 Subject: [PATCH 3/3] Update xtask/src/main.rs Co-authored-by: Sergio Gasquez Arcos --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index a2d46e663d6..e38c825784d 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -812,7 +812,7 @@ fn publish(workspace: &Path, args: PublishArgs) -> Result<()> { let args = builder.build(); log::debug!("{args:#?}"); - // Execute `cargo publish --dry-run` from the package root: + // Execute `cargo publish` command from the package root: xtask::cargo::run(&args, &package_path)?; Ok(())