aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-07 18:28:29 +0200
committerDanilo M. <danix@danix.xyz>2026-07-07 18:28:29 +0200
commitf0e458c39b475a887c43c7f4d3616ebb94f798ac (patch)
treee08d5dfd6f790189f6cdcfc64a44748a66653645
parent375b2b74e3ff11a7029ec8de7ca8cb8167b2f6a1 (diff)
downloadmkhintfile-f0e458c39b475a887c43c7f4d3616ebb94f798ac.tar.gz
mkhintfile-f0e458c39b475a887c43c7f4d3616ebb94f798ac.zip
feat: load_bundle_manifests + manifest_url_for
Parse the pkg->url-template config and substitute {VERSION}. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
-rwxr-xr-xmkhint28
-rwxr-xr-xtests/mkhint_test.sh20
2 files changed, 48 insertions, 0 deletions
diff --git a/mkhint b/mkhint
index 7c593b8..2a18abc 100755
--- a/mkhint
+++ b/mkhint
@@ -485,6 +485,34 @@ match_dep_url() {
done <<< "$list"
return 1
}
+
+# Loaded map: pkg name -> URL template. Populated by load_bundle_manifests.
+declare -A BUNDLE_MANIFESTS=()
+load_bundle_manifests() {
+ BUNDLE_MANIFESTS=()
+ [[ -f "$BUNDLE_MANIFEST_FILE" ]] || return 0
+ local line pkg url
+ while IFS= read -r line; do
+ line="${line%%#*}"
+ [[ -z "${line// }" ]] && continue
+ read -r pkg url <<< "$line"
+ [[ -n "$pkg" && -n "$url" ]] && BUNDLE_MANIFESTS["$pkg"]="$url"
+ done < "$BUNDLE_MANIFEST_FILE"
+}
+
+# manifest_url_for <pkg> <version> — echo the manifest URL for pkg with
+# {VERSION} substituted. Non-zero if pkg is not listed.
+manifest_url_for() {
+ local pkg="$1" ver="$2"
+ local tmpl="${BUNDLE_MANIFESTS[$pkg]:-}"
+ [[ -z "$tmpl" ]] && return 1
+ printf '%s\n' "${tmpl//\{VERSION\}/$ver}"
+}
+
+# True if pkg has a bundle manifest configured.
+pkg_has_manifest() {
+ [[ -n "${BUNDLE_MANIFESTS[$1]:-}" ]]
+}
# ── end bundled-dep manifest handling ─────────────────────────────────────────
# Create new hint file
diff --git a/tests/mkhint_test.sh b/tests/mkhint_test.sh
index 908b738..959cbdb 100755
--- a/tests/mkhint_test.sh
+++ b/tests/mkhint_test.sh
@@ -1511,6 +1511,26 @@ r=$(bash -c "$BM_SRC; match_dep_url 'https://github.com/baz/qux/archive/v2.0.tar
&& { echo " PASS: empty on no match"; (( PASS++ )); } \
|| { echo " FAIL: expected empty got '$r'"; (( FAIL++ )); ERRORS+=("T-BM5"); }
+# ── T-BM6: load_bundle_manifests + manifest_url_for ──────────────────────────
+echo ""
+echo "T-BM6: manifest_url_for substitutes {VERSION}, unlisted pkg → non-zero"
+cat > "$MOCK_BASE/bundle-manifests" << 'EOF'
+# comment
+neovim https://example.com/neovim/v{VERSION}/deps.txt
+EOF
+BM_SRC='source <(sed -n "/# ── bundled-dep manifest handling/,/# ── end bundled-dep/p" '"$SCRIPT"')'
+r=$(bash -c "BUNDLE_MANIFEST_FILE='$MOCK_BASE/bundle-manifests'; $BM_SRC; load_bundle_manifests; manifest_url_for neovim 0.13.0")
+[[ "$r" == 'https://example.com/neovim/v0.13.0/deps.txt' ]] \
+ && { echo " PASS: templated URL"; (( PASS++ )); } \
+ || { echo " FAIL: templated URL got '$r'"; (( FAIL++ )); ERRORS+=("T-BM6a"); }
+set +e
+bash -c "BUNDLE_MANIFEST_FILE='$MOCK_BASE/bundle-manifests'; $BM_SRC; load_bundle_manifests; manifest_url_for curl 8.0" >/dev/null 2>&1
+rc=$?
+set -e
+[[ $rc -ne 0 ]] \
+ && { echo " PASS: unlisted pkg non-zero"; (( PASS++ )); } \
+ || { echo " FAIL: unlisted pkg should be non-zero"; (( FAIL++ )); ERRORS+=("T-BM6b"); }
+
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
teardown