From 960c74c21df4088db45ea904e1510f3994ca7f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 6 Mar 2023 19:50:17 +0100 Subject: [PATCH] ci: Sort Cargo.toml and add a check for it --- Cargo.toml | 84 ++++++++++++++++++++++++----------------------- scripts/checks.sh | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3acc8f5c..cb3d3ae7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,69 +16,62 @@ overflow-checks = false incremental = false codegen-units = 16 +# Please keep dependencies sorted. [dependencies] -async-stream = "0.3" -log = "0.4" -mime = "0.3.16" -tracing-subscriber = "0.3" -gettext-rs = { version = "0.7", features = ["gettext-system"] } -once_cell = "1.5" -serde = "1.0.130" -serde_json = "1.0" -tokio = { version = "1.15", features = ["rt", "rt-multi-thread", "sync"] } -url = "2.2" -oo7 = { version = "0.1.0-beta.3", default-features = false, features = [ - "native_crypto", - "tokio", - "tracing", -] } -html2pango = "0.5.0" -futures = "0.3" -rand = "0.8" -indexmap = "1.6.2" -qrcode = "0.12.0" ashpd = { version = "0.4.0-alpha.4", default-features = false, features = [ "gtk4", "pipewire", "tracing", "tokio", ] } +async-stream = "0.3" +djb_hash = "0.1.3" +futures = "0.3" +futures-signals = { version = "0.3.30", default-features = false } +geo-uri = "0.2.0" +gettext-rs = { version = "0.7", features = ["gettext-system"] } gst = { version = "0.20.2", package = "gstreamer" } gst_base = { version = "0.20.0", package = "gstreamer-base" } -gst_video = { version = "0.20.2", package = "gstreamer-video" } -gst_play = { version = "0.20.2", package = "gstreamer-play" } gst_gtk = { version = "0.10.3", package = "gst-plugin-gtk4" } gst_pbutils = { version = "0.20.0", package = "gstreamer-pbutils" } +gst_play = { version = "0.20.2", package = "gstreamer-play" } +gst_video = { version = "0.20.2", package = "gstreamer-video" } +html-escape = "0.2.11" +html2pango = "0.5.0" image = "0.24" -regex = "1.5.4" +indexmap = "1.6.2" +log = "0.4" +mime = "0.3.16" mime_guess = "2.0.3" num_enum = "0.5.6" -thiserror = "1.0.25" +once_cell = "1.5" +oo7 = { version = "0.1.0-beta.3", default-features = false, features = [ + "native_crypto", + "tokio", + "tracing", +] } +pulldown-cmark = "0.9.2" +qrcode = "0.12.0" +rand = "0.8" +regex = "1.5.4" rqrr = "0.5" secular = { version = "1.0.1", features = ["bmp", "normalization"] } -pulldown-cmark = "0.9.2" -geo-uri = "0.2.0" -html-escape = "0.2.11" -djb_hash = "0.1.3" -futures-signals = { version = "0.3.30", default-features = false } - -[dependencies.sourceview] -package = "sourceview5" -version = "0.6.0" - -[dependencies.gtk] -package = "gtk4" -version = "0.6.2" -features = ["v4_6"] +serde = "1.0.130" +serde_json = "1.0" +thiserror = "1.0.25" +tokio = { version = "1.15", features = ["rt", "rt-multi-thread", "sync"] } +tracing-subscriber = "0.3" +url = "2.2" [dependencies.adw] package = "libadwaita" version = "0.3.1" features = ["v1_3"] -[dependencies.shumate] -package = "libshumate" -version = "0.3.0" +[dependencies.gtk] +package = "gtk4" +version = "0.6.2" +features = ["v4_6"] [dependencies.matrix-sdk] git = "https://github.com/matrix-org/matrix-rust-sdk.git" @@ -101,6 +94,15 @@ features = ["crypto-store"] version = "0.8.1" features = ["unstable-unspecified", "client-api-c", "unstable-sanitize"] +[dependencies.shumate] +package = "libshumate" +version = "0.3.0" + +[dependencies.sourceview] +package = "sourceview5" +version = "0.6.0" + +# FIXME: Remove when matrix-sdk dependencies don't pin zeroize (conflict with oo7) [patch.crates-io.x25519-dalek] git = "https://github.com/A6GibKm/x25519-dalek" rev = "9f19028c34107eea87d37bcee2eb2b350ec34cfe" diff --git a/scripts/checks.sh b/scripts/checks.sh index 13b8c404..d5550e79 100755 --- a/scripts/checks.sh +++ b/scripts/checks.sh @@ -498,6 +498,65 @@ check_resources() { fi } +# Install cargo-sort with cargo. +install_cargo_sort() { + echo -e "$Installing cargo-sort…" + cargo install cargo-sort + if ! cargo-sort --version >/dev/null 2>&1; then + echo -e "$Failed to install cargo-sort" + exit 2 + fi +} + +# Run cargo-sort to check if Cargo.toml is sorted. +run_cargo_sort() { + if ! cargo-sort --version >/dev/null 2>&1; then + if [[ $force_install -eq 1 ]]; then + install_cargo_sort + elif [ ! -t 1 ]; then + echo "Unable to check Cargo.toml sorting, because cargo-sort could not be run" + exit 2 + else + echo "Cargo-sort is needed to check the sorting in Cargo.toml, but it isn’t available" + echo "" + echo "y: Install cargo-sort via cargo" + echo "N: Don't install cargo-sort and abort checks" + echo "" + while true; do + echo -n "Install cargo-sort? [y/N]: "; read yn < /dev/tty + case $yn in + [Yy]* ) + install_cargo_sort + break + ;; + [Nn]* | "" ) + exit 2 + ;; + * ) + echo $invalid + ;; + esac + done + fi + fi + + echo -e "$Checking Cargo.toml sorting…" + + if [[ $verbose -eq 1 ]]; then + echo "" + cargo-sort --version + echo "" + fi + + if ! cargo-sort --check --grouped --order package,lib,profile,features,dependencies,target,dev-dependencies,build-dependencies; then + echo -e " Cargo.toml sorting result: $fail" + echo "Please fix the Cargo.toml file, either manually or by running: cargo-sort --grouped --order package,lib,profile,features,dependencies,target,dev-dependencies,build-dependencies" + exit 1 + else + echo -e " Cargo.toml sorting result: $ok" + fi +} + # Check arguments while [[ "$1" ]]; do case $1 in -s | --git-staged ) @@ -547,3 +606,5 @@ else check_resources fi echo "" +run_cargo_sort +echo ""