cargo_sort
1 #!/usr/bin/env bash 2 # 3 # Run "cargo sort" to check that the Cargo.tomls are sorted 4 5 set -euo pipefail 6 7 # We want to exclude the toplevel Cargo.toml, because that needs to be in 8 # topological order. But cargo sort doesn't support that. 9 # https://github.com/DevinR528/cargo-sort/issues/38 10 11 # So instead, we sed its output. Urgh. 12 13 (TERM=dumb cargo sort --check --workspace || test $? = 1) 2>&1 | perl -ne ' 14 next if m{^\Qerror: Dependencies for arti are not sorted\E$}; 15 $n_arti += !!m{^\QChecking arti...}; # printed for toplevel too 16 next if m{^Checking \S+\Q...\E$}; 17 $n_bad++; 18 print STDERR; 19 END { 20 flush STDOUT; 21 eval { 22 die "expected \"Checking arti\" twice, got $n_arti times\n" unless $n_arti==2; 23 die "unexpected output ($n_bad line(s)) from cargo-sort\n" if $n_bad; 24 }; 25 if ($@) { 26 print STDERR $@; 27 exit 12; 28 } 29 } 30 '