halkyon/tool/workspace_only.sh

31 lines
1.4 KiB
Shell
Raw Permalink Normal View History

#!/bin/sh
# Narrows the workspace in ./pubspec.yaml to the members named, for an image that builds
# only those (the Dockerfiles of the servers and Learn's curator): pub then resolves
# without the other members, whose folders the image doesn't hold. Fails if one named
# isn't a member, so a renamed package fails the build loudly.
#
# It also drops the dependency overrides of third_party/'s patched Flutter plugins: an
# image has Dart without Flutter, and pub refuses an override depending on the Flutter
# SDK, used or not (exit 69, the deploys of 4 Nov 2026). No image's package uses them.
#
# sh tool/workspace_only.sh apps/learn/halkyon_learn_server packages/halkyon_base_server
set -eu
awk -v keep="$*" '
BEGIN { n = split(keep, k, " "); for (i = 1; i <= n; i++) wanted[" - " k[i]] = 1 }
# An override held back until its next line says whether its path is in third_party.
held != "" {
line = held; held = ""
if ($0 ~ /^ path: third_party\//) { next }
print line
}
/^[a-z_]+:/ { overrides = ($0 == "dependency_overrides:") }
overrides && /^ [a-z0-9_]+:$/ { held = $0; next }
/^workspace:/ { block = 1; print; next }
block && /^ - / { if ($0 in wanted) { print; found[$0] = 1 }; next }
{ block = 0; print }
END {
for (w in wanted) if (!(w in found)) { print "Not a workspace member:" substr(w, 4) > "/dev/stderr"; failed = 1 }
exit failed
}
' pubspec.yaml >pubspec.yaml.narrowed
mv pubspec.yaml.narrowed pubspec.yaml