Use --arg for jq more

This commit is contained in:
Taiki Endo
2026-04-10 15:42:08 +09:00
parent 08a38582e3
commit 0620033eb0
2 changed files with 8 additions and 8 deletions

12
main.sh
View File

@@ -277,14 +277,14 @@ read_manifest() {
# usually preferred over linux-gnu binaries because they can avoid glibc version issues. # usually preferred over linux-gnu binaries because they can avoid glibc version issues.
# (rustc enables statically linking for linux-musl by default, except for mips.) # (rustc enables statically linking for linux-musl by default, except for mips.)
host_platform="${host_arch}_linux_musl" host_platform="${host_arch}_linux_musl"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(jq -r --arg p "${host_platform}" '.[$p]' <<<"${manifest}")
if [[ "${download_info}" == "null" ]]; then if [[ "${download_info}" == "null" ]]; then
# Even if host_env is musl, we won't issue an error here because it seems that in # Even if host_env is musl, we won't issue an error here because it seems that in
# some cases linux-gnu binaries will work on linux-musl hosts. # some cases linux-gnu binaries will work on linux-musl hosts.
# https://wiki.alpinelinux.org/wiki/Running_glibc_programs # https://wiki.alpinelinux.org/wiki/Running_glibc_programs
# TODO: However, a warning may make sense. # TODO: However, a warning may make sense.
host_platform="${host_arch}_linux_gnu" host_platform="${host_arch}_linux_gnu"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(jq -r --arg p "${host_platform}" '.[$p]' <<<"${manifest}")
elif [[ "${host_env}" == "gnu" ]]; then elif [[ "${host_env}" == "gnu" ]]; then
# TODO: don't hardcode tool name and use 'prefer_linux_gnu' field in base manifest. # TODO: don't hardcode tool name and use 'prefer_linux_gnu' field in base manifest.
case "${tool}" in case "${tool}" in
@@ -296,7 +296,7 @@ read_manifest() {
# musl build of nextest is slow, so use glibc build if host_env is gnu. # musl build of nextest is slow, so use glibc build if host_env is gnu.
# https://github.com/taiki-e/install-action/issues/13 # https://github.com/taiki-e/install-action/issues/13
host_platform="${host_arch}_linux_gnu" host_platform="${host_arch}_linux_gnu"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(jq -r --arg p "${host_platform}" '.[$p]' <<<"${manifest}")
fi fi
;; ;;
esac esac
@@ -306,10 +306,10 @@ read_manifest() {
# Binaries compiled for x86_64 macOS will usually also work on AArch64 macOS. # Binaries compiled for x86_64 macOS will usually also work on AArch64 macOS.
# Binaries compiled for x86_64 Windows will usually also work on AArch64 Windows 11+. # Binaries compiled for x86_64 Windows will usually also work on AArch64 Windows 11+.
host_platform="${host_arch}_${host_os}" host_platform="${host_arch}_${host_os}"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(jq -r --arg p "${host_platform}" '.[$p]' <<<"${manifest}")
if [[ "${download_info}" == "null" ]] && [[ "${host_arch}" != "x86_64" ]]; then if [[ "${download_info}" == "null" ]] && [[ "${host_arch}" != "x86_64" ]]; then
host_platform="x86_64_${host_os}" host_platform="x86_64_${host_os}"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(jq -r --arg p "${host_platform}" '.[$p]' <<<"${manifest}")
fi fi
;; ;;
*) bail "unsupported OS type '${host_os}' for ${tool}" ;; *) bail "unsupported OS type '${host_os}' for ${tool}" ;;
@@ -327,7 +327,7 @@ read_download_info() {
bin_in_archive=() bin_in_archive=()
if [[ "${url}" == "null" ]]; then if [[ "${url}" == "null" ]]; then
local template local template
template=$(jq -c ".template.${host_platform}" "${manifest_dir}/${tool}.json") template=$(jq -c --arg p "${host_platform}" '.template[$p]' "${manifest_dir}/${tool}.json")
template="${template//\$\{version\}/${exact_version}}" template="${template//\$\{version\}/${exact_version}}"
url=$(jq -r '.url' <<<"${template}") url=$(jq -r '.url' <<<"${template}")
tmp=$(jq -r '.bin' <<<"${template}") tmp=$(jq -r '.bin' <<<"${template}")

View File

@@ -147,12 +147,12 @@ for manifest in tools/codegen/base/*.json; do
fi fi
case "${host_os}" in case "${host_os}" in
linux*) linux*)
if [[ "${host_arch}" != "x86_64" ]] && [[ "$(jq -r ".platform.${host_arch}_${host_os}_gnu" "${manifest}")" == "null" ]] && [[ "$(jq -r ".platform.${host_arch}_${host_os}_musl" "${manifest}")" == "null" ]]; then if [[ "${host_arch}" != "x86_64" ]] && [[ "$(jq -r --arg p "${host_arch}_${host_os}_gnu" '.platform[$p]' "${manifest}")" == "null" ]] && [[ "$(jq -r --arg p "${host_arch}_${host_os}_musl" '.platform[$p]' "${manifest}")" == "null" ]]; then
continue continue
fi fi
;; ;;
*) *)
if [[ "$(jq -r ".platform.x86_64_${host_os}" "${manifest}")" == "null" ]] && [[ "$(jq -r ".platform.${host_arch}_${host_os}" "${manifest}")" == "null" ]]; then if [[ "$(jq -r --arg p "x86_64_${host_os}" '.platform[$p]' "${manifest}")" == "null" ]] && [[ "$(jq -r --arg p "${host_arch}_${host_os}" '.platform[$p]' "${manifest}")" == "null" ]]; then
continue continue
fi fi
;; ;;