diff --git a/.cargo/config.toml b/.cargo/config.toml index 8b1378917..35049cbcb 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1 +1,2 @@ - +[alias] +xtask = "run --package xtask --" diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b5885ed41..54f36cb88 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -50,7 +50,7 @@ Guidelines In short: - Be conservative in what you need (keep to the agreed minimum supported Rust version, limit new dependencies) -- Use automated tools to help you (``build_tools/check.sh``) +- Use automated tools to help you (``cargo xtask check``) Commit History ============== @@ -245,7 +245,7 @@ In this example we're in the root of the workspace and have run ``cargo build`` To run all tests and linters, use:: - build_tools/check.sh + cargo xtask check Contributing Translations ========================= diff --git a/Cargo.lock b/Cargo.lock index 8c2b2e93e..ca3a46228 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,56 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + [[package]] name = "autocfg" version = "1.5.0" @@ -72,6 +122,52 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "clap" +version = "4.5.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -401,6 +497,18 @@ dependencies = [ "foldhash", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + [[package]] name = "itertools" version = "0.14.0" @@ -525,6 +633,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + [[package]] name = "option-ext" version = "0.2.0" @@ -947,6 +1061,12 @@ version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "2.0.111" @@ -1029,6 +1149,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ace0b4755d0a2959962769239d56267f8a024fef2d9b32666b3dcd0946b0906" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "version_check" version = "0.9.5" @@ -1096,6 +1222,14 @@ version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +[[package]] +name = "xtask" +version = "0.0.0" +dependencies = [ + "clap", + "fish-build-helper", +] + [[package]] name = "xterm-color" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index 040ca15d1..6190677cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ license = "GPL-2.0-only AND LGPL-2.0-or-later AND MIT AND PSF-2.0" bitflags = "2.5.0" cc = "1.0.94" cfg-if = "1.0.3" +clap = { version = "4.5.54", features = ["derive"] } errno = "0.3.0" fish-build-helper = { path = "crates/build-helper" } fish-build-man-pages = { path = "crates/build-man-pages" } @@ -177,7 +178,7 @@ embed-manpages = ["dep:fish-build-man-pages"] localize-messages = ["dep:fish-gettext"] # This feature is used to enable extracting messages from the source code for localization. # It only needs to be enabled if updating these messages (and the corresponding PO files) is -# desired. This happens when running tests via `build_tools/check.sh` and when calling +# desired. This happens when running tests via `cargo xtask check` and when calling # `build_tools/update_translations.fish`, so there should not be a need to enable it manually. gettext-extract = ["dep:fish-gettext-extraction"] diff --git a/crates/xtask/Cargo.toml b/crates/xtask/Cargo.toml new file mode 100644 index 000000000..4df60be27 --- /dev/null +++ b/crates/xtask/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "xtask" +version = "0.0.0" +rust-version.workspace = true +edition.workspace = true +repository.workspace = true + +[dependencies] +clap.workspace = true +fish-build-helper.workspace = true diff --git a/crates/xtask/src/lib.rs b/crates/xtask/src/lib.rs new file mode 100644 index 000000000..0b1267fb5 --- /dev/null +++ b/crates/xtask/src/lib.rs @@ -0,0 +1,20 @@ +use std::process::Command; + +pub trait CommandExt { + fn run_or_panic(&mut self); +} + +impl CommandExt for Command { + fn run_or_panic(&mut self) { + match self.status() { + Ok(exit_status) => { + if !exit_status.success() { + panic!("Command did not run successfully: {:?}", self.get_program()) + } + } + Err(err) => { + panic!("Failed to run command: {err}"); + } + } + } +} diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs new file mode 100644 index 000000000..6e3e9d4d9 --- /dev/null +++ b/crates/xtask/src/main.rs @@ -0,0 +1,33 @@ +use clap::{Parser, Subcommand}; +use std::process::Command; +use xtask::CommandExt; + +#[derive(Parser)] +#[command( + name = "cargo xtask", + about = "Wrapper for running various utilities", + arg_required_else_help(true) +)] +struct Cli { + #[command(subcommand)] + task: Task, +} + +#[derive(Subcommand)] +enum Task { + /// Run various checks on the repo. + Check, +} + +fn main() { + let cli = Cli::parse(); + match cli.task { + Task::Check => run_checks(), + } +} + +fn run_checks() { + let repo_root_dir = fish_build_helper::workspace_root(); + let check_script = repo_root_dir.join("build_tools").join("check.sh"); + Command::new(check_script).run_or_panic(); +}