forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB8defefbTahinli6 days ago3947 commits

changed-crates.sh48 lines, 2.1 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# Print `-p <crate>` lines for the workspace crates affected by a change, for use as
3# cargo test $(scripts/changed-crates.sh)
4#
5# Changed files = `git diff <base>...HEAD` + uncommitted (staged/unstaged) + untracked.
6# Each changed file maps to the workspace package whose directory contains it. Those
7# packages are then expanded to all their reverse dependencies inside the workspace
8# (path dependencies only). A change to a root file (Cargo.toml, Cargo.lock, .config/,
9# .cargo/, rust-toolchain*) selects every workspace crate.
10# ec-hw and ec-va are dropped unless they changed themselves (GPU; no hardware encode).
11#
12# Usage: scripts/changed-crates.sh [BASE_REF] (BASE_REF defaults to main)
13set -euo pipefail
14
15base="${1:-main}"
16root="$(git rev-parse --show-toplevel)"
17cd "$root"
18
19meta_file="$(mktemp)"
20trap 'rm -f "$meta_file"' EXIT
21cargo metadata --format-version 1 --no-deps > "$meta_file"
22
23changed="$({
24 git diff --name-only "$base...HEAD"
25 git diff --name-only HEAD
26 git ls-files --others --exclude-standard
27} | sort -u | jq -R -s 'split("\n") | map(select(length > 0))')"
28
29jq -r --argjson files "$changed" '
30 .workspace_root as $wr
31 | [ .packages[] | select(.source == null)
32 | { name,
33 dir: (.manifest_path | sub("/Cargo.toml$"; "") | ltrimstr($wr + "/")),
34 deps: [ .dependencies[] | select(.path != null) | .name ] } ] as $pk
35 | ($files | any(test("^(Cargo\\.toml|Cargo\\.lock|rust-toolchain[^/]*|\\.config/.*|\\.cargo/.*)$"))) as $rootChanged
36 | [ $pk[] | select(.dir != "") as $p
37 | select([$files[] | select(startswith($p.dir + "/"))] | length > 0)
38 | .name ] | unique as $changedPkgs
39 | (if $rootChanged then [$pk[].name] else $changedPkgs end) as $seeds
40 | def closure($cur):
41 ([ $pk[] | select(any(.deps[]; . as $x | any($cur[]; . == $x))) | .name ] + $cur | unique) as $next
42 | if ($next | length) == ($cur | length) then $cur else closure($next) end;
43 closure($seeds)
44 | map(. as $n
45 | select((["ec-hw", "ec-va"] | any(. == $n) | not) or ($changedPkgs | any(. == $n))))
46 | sort[]
47 | "-p " + .
48' "$meta_file"