Files
obiskim/.crate-kit/scripts/deps-check-external.sh
T
Eric Coissac 8159137f8b chore: add crate-kit build system and CeCILL license
Introduce the `.crate-kit` infrastructure to standardize build, testing,
and release workflows using Jujutsu and Cargo. Add CeCILL-2.1 license
files and update all workspace crate manifests with license and repository
metadata.

- Add `.crate-kit/` directory with `VERSION`, `crate.mk`, `dev-patch.mk`,
  `jj.mk`, and `org.mk` to define build targets, Jujutsu helpers, and
  registry configuration for the workspace.
- Add 21 shell scripts in `.crate-kit/scripts/` for API tracking,
  dependency checking, version bumping, publishing, tagging, and wiki
  generation, including `common.sh` with shared utility functions.
- Add `scripts/jj-tag.sh` to support tagging commits with version strings
  derived from the current crate version.
- Add `LICENSE` and `LICENSE.en` files containing the CeCILL-2.1 free
  software license agreement in French and English.
- Update `Makefile` with new targets for building, testing, formatting,
  CI, and releasing, integrating with `.crate-kit` scripts and updating
  the wiki directory path to `obiskim`.
- Update `.gitignore` to ignore `.cargo/config.toml` files generated by
  the development patch system.
- Add `license = "CECILL-2.1"` and
  `repository = "https://forge.metabarcoding.org/obi/obiskim"` to all
  `Cargo.toml` files in the workspace, including `obicompactvec`,
  `obidebruinj`, `obifastwrite`, `obikalgorithm`, `obikdump`,
  `obikentropy`, `obikfilter`, `obikidxcache`, `obikindex`,
  `obikindexer`, `obikmer`, `obikmerge`, `obikphylo`, `obikquery`,
  `obikrebuild`, `obikrope`, `obikselect`, `obikseq`, `obiksession`,
  `obikstats`, `obipipeline`, `obiread`, `obiskbuilder`, `obiskio`,
  `obisys`, and `obitaxonomy`.
- Update `src/obikrope/Cargo.toml` to use `criterion2` version 3 with
  the `cargo_bench_support` feature.
- Update `src/obikseq/Cargo.toml` to replace the "OnceLock-based params"
  feature with a new feature description involving thread-local storage.
- Update `src/Cargo.lock` to reflect the version bump of `obikmer` from
  1.4.7 to 1.4.8.
2026-12-01 17:18:34 +01:00

