diff --git a/README.md b/README.md index 6772c251de..e6947f4d3b 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,12 @@ The `xtask` package is a binary application, based on the workflow outlined by [ Usage: xtask Commands: + html Generate a webpage for a given SVD file patch Patch the specified package(s)'s SVD file generate Generate the specified package(s) build Build the specified package(s) bump-version Bump the version of the specified package(s) + publish Published the specified package(s) help Print this message or the help of the given subcommand(s) Options: diff --git a/xtask/Cargo.lock b/xtask/Cargo.lock index 7227bd8899..dcc6dafc2c 100644 --- a/xtask/Cargo.lock +++ b/xtask/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" dependencies = [ "anstyle", "anstyle-parse", @@ -42,9 +42,9 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3a318f1f38d2418400f8209655bfd825785afd25aa30bb7ba6cc792e4596748" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ "windows-sys 0.52.0", ] @@ -121,9 +121,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.10" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272" +checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" dependencies = [ "clap_builder", "clap_derive", @@ -131,9 +131,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.9" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1" +checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" dependencies = [ "anstream", "anstyle", @@ -150,7 +150,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -191,9 +191,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" dependencies = [ "cfg-if", "crossbeam-epoch", @@ -202,22 +202,21 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.15" +version = "0.9.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "2d2fe95351b870527a5d09bf563ed3c97c0cffb87cf1c78a591bf48bb218d9aa" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", "memoffset", - "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" dependencies = [ "cfg-if", ] @@ -457,9 +456,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kstring" @@ -473,9 +472,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.150" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "linked-hash-map" @@ -528,7 +527,7 @@ checksum = "fc2fb41a9bb4257a3803154bdf7e2df7d45197d1941c9b1a90ad815231630721" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -587,9 +586,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "percent-encoding" @@ -628,7 +627,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -736,9 +735,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.26" +version = "0.38.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a" +checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" dependencies = [ "bitflags", "errno", @@ -755,15 +754,9 @@ checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "scopeguard" -version = "1.2.0" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "semver" @@ -788,7 +781,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -857,7 +850,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -911,7 +904,7 @@ dependencies = [ "regex", "svd-parser", "svd-rs", - "syn 2.0.39", + "syn 2.0.41", "thiserror", ] @@ -958,9 +951,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" dependencies = [ "proc-macro2", "quote", @@ -993,7 +986,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -1255,9 +1248,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.19" +version = "0.5.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +checksum = "6c830786f7720c2fd27a1a0e27a709dbd3c4d009b56d098fc742d4f4eab91fe2" dependencies = [ "memchr", ] diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 1f85ef88b4..5e0f0414fa 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -6,12 +6,12 @@ publish = false [dependencies] anyhow = "1.0.75" -clap = { version = "4.4.10", features = ["derive"] } +clap = { version = "4.4.11", features = ["derive"] } env_logger = "0.10.1" form = "0.11.0" log = "0.4.20" semver = "1.0.20" strum = { version = "0.25.0", features = ["derive"] } svd2rust = { version = "0.31.2", default-features = false } -svdtools = "0.3.4" +svdtools = "0.3.6" toml_edit = "0.21.0" diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 6973483385..1c9e909574 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -38,6 +38,9 @@ enum Version { Patch, } +// ---------------------------------------------------------------------------- +// Command-line interface + #[derive(Debug, Parser)] struct Cli { #[command(subcommand)] @@ -46,10 +49,20 @@ struct Cli { #[derive(Debug, Subcommand)] enum Commands { + /// Generate a webpage for a given SVD file + /// + /// Contains details on every peripheral and register and their level + /// of coverage. + Html { + /// Package(s) to target + #[arg(value_enum, default_values_t = Chip::iter())] + chips: Vec, + }, + /// Patch the specified package(s)'s SVD file Patch { - /// Chip(s) to target - #[clap(value_enum, default_values_t = Chip::iter())] + /// Package(s) to target + #[arg(value_enum, default_values_t = Chip::iter())] chips: Vec, }, @@ -58,8 +71,8 @@ enum Commands { /// Additionally patches the releavant SVD(s) prior to generating the /// package(s). Generate { - /// Chip(s) to target - #[clap(value_enum, default_values_t = Chip::iter())] + /// Package(s) to target + #[arg(value_enum, default_values_t = Chip::iter())] chips: Vec, }, @@ -68,30 +81,37 @@ enum Commands { /// Additionally patches the relevant SVD(s) and generates the relevant /// package(s) prior to building the package(s). Build { - /// Chip(s) to target - #[clap(value_enum, default_values_t = Chip::iter())] + /// Package(s) to target + #[arg(value_enum, default_values_t = Chip::iter())] chips: Vec, }, /// Bump the version of the specified package(s) BumpVersion { /// How much to bump the version - #[clap(value_enum)] + #[arg(value_enum)] amount: Version, - /// Chip(s) to target - #[clap(value_enum, default_values_t = Chip::iter())] + + /// Package(s) to target + #[arg(value_enum, default_values_t = Chip::iter())] chips: Vec, }, - // Generates a webpage for a given SVD file containing details on every - /// peripheral and register and their level of coverage. - Html { - /// Chip(s) to target - #[clap(value_enum, default_values_t = Chip::iter())] + /// Published the specified package(s) + Publish { + /// Perform all checks without uploading + #[arg(long)] + dry_run: bool, + + /// Package(s) to publish + #[arg(value_enum, default_values_t = Chip::iter())] chips: Vec, }, } +// ---------------------------------------------------------------------------- +// Application + fn main() -> Result<()> { env_logger::Builder::new() .filter_module("xtask", log::LevelFilter::Info) @@ -103,25 +123,49 @@ fn main() -> Result<()> { let workspace = workspace.parent().unwrap().canonicalize()?; match Cli::parse().command { + Commands::Html { chips } => generate_html(&workspace, chips), + Commands::Patch { chips } => chips .iter() .try_for_each(|chip| patch_svd(&workspace, chip)), + Commands::Generate { chips } => chips .iter() .try_for_each(|chip: &Chip| generate_package(&workspace, chip)), + Commands::Build { chips } => chips .iter() .try_for_each(|chip| build_package(&workspace, chip)), - Commands::BumpVersion { - chips, - amount: version, - } => chips + + Commands::BumpVersion { chips, amount } => chips .iter() - .try_for_each(|chip| bump_version(&workspace, chip, version)), - Commands::Html { chips } => generate_html(&workspace, chips), + .try_for_each(|chip| bump_version(&workspace, chip, amount)), + + Commands::Publish { dry_run, chips } => chips + .iter() + .try_for_each(|chip| publish_package(&workspace, chip, dry_run)), } } +// ---------------------------------------------------------------------------- +// Subcommands + +fn generate_html(workspace: &Path, chips: Vec) -> Result<()> { + let svdfiles = chips + .iter() + .map(|chip| { + workspace + .join(chip.to_string()) + .join("svd") + .join(format!("{chip}.svd")) + }) + .collect::>(); + + svd2html(&workspace.join("html"), &svdfiles)?; + + Ok(()) +} + fn patch_svd(workspace: &Path, chip: &Chip) -> Result<()> { log::info!("applying patches to SVD file for {chip}"); @@ -266,6 +310,25 @@ fn bump_version(workspace: &Path, chip: &Chip, amount: Version) -> Result<()> { Ok(()) } +fn publish_package(workspace: &Path, chip: &Chip, dry_run: bool) -> Result<()> { + // Patch the SVD and generate the package prior to publishing: + generate_package(workspace, chip)?; + + let path = workspace.join(chip.to_string()); + clean(&path)?; + + log::info!("publishing package '{chip}', dry run: {dry_run}"); + Command::new("cargo") + .args(&["publish", if dry_run { "--dry-run" } else { "" }]) + .current_dir(path) + .output()?; + + Ok(()) +} + +// ---------------------------------------------------------------------------- +// Helper functions + fn build_target(path: &Path) -> Result { let config_file = path.join(".cargo").join("config.toml"); let target = extract_toml_value(&config_file, &["build", "target"])?; @@ -320,19 +383,3 @@ fn clean(path: &Path) -> Result<()> { Ok(()) } - -fn generate_html(workspace: &Path, chips: Vec) -> Result<()> { - let svdfiles = chips - .iter() - .map(|chip| { - workspace - .join(chip.to_string()) - .join("svd") - .join(format!("{chip}.svd")) - }) - .collect::>(); - - svd2html(&workspace.join("html"), &svdfiles)?; - - Ok(()) -}