Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/justfile

Raw
# Cargo serializes shared builds; dependencies live outside every checkout.
# Only the release executable is installed locally for runtime/sandbox use.
export CARGO_TARGET_DIR := env_var_or_default("XDG_CACHE_HOME", home_directory() / ".cache") / "nuguland/cargo"

default:
  @just --list

# create an agent worktree outside the live desktop config; prints its directory
worktree name:
  #!/usr/bin/env bash
  set -euo pipefail
  name={{ quote(name) }}
  [[ "$name" =~ ^[a-z0-9][a-z0-9-]*$ ]] || { echo "usage: just worktree <name>" >&2; exit 2; }
  dir="${TMPDIR:-/tmp}/nuguland-$name"
  git worktree add --quiet -b "agent/$name" "$dir" HEAD
  # The nested sandbox runs vault-native/run.sh against the copy, not the shared cache.
  if [[ -x "$CARGO_TARGET_DIR/release/nuguland-vault" ]]; then
    install -D "$CARGO_TARGET_DIR/release/nuguland-vault" "$dir/quickshell/nuguland/vault-native/target/release/nuguland-vault"
  else
    echo "no release vault binary: run just build here first, or vault ui-test suites report unavailable-vault" >&2
  fi
  echo "$dir/quickshell/nuguland"

# owner only: restart the live desktop shell; agents never run it
reload:
  #!/usr/bin/env bash
  set -euo pipefail
  mapfile -t pids < <(qs list -c nuguland -j | node -e 'const text = require("fs").readFileSync(0, "utf8").trim(); for (const instance of text ? JSON.parse(text) : []) console.log(instance.pid)')
  for pid in "${pids[@]}"; do qs kill --pid "$pid"; done
  # The new instance only gets the notification and tray bus names once the old one has exited.
  for pid in "${pids[@]}"; do
    for _ in $(seq 50); do
      kill -0 "$pid" 2>/dev/null || continue 2
      sleep 0.1
    done
    echo "nuguland $pid did not exit within 5 s" >&2
    exit 1
  done
  qs -c nuguland -d

# check host packages; ~90ms when present, installs missing ones explicitly when interactive
deps:
  #!/usr/bin/env bash
  set -euo pipefail
  packages=(
    weston niri quickshell pipewire wdotool wtype bubblewrap dbus systemd systemd-libs iproute2
    gcc pkgconf wayland wayland-protocols libxkbcommon wl-clipboard imagemagick colord
    qt6-base qt6-declarative qt6-shadertools glslang shellcheck shfmt cargo
    nushell tar zstd util-linux coreutils pastel glib2 aerc tmux procps-ng wezterm neovim neovide
  )
  command -v node >/dev/null || { echo "missing node: install it through mise" >&2; exit 1; }
  if missing=$(pacman -T "${packages[@]}"); then exit 0; else status=$?; fi
  ((status == 127)) || exit "$status"
  mapfile -t missing <<<"$missing"
  if [[ -t 0 ]]; then
    sudo pacman -S --needed "${missing[@]}"
  else
    echo "missing packages; run: sudo pacman -S --needed ${missing[*]}" >&2
    exit 1
  fi

