111 lines
No EOL
3.2 KiB
Makefile
111 lines
No EOL
3.2 KiB
Makefile
# crossing the boundary. run `just` to list recipes
|
|
|
|
set shell := ["bash", "-euo", "pipefail", "-c"]
|
|
|
|
# list the available recipes
|
|
default:
|
|
@just --list
|
|
|
|
# install every chapter's pinned toolchain
|
|
setup:
|
|
@just _each toolchain ""
|
|
|
|
# rustfmt and clippy in every chapter (or one: `just check 3`)
|
|
check chapter="":
|
|
@just _each check "{{chapter}}"
|
|
|
|
# diff two chapters' committed code: `just diff 3 4`, `just diff 3 4 --stat`
|
|
diff from to *args:
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
a="$(just _dir {{from}})"
|
|
b="$(just _dir {{to}})"
|
|
git diff {{args}} "HEAD:$a" "HEAD:$b"
|
|
|
|
# start the new chapter as a copy of the latest one: `just new-chapter paging`
|
|
new-chapter slug:
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
chapters=(chapters/*/)
|
|
last="${chapters[-1]%/}"
|
|
name="$(basename "$last")"
|
|
next=$((10#${name%%-*} + 1))
|
|
dest="chapters/$(printf '%02d' "$next")-{{slug}}"
|
|
if [[ -e "$dest" ]]; then
|
|
echo "$dest already exists" >&2
|
|
exit 1
|
|
fi
|
|
cp -r "$last" "$dest"
|
|
rm -rf "$dest/target" "$dest/build"
|
|
sed -i "1s/.*/# chapter $next: {{slug}}/" "$dest/README.md"
|
|
echo "created $dest from $name"
|
|
echo "remember to update its README.md and the table in the root README"
|
|
|
|
# apply a fix committed in one chapter to every later chapter: `just propagate 3 [commit]`
|
|
propagate chapter commit="HEAD":
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
src="$(just _dir {{chapter}})"
|
|
name="$(basename "$src")"
|
|
from=$((10#${name%%-*}))
|
|
patch="$(mktemp)"
|
|
trap 'rm -f "$patch"' EXIT
|
|
git diff --relative="$src" "{{commit}}^" "{{commit}}" >"$patch"
|
|
if [[ ! -s "$patch" ]]; then
|
|
echo "{{commit}} doesn't touch $src" >&2
|
|
exit 1
|
|
fi
|
|
conflicts=()
|
|
for dir in chapters/*/; do
|
|
dir="${dir%/}"
|
|
name="$(basename "$dir")"
|
|
(( 10#${name%%-*} > from )) || continue
|
|
if git apply --3way --directory="$dir" "$patch"; then
|
|
echo "applied to $dir"
|
|
else
|
|
conflicts+=("$dir")
|
|
fi
|
|
done
|
|
if [[ ${#conflicts[@]} -gt 0 ]]; then
|
|
echo "conflicts in: ${conflicts[*]}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# run chapter recipes in every chapter, or just in `chapter`
|
|
_each recipes chapter:
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
if [[ -n "{{chapter}}" ]]; then
|
|
dirs=("$(just _dir {{chapter}})")
|
|
else
|
|
dirs=(chapters/*/)
|
|
fi
|
|
failed=()
|
|
for dir in "${dirs[@]}"; do
|
|
dir="${dir%/}"
|
|
echo "==> $(basename "$dir"): {{recipes}}"
|
|
(cd "$dir" && just {{recipes}}) || failed+=("$(basename "$dir")")
|
|
done
|
|
if [[ ${#failed[@]} -gt 0 ]]; then
|
|
echo "failed: ${failed[*]}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# resolve a chapter number (3, 03) or full name to directory
|
|
_dir chapter:
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
if [[ -d "chapters/{{chapter}}" ]]; then
|
|
echo "chapters/{{chapter}}"
|
|
exit 0
|
|
fi
|
|
matches=(chapters/"$(printf '%02d' "$((10#{{chapter}}))")"-*/)
|
|
if [[ ! -d "${matches[0]}" ]]; then
|
|
echo "no chapter matching '{{chapter}}'" >&2
|
|
exit 1
|
|
fi
|
|
echo "${matches[0]%/}"
|
|
|
|
# build every chapter and test them (or just one: `just test 3`)
|
|
test chapter="":
|
|
@just _each "build test" "{{chapter}}"
|