diff --git a/.scripts/cargo-check.ps1 b/.scripts/cargo-check.ps1 index 47b71f546..c6b7d1d1a 100644 --- a/.scripts/cargo-check.ps1 +++ b/.scripts/cargo-check.ps1 @@ -1,14 +1,59 @@ -Write-Output "Checking tauri crates" +#!/usr/bin/env pwsh +# note: you can pass in the cargo sub-commands used to check manually. +# allowed commands: check, clippy, fmt, test +# default: clippy, fmt, test +# set the script arguments if none are found +if(-Not $args) { + $args=@("clippy","fmt","test") +} -$commands=@("clippy","test") -$features=@("no-server","embedded-server") -foreach ($command in $commands) { - foreach ($feature in $features) { - Write-Output "[$command][$feature] checking tauri" - cargo $command --manifest-path tauri/Cargo.toml --all-targets --features "$feature,cli,all-api" +# exit the script early if the last command returned an error +function check_error { + if($LASTEXITCODE -ne 0 ) { + Exit $LASTEXITCODE + } +} + +# run n+1 times, where n is the amount of mutually exclusive features. +# the extra run is for all the crates without mutually exclusive features. +# as many features as possible are enabled at for each command +function mutex { + $command, $_args = $args + + foreach ($feature in @("no-server","embedded-server")) { + Write-Output "[$command][$feature] tauri" + cargo $command --manifest-path tauri/Cargo.toml --all-targets --features "$feature,cli,all-api" $_args + check_error } - Write-Output "[$command] checking other crates" - cargo $command --workspace --exclude tauri --all-targets --all-features + Write-Output "[$command] other crates" + cargo $command --workspace --exclude tauri --all-targets --all-features $_args + check_error +} + +foreach ($command in $args) { + Switch ($command) { + "check" { + mutex check + break + } + "test" { + mutex test + break + } + "clippy" { + mutex clippy "--" -D warnings + break + } + "fmt" { + Write-Output "[$command] checking formatting" + cargo fmt "--" --check + check_error + } + default { + Write-Output "[cargo-check.ps1] Unknown cargo sub-command: $command" + Exit 1 + } + } } diff --git a/.scripts/cargo-check.sh b/.scripts/cargo-check.sh index 95e4c2c10..963912508 100644 --- a/.scripts/cargo-check.sh +++ b/.scripts/cargo-check.sh @@ -1,16 +1,47 @@ #!/usr/bin/env sh +# note: you can pass in the cargo sub-commands used to check manually. +# allowed commands: check, clippy, fmt, test +# default: clippy, fmt, test + +# exit the script early if any of the commands return an error set -e -echo "Checking tauri crates" +# set the script arguments if none are found +if [ -z "$*" ]; then + set -- "clippy" "fmt" "test" +fi -for command in "clippy" "test" -do - for feature in "no-server" "embedded-server" - do - echo "[$command][$feature] checking tauri" - cargo "$command" --manifest-path tauri/Cargo.toml --all-targets --features "$feature,cli,all-api" +# run n+1 times, where n is the amount of mutually exclusive features. +# the extra run is for all the crates without mutually exclusive features. +# as many features as possible are enabled at for each command +mutex() { + command=$1 + shift 1 + + for feature in "no-server" "embedded-server"; do + echo "[$command][$feature] tauri" + cargo "$command" --manifest-path tauri/Cargo.toml --all-targets --features "$feature,cli,all-api" "$@" done - echo "[$command] checking other crates" - cargo "$command" --workspace --exclude tauri --all-targets --all-features + echo "[$command] other crates" + cargo "$command" --workspace --exclude tauri --all-targets --all-features "$@" +} + +for command in "$@"; do + case "$command" in + check | test) + mutex "$command" + ;; + clippy) + mutex clippy -- -D warnings + ;; + fmt) + echo "[$command] checking formatting" + cargo fmt -- --check + ;; + *) + echo "[cargo-check.sh] Unknown cargo sub-command: $command" + exit 1 + ;; + esac done