# lint/typecheck/verify all Nuguland source; zero warnings
lint: deps
  #!/usr/bin/env bash
  set -euo pipefail
  tmp=$(mktemp -d)
  qs_pid=""
  cleanup() {
    [[ -z "$qs_pid" ]] || kill "$qs_pid" 2>/dev/null || true
    rm -rf "$tmp"
  }
  trap cleanup EXIT

  mapfile -t qml < <(find . -path ./vault-native -prune -o -name '*.qml' -print | sort)
  mapfile -t sh < <(find . -path './vault-native/target' -prune -o -name '*.sh' -print | sort)
  mapfile -t mjs < <(find . -name '*.mjs' -print | sort)
  mapfile -t frag < <(find shaders -name '*.frag' -print 2>/dev/null | sort)
  # One qmllint process: same per-file diagnostics and exit status, about 5x faster.
  /usr/lib/qt6/bin/qmllint --max-warnings 0 -I /usr/lib/qt6/qml "${qml[@]}" || { echo "qmllint failed" >&2; exit 1; }
  ((${#sh[@]} == 0)) || shellcheck "${sh[@]}"
  for file in "${mjs[@]}"; do
    node --check "$file"
  done
  cc -std=c17 -Wall -Wextra -Werror -fsyntax-only $(pkg-config --cflags colorhug) ambient-light-native/read.c
  cargo fmt --manifest-path vault-native/Cargo.toml --check
  cargo clippy --manifest-path vault-native/Cargo.toml --all-targets --locked -- -D warnings
  cargo test --manifest-path vault-native/Cargo.toml --locked
  cargo build --manifest-path vault-native/Cargo.toml --locked
  just test
  just load-test
  ((${#frag[@]} == 0)) || glslangValidator "${frag[@]}"

  for file in "${qml[@]}"; do
    out="$tmp/${file#./}"
    mkdir -p "$(dirname "$out")"
    /usr/lib/qt6/bin/qmlformat "$file" > "$out" || { echo "qmlformat failed: $file" >&2; exit 1; }
    cmp -s "$file" "$out" || { echo "qmlformat changed: $file" >&2; diff -u "$file" "$out"; exit 1; }
  done

  for file in "${sh[@]}"; do
    out="$tmp/${file#./}"
    mkdir -p "$(dirname "$out")"
    shfmt "$file" > "$out"
    cmp -s "$file" "$out" || { diff -u "$file" "$out"; exit 1; }
  done

  shopt -s nullglob
  for shader in shaders/*.frag; do
    out="$tmp/${shader//\//__}.qsb"
    /usr/lib/qt6/bin/qsb --glsl 330 --hlsl 50 --msl 12 -o "$out" "$shader"
    cmp -s "$shader.qsb" "$out" || { echo "stale shader blob: $shader.qsb" >&2; exit 1; }
  done
  for blob in shaders/*.qsb; do
    [[ -f "${blob%.qsb}" ]] || { echo "orphan shader blob: $blob" >&2; exit 1; }
  done

# run JS tests; pass a file, basename, stem, or vault-native for all Rust tests
# examples: just test, just test network, just test vault-native
test name="": deps
  #!/usr/bin/env bash
  set -euo pipefail
  target={{quote(name)}}
  if [[ "$target" == vault-native ]]; then
    exec cargo test --manifest-path vault-native/Cargo.toml --locked
  fi
  if [[ -n "$target" ]]; then
    case "$target" in
      /*|*..*|*$'\n'*|*$'\r'*) echo "unsafe test: $target" >&2; exit 2 ;;
    esac
    names=("$target")
    [[ "$target" == *.js || "$target" == *.mjs ]] || names=("$target.test.js" "$target.test.mjs")
    # A path runs as given; a bare stem searches root and feature directories alike,
    # so a duplicate name anywhere is reported as ambiguous instead of shadowed.
    found=()
    for name in "${names[@]}"; do
      if [[ "$name" == */* ]]; then
        [[ ! -f "$name" ]] || found+=("$name")
      else
        mapfile -t -O "${#found[@]}" found < <(find . -path ./vault-native -prune -o -type f -name "$name" -print)
      fi
    done
    ((${#found[@]} == 1)) || { echo "missing or ambiguous test: $target ${found[*]}" >&2; exit 2; }
    node "${found[0]}"
    exit
  fi

  mapfile -t tests < <(find . -path ./vault-native -prune -o \( -name '*.test.js' -o -name '*.test.mjs' \) -print | sort)
  ((${#tests[@]} > 0)) || { echo "no tests" >&2; exit 1; }
  node --test --test-concurrency=4 "${tests[@]}"

# run one JS test many times concurrently; any failure means it is flaky
# examples: just stress ambient-light, just stress ui-test 32
stress test runs="16": deps
  node stress-test.mjs {{quote(test)}} {{quote(runs)}}

# load a feature's panel offscreen with its fixture doubles; any warning fails
# examples: just load-test, just load-test audio
load-test feature="all": deps
  node load-test.mjs {{quote(feature)}}

# run nested-niri UI suites; retain screenshots and logs
ui-test fixture="all" size="": deps
  node ui-test.mjs {{quote(fixture)}} {{if size == "" { "" } else { quote(size) }}}

# format Nuguland QML and shell scripts in place
fmt: deps
  #!/usr/bin/env bash
  set -euo pipefail
  mapfile -t qml < <(find . -path ./vault-native -prune -o -name '*.qml' -print | sort)
  mapfile -t sh < <(find . -path './vault-native/target' -prune -o -name '*.sh' -print | sort)
  for file in "${qml[@]}"; do
    /usr/lib/qt6/bin/qmlformat -i "$file" || { echo "qmlformat failed: $file" >&2; exit 1; }
  done
  ((${#sh[@]} == 0)) || shfmt -w "${sh[@]}"
  cargo fmt --manifest-path vault-native/Cargo.toml

# build native helpers and compile checked-in shaders
build: deps
  #!/usr/bin/env bash
  set -euo pipefail
  cc -std=c17 -Wall -Wextra -Werror -O2 $(pkg-config --cflags colorhug) ambient-light-native/read.c -o ambient-light-native/read $(pkg-config --libs colorhug)
  cargo build --manifest-path vault-native/Cargo.toml --release --locked
  install -D "$CARGO_TARGET_DIR/release/nuguland-vault" vault-native/target/release/nuguland-vault
  shopt -s nullglob
  for shader in shaders/*.frag; do
    /usr/lib/qt6/bin/qsb --glsl 330 --hlsl 50 --msl 12 -o "$shader.qsb" "$shader"
  done