diff --git a/build b/build index 45dfa384ee0db652d07a879a09496fa63454e187..9584d0d7038742bde2f4e6ed388180422da1c71c 100755 --- a/build +++ b/build @@ -16,6 +16,20 @@ if [ -z "$ZIG_LOCAL_CACHE_DIR" ]; then fi ZIG="$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION/zig" + +if [ "$1" == "--fmt" ]; then + # dprint.jsonc is configured to run this, however it runs in parallel. + # only one installation should happen, not one per file. since there + # is no concise way to acquire a filesystem lock on .zig-cache, + # formatting before an install is left unsupported. + if [ ! -f "$ZIG" ]; then + printf "Zig is not installed. Please run ./build once manually\n" + exit 1 + fi + shift + exec $ZIG fmt $@ +fi + if [ ! -f "$ZIG" ]; then OS=$(uname -s | tr '[:upper:]' '[:lower:]') if [ "$OS" = "darwin" ]; then @@ -28,16 +42,16 @@ if [ ! -f "$ZIG" ]; then URL="https://ziglang.org/builds/zig-$OS-$ARCH-$ZIG_VERSION.tar.xz" - echo "Installing Zig v$ZIG_VERSION via $URL" + printf "Installing Zig v$ZIG_VERSION via $URL\n" CURL=$(command -v curl 2>/dev/null) TAR=$(command -v curl 2>/dev/null) if [ -z "$CURL" ]; then - echo "This script requires 'curl' to be installed." + printf "This script requires 'curl' to be installed.\n" fi if [ -z "$TAR" ]; then - echo "This script requires 'tar' to be installed." + printf "This script requires 'tar' to be installed.\n" fi if [ -z "$CURL" ] || [ -z "$TAR" ]; then @@ -48,10 +62,15 @@ if [ ! -f "$ZIG" ]; then curl -fsSL --retry 3 --retry-delay 3 $URL \ | tar -xJ --strip-components=1 -C "$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION" if [ "$($ZIG version)" != "$ZIG_VERSION" ]; then - echo "Zig failed to install." + printf "Zig failed to install.\n" rm -rf "$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION" exit 1 fi fi +if [ "$1" == "--version" ]; then + printf "Zig version: " + exec $ZIG version +fi + exec $ZIG build $@ diff --git a/ci b/ci index 619452c747148e93756c6c6bf71355707ced34ad..21eaf46e5c963b94e7e2946ff7a8136e5ee0d1e0 100755 --- a/ci +++ b/ci @@ -8,6 +8,7 @@ set -e commit=$(git rev-parse HEAD) commit_short=$(echo "$commit" | cut -c -9) +./build --version typos dprint check ./build all --summary new diff --git a/dprint.jsonc b/dprint.jsonc index 7143e211560d5ae63385cd9b9ea1dfe20339788f..829702cde8f40c1e6bb4233b52b1d8b556a5ff25 100644 --- a/dprint.jsonc +++ b/dprint.jsonc @@ -18,7 +18,7 @@ "cwd": "${configDir}", "commands": [ { - "command": "zig fmt --stdin", + "command": "./build --fmt --stdin", "exts": ["zig", "zon"], }, ],