194 lines
8.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Freshness of the EXTERNAL dependencies (crates.io) declared by the project. `cargo outdated` compares the
# Cargo.lock version to the latest published one, but not the requirement written in Cargo.toml: a
# requirement `os_info = "3.8"` with a lock up to date at 3.15 goes unnoticed, and a consumer of the
# crate may end up with a version seven minor versions old.
#
# For each direct dependency `name = "x.y"` or `name = { version = "x.y", … }` (excluding `path`, `git`,
# `registry`, `workspace`), in [dependencies], [dev-dependencies], [build-dependencies], their
# `target.*` variants and [workspace.dependencies], it checks:
# 1. the requirement accepts the latest published version (for a 0.x, `0.5` does not accept 0.6);
# 2. for a version ≥ 1, the required minor version is not behind the latest
# (`tokio = "1.35"` while 1.52 exists). A 0.x is not checked at this level: its
# patch number does not count;
# 3. Cargo.lock is on the latest version that the requirement accepts.
# Requirements that are not written `x`, `x.y` or `x.y.z` (`=1.2.3`, `~1.2`, `>=1`, ranges) are
# explicit choices: ignored.
#
# deps-check-external.sh check (read-only, except for the network)
# deps-check-external.sh bump raises the outdated requirements then `cargo update -p`
#
# Variables: DEPS_CHECK_EXTERNAL=0 disables the check (workspace too large to be kept up
# to date all at once); DEPS_CHECK_EXTERNAL_IGNORE="crate1 crate2" sets crates aside (to be justified in
# the Makefile: for example a public dependency that must move up with the neighbouring crates); CRATES_IO_INDEX (default https://index.crates.io); DEPS_CHECK_OFFLINE=1 ignores
# the absence of network (warning).
# shellcheck disable=SC2154 # manifests comes from deps-lib.sh
set -euo pipefail
. "$(dirname "$0")/common.sh"
. "$(dirname "$0")/deps-lib.sh"
mode="${1:-check}"
case "$mode" in check | bump) ;; *)
err "usage: deps-check-external.sh [check|bump]"
exit 2
;;
esac
if [ "${DEPS_CHECK_EXTERNAL:-1}" = 0 ]; then
info " (external dependencies: check disabled by DEPS_CHECK_EXTERNAL=0)"
exit 0
fi
[ -f "$CARGO_TOML" ] || exit 0
crates_index="${CRATES_IO_INDEX:-https://index.crates.io}"
crates_index="${crates_index%/}"
fail=0
bad() {
err " ✗ $*"
fail=1
}
# External declarations of a manifest: "key<TAB>crate<TAB>requirement" (the crate differs from the key
# when the dependency is renamed by `package = "…"`).
declarations() {
awk '
/^\[/ { dep = ($0 ~ /^\[(workspace\.|target\..*\.)?(dev-|build-)?dependencies\]$/); next }
!dep { next }
/^[ \t]*#/ { next }
{
if (match($0, /^[A-Za-z0-9_-]+[ \t]*=/) == 0) next
key = $0; sub(/[ \t]*=.*/, "", key)
rest = $0; sub(/^[A-Za-z0-9_-]+[ \t]*=[ \t]*/, "", rest)
crate = key
if (rest ~ /^"/) {
req = rest; sub(/^"/, "", req); sub(/".*/, "", req)
} else if (rest ~ /^\{/) {
if (rest ~ /(path|git|registry|workspace)[ \t]*=/) next
if (match(rest, /version[ \t]*=[ \t]*"[^"]*"/) == 0) next
req = substr(rest, RSTART, RLENGTH)
sub(/^version[ \t]*=[ \t]*"/, "", req); sub(/"$/, "", req)
if (match(rest, /package[ \t]*=[ \t]*"[^"]*"/)) {
crate = substr(rest, RSTART, RLENGTH)
sub(/^package[ \t]*=[ \t]*"/, "", crate); sub(/"$/, "", crate)
}
} else next
print key "\t" crate "\t" req
}
' "$1"
}
# Replaces the requirement of the dependency `key` (in a dependencies section) of manifest $1 with $3.
rewrite_req() {
awk -v n="$2" -v r="$3" '
/^\[/ { dep = ($0 ~ /dependencies\]$/) }
dep && $0 ~ "^" n "[ \t]*=" {
if ($0 ~ /\{/) sub(/version[ \t]*=[ \t]*"[^"]*"/, "version = \"" r "\"")
else sub(/"[^"]*"/, "\"" r "\"")
}
{ print }
' "$1" >"$1.tmp" && mv "$1.tmp" "$1"
}
# Requirement to write for version $1: x.y (≥ 1) or 0.y.
floor_for() { echo "$1" | cut -d. -f1,2; }
tmp=$(mktemp -d)
trap 'rm -r "$tmp"' EXIT
info "→ Freshness of the external dependencies (crates.io)..."
count=0
offline=0
updates=""
for manifest in "${manifests[@]}"; do
while IFS=$'\t' read -r key crate req; do
[ -n "$crate" ] || continue
# Dependency deliberately set aside (DEPS_CHECK_EXTERNAL_IGNORE, with its reason in the Makefile).
case " ${DEPS_CHECK_EXTERNAL_IGNORE:-} " in *" $crate "*) continue ;; esac
# Explicit requirement (=, ~, >=, range): a choice, not checked (and no network request).
case "${req#^}" in '' | *[!0-9.]*) continue ;; esac
count=$((count + 1))
if [ ! -f "$tmp/$crate" ]; then
rc=0
found=$(latest_published "$crate" "$crates_index") || rc=$?
printf '%s %s\n' "$rc" "$found" >"$tmp/$crate"
fi
read -r rc latest <"$tmp/$crate"
if [ "$rc" -eq 2 ]; then
offline=1
continue
fi
if [ "$rc" -eq 1 ] || [ -z "$latest" ]; then
warn " ⚠ $crate ($manifest): not found on crates.io, not checked"
continue
fi
acc=0
req_accepts "$req" "$latest" || acc=$?
if [ "$acc" -eq 1 ]; then
# Newer than the latest published (pre-release, yank): nothing to raise.
[ "$(printf '%s\n%s\n' "$req" "$latest" | sort -V | tail -n 1)" = "$latest" ] || continue
if [ "$mode" = bump ]; then
new=$(floor_for "$latest")
rewrite_req "$manifest" "$key" "$new"
info " $crate ($manifest): \"$req\" → \"$new\" (latest version: $latest)"
updates+="$crate "
else
bad "$crate ($manifest): the requirement \"$req\" does not accept the latest version $latest → \"$(floor_for "$latest")\" (make deps-bump)"
fi
continue
fi
# The requirement accepts the latest version: is the required minor (≥ 1.0) behind?
IFS=. read -r rmaj rmin _ <<<"${req#^}"
IFS=. read -r _ lmin _ <<<"$latest"
if [ "$rmaj" != 0 ] && [ -n "$rmin" ] && [ "$rmin" -lt "$lmin" ]; then
if [ "$mode" = bump ]; then
new=$(floor_for "$latest")
rewrite_req "$manifest" "$key" "$new"
info " $crate ($manifest): \"$req\" → \"$new\" (latest version: $latest)"
updates+="$crate "
else
bad "$crate ($manifest): the requirement \"$req\" is behind the latest version $latest → \"$(floor_for "$latest")\" (make deps-bump)"
fi
fi
# Cargo.lock: on the latest version that the requirement accepts.
if [ -f Cargo.lock ]; then
locked=$(lock_entries | awk -v n="$crate" '$1 == n && index($3, "crates.io-index") { print $2 }' | sort -V | tail -n 1)
if [ -n "$locked" ] && [ "$locked" != "$latest" ] &&
[ "$(printf '%s\n%s\n' "$locked" "$latest" | sort -V | tail -n 1)" = "$latest" ]; then
if [ "$mode" = bump ]; then
updates+="$crate "
else
bad "$crate: Cargo.lock is on $locked, the latest version is $latest → cargo update -p $crate (make deps-bump)"
fi
fi
fi
done < <(declarations "$manifest")
done
if [ "$offline" -eq 1 ]; then
if [ "${DEPS_CHECK_OFFLINE:-}" = 1 ]; then
warn " ⚠ crates.io unreachable: freshness of the external dependencies not verified (DEPS_CHECK_OFFLINE=1)"
else
bad "crates.io unreachable ($crates_index): freshness cannot be verified (DEPS_CHECK_OFFLINE=1 to ignore)"
fi
fi
if [ "$mode" = bump ] && [ -n "$updates" ]; then
for n in $(printf '%s\n' $updates | sort -u); do
info " cargo update -p $n"
"$CARGO" update -p "$n" >/dev/null
done
fi
if [ "$fail" -ne 0 ]; then
err "✗ External dependencies out of date (see above)"
exit 1
fi
ok "✓ External dependencies up to date ($count checked)"