diff --git a/main.sh b/main.sh index 614f76ba..e59d5d0b 100755 --- a/main.sh +++ b/main.sh @@ -152,6 +152,7 @@ read_manifest() { local tool="$1" local version="$2" local manifest + rust_crate=$(jq -r ".rust_crate" "${manifest_dir}/${tool}.json") manifest=$(jq -r ".\"${version}\"" "${manifest_dir}/${tool}.json") if [[ "${manifest}" == "null" ]]; then download_info="null" @@ -220,15 +221,14 @@ read_download_info() { template=$(jq -r ".template.${host_platform}" "${manifest_dir}/${tool}.json") url=$(jq <<<"${template}" -r '.url') url="${url//\$\{version\}/${exact_version}}" - bin_dir=$(jq <<<"${template}" -r '.bin_dir') - bin_dir="${bin_dir//\$\{version\}/${exact_version}}" bin_in_archive=$(jq <<<"${template}" -r '.bin') bin_in_archive="${bin_in_archive//\$\{version\}/${exact_version}}" else - bin_dir=$(jq <<<"${download_info}" -r '.bin_dir') bin_in_archive=$(jq <<<"${download_info}" -r '.bin') fi - if [[ "${bin_dir}" == "null" ]]; then + if [[ "${rust_crate}" == "null" ]]; then + bin_dir="/usr/local/bin" + else bin_dir="${cargo_bin}" fi if [[ "${bin_in_archive}" == "null" ]]; then @@ -563,10 +563,13 @@ for tool in "${tools[@]}"; do # Use cargo-binstall fallback if tool is available but the specified version not available. read_manifest "${tool}" "${version}" if [[ "${download_info}" == "null" ]]; then + if [[ "${rust_crate}" == "null" ]]; then + bail "${tool}@${version} for '${host_os}' is not supported" + fi warn "${tool}@${version} for '${host_os}' is not supported; fallback to cargo-binstall" case "${version}" in - latest) unsupported_tools+=("${tool}") ;; - *) unsupported_tools+=("${tool}@${version}") ;; + latest) unsupported_tools+=("${rust_crate}") ;; + *) unsupported_tools+=("${rust_crate}@${version}") ;; esac continue fi diff --git a/manifests/cargo-binstall.json b/manifests/cargo-binstall.json index c66e2d73..90f37e0f 100644 --- a/manifests/cargo-binstall.json +++ b/manifests/cargo-binstall.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-binstall", "template": { "x86_64_linux_musl": { "url": "https://github.com/cargo-bins/cargo-binstall/releases/download/v${version}/cargo-binstall-x86_64-unknown-linux-musl.tgz" diff --git a/manifests/cargo-careful.json b/manifests/cargo-careful.json index cf371fa1..08d56331 100644 --- a/manifests/cargo-careful.json +++ b/manifests/cargo-careful.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-careful", "template": { "x86_64_linux_musl": { "url": "https://github.com/RalfJung/cargo-careful/releases/download/v${version}/cargo-careful.x86_64-unknown-linux-musl" diff --git a/manifests/cargo-deny.json b/manifests/cargo-deny.json index f0de034a..c0a36b96 100644 --- a/manifests/cargo-deny.json +++ b/manifests/cargo-deny.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-deny", "template": { "x86_64_linux_musl": { "url": "https://github.com/EmbarkStudios/cargo-deny/releases/download/${version}/cargo-deny-${version}-x86_64-unknown-linux-musl.tar.gz", diff --git a/manifests/cargo-dinghy.json b/manifests/cargo-dinghy.json index de5915d3..861514e1 100644 --- a/manifests/cargo-dinghy.json +++ b/manifests/cargo-dinghy.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-dinghy", "template": { "x86_64_linux_musl": { "url": "https://github.com/sonos/dinghy/releases/download/${version}/cargo-dinghy-linux-${version}.tgz", diff --git a/manifests/cargo-hack.json b/manifests/cargo-hack.json index d49547b0..cca22f1b 100644 --- a/manifests/cargo-hack.json +++ b/manifests/cargo-hack.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-hack", "template": null, "latest": { "version": "0.5.28" diff --git a/manifests/cargo-llvm-cov.json b/manifests/cargo-llvm-cov.json index e4375354..03240f38 100644 --- a/manifests/cargo-llvm-cov.json +++ b/manifests/cargo-llvm-cov.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-llvm-cov", "template": { "x86_64_linux_musl": { "url": "https://github.com/taiki-e/cargo-llvm-cov/releases/download/v${version}/cargo-llvm-cov-x86_64-unknown-linux-musl.tar.gz" diff --git a/manifests/cargo-make.json b/manifests/cargo-make.json index d687b839..f6581be6 100644 --- a/manifests/cargo-make.json +++ b/manifests/cargo-make.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-make", "template": { "x86_64_linux_musl": { "url": "https://github.com/sagiegurari/cargo-make/releases/download/${version}/cargo-make-v${version}-x86_64-unknown-linux-musl.zip", diff --git a/manifests/cargo-minimal-versions.json b/manifests/cargo-minimal-versions.json index 184d7892..3dc29b64 100644 --- a/manifests/cargo-minimal-versions.json +++ b/manifests/cargo-minimal-versions.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-minimal-versions", "template": { "x86_64_linux_musl": { "url": "https://github.com/taiki-e/cargo-minimal-versions/releases/download/v${version}/cargo-minimal-versions-x86_64-unknown-linux-musl.tar.gz" diff --git a/manifests/cargo-nextest.json b/manifests/cargo-nextest.json index aa5c6f18..2977e1f8 100644 --- a/manifests/cargo-nextest.json +++ b/manifests/cargo-nextest.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-nextest", "template": { "x86_64_linux_gnu": { "url": "https://github.com/nextest-rs/nextest/releases/download/cargo-nextest-${version}/cargo-nextest-${version}-x86_64-unknown-linux-gnu.tar.gz" diff --git a/manifests/cargo-no-dev-deps.json b/manifests/cargo-no-dev-deps.json index 56ac8e24..d44247d0 100644 --- a/manifests/cargo-no-dev-deps.json +++ b/manifests/cargo-no-dev-deps.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-no-dev-deps", "template": { "x86_64_linux_musl": { "url": "https://github.com/taiki-e/cargo-no-dev-deps/releases/download/v${version}/cargo-no-dev-deps-x86_64-unknown-linux-musl.tar.gz" diff --git a/manifests/cargo-tarpaulin.json b/manifests/cargo-tarpaulin.json index bebf9680..840847bb 100644 --- a/manifests/cargo-tarpaulin.json +++ b/manifests/cargo-tarpaulin.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-tarpaulin", "template": { "x86_64_linux_musl": { "url": "https://github.com/xd009642/tarpaulin/releases/download/${version}/cargo-tarpaulin-x86_64-unknown-linux-musl.tar.gz" diff --git a/manifests/cargo-udeps.json b/manifests/cargo-udeps.json index ba3eac08..de309bc5 100644 --- a/manifests/cargo-udeps.json +++ b/manifests/cargo-udeps.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-udeps", "template": { "x86_64_linux_gnu": { "url": "https://github.com/est31/cargo-udeps/releases/download/v${version}/cargo-udeps-v${version}-x86_64-unknown-linux-gnu.tar.gz", diff --git a/manifests/cargo-valgrind.json b/manifests/cargo-valgrind.json index 9a514b5d..8b37256e 100644 --- a/manifests/cargo-valgrind.json +++ b/manifests/cargo-valgrind.json @@ -1,4 +1,5 @@ { + "rust_crate": "cargo-valgrind", "template": { "x86_64_linux_musl": { "url": "https://github.com/jfrimmel/cargo-valgrind/releases/download/v${version}/cargo-valgrind-${version}-x86_64-unknown-linux-musl.tar.gz" diff --git a/manifests/cross.json b/manifests/cross.json index a7c84982..9709463c 100644 --- a/manifests/cross.json +++ b/manifests/cross.json @@ -1,4 +1,5 @@ { + "rust_crate": "cross", "template": null, "latest": { "version": "0.2.5" diff --git a/manifests/dprint.json b/manifests/dprint.json index 648fe413..e5c132dd 100644 --- a/manifests/dprint.json +++ b/manifests/dprint.json @@ -1,4 +1,5 @@ { + "rust_crate": "dprint", "template": { "x86_64_linux_gnu": { "url": "https://github.com/dprint/dprint/releases/download/${version}/dprint-x86_64-unknown-linux-gnu.zip" diff --git a/manifests/grcov.json b/manifests/grcov.json index febd9679..5f05867e 100644 --- a/manifests/grcov.json +++ b/manifests/grcov.json @@ -1,4 +1,5 @@ { + "rust_crate": "grcov", "template": { "x86_64_linux_musl": { "url": "https://github.com/mozilla/grcov/releases/download/v${version}/grcov-x86_64-unknown-linux-musl.tar.bz2" diff --git a/manifests/just.json b/manifests/just.json index fe23b791..e0292e3c 100644 --- a/manifests/just.json +++ b/manifests/just.json @@ -1,4 +1,5 @@ { + "rust_crate": "just", "template": { "x86_64_linux_musl": { "url": "https://github.com/casey/just/releases/download/${version}/just-${version}-x86_64-unknown-linux-musl.tar.gz" diff --git a/manifests/mdbook-linkcheck.json b/manifests/mdbook-linkcheck.json index 401ae6ae..590dec66 100644 --- a/manifests/mdbook-linkcheck.json +++ b/manifests/mdbook-linkcheck.json @@ -1,4 +1,5 @@ { + "rust_crate": "mdbook-linkcheck", "template": { "x86_64_linux_gnu": { "url": "https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/download/v${version}/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip" diff --git a/manifests/mdbook.json b/manifests/mdbook.json index 261c7136..529e49e8 100644 --- a/manifests/mdbook.json +++ b/manifests/mdbook.json @@ -1,4 +1,5 @@ { + "rust_crate": "mdbook", "template": { "x86_64_linux_gnu": { "url": "https://github.com/rust-lang/mdBook/releases/download/v${version}/mdbook-v${version}-x86_64-unknown-linux-gnu.tar.gz" diff --git a/manifests/parse-changelog.json b/manifests/parse-changelog.json index 832cc770..c1885be0 100644 --- a/manifests/parse-changelog.json +++ b/manifests/parse-changelog.json @@ -1,4 +1,5 @@ { + "rust_crate": "parse-changelog", "template": { "x86_64_linux_gnu": { "url": "https://github.com/taiki-e/parse-changelog/releases/download/v${version}/parse-changelog-x86_64-unknown-linux-gnu.tar.gz" diff --git a/manifests/protoc.json b/manifests/protoc.json index 6361d76f..7e7e1074 100644 --- a/manifests/protoc.json +++ b/manifests/protoc.json @@ -1,4 +1,5 @@ { + "rust_crate": null, "template": null, "latest": { "version": "3.23.4" diff --git a/manifests/shellcheck.json b/manifests/shellcheck.json index 47f109ab..bc10d2a8 100644 --- a/manifests/shellcheck.json +++ b/manifests/shellcheck.json @@ -1,23 +1,20 @@ { + "rust_crate": null, "template": { "x86_64_linux_gnu": { "url": "https://github.com/koalaman/shellcheck/releases/download/v${version}/shellcheck-v${version}.linux.x86_64.tar.xz", - "bin_dir": "/usr/local/bin", "bin": "shellcheck-v${version}/shellcheck" }, "x86_64_macos": { "url": "https://github.com/koalaman/shellcheck/releases/download/v${version}/shellcheck-v${version}.darwin.x86_64.tar.xz", - "bin_dir": "/usr/local/bin", "bin": "shellcheck-v${version}/shellcheck" }, "x86_64_windows": { "url": "https://github.com/koalaman/shellcheck/releases/download/v${version}/shellcheck-v${version}.zip", - "bin_dir": "/usr/local/bin", "bin": "shellcheck.exe" }, "aarch64_linux_gnu": { "url": "https://github.com/koalaman/shellcheck/releases/download/v${version}/shellcheck-v${version}.linux.aarch64.tar.xz", - "bin_dir": "/usr/local/bin", "bin": "shellcheck-v${version}/shellcheck" } }, diff --git a/manifests/shfmt.json b/manifests/shfmt.json index 4804584c..4875d748 100644 --- a/manifests/shfmt.json +++ b/manifests/shfmt.json @@ -1,24 +1,20 @@ { + "rust_crate": null, "template": { "x86_64_linux_gnu": { - "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_linux_amd64", - "bin_dir": "/usr/local/bin" + "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_linux_amd64" }, "x86_64_macos": { - "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_darwin_amd64", - "bin_dir": "/usr/local/bin" + "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_darwin_amd64" }, "x86_64_windows": { - "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_windows_amd64.exe", - "bin_dir": "/usr/local/bin" + "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_windows_amd64.exe" }, "aarch64_linux_gnu": { - "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_linux_arm64", - "bin_dir": "/usr/local/bin" + "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_linux_arm64" }, "aarch64_macos": { - "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_darwin_arm64", - "bin_dir": "/usr/local/bin" + "url": "https://github.com/mvdan/sh/releases/download/v${version}/shfmt_v${version}_darwin_arm64" } }, "latest": { diff --git a/manifests/syft.json b/manifests/syft.json index 903974f1..b787bd3f 100644 --- a/manifests/syft.json +++ b/manifests/syft.json @@ -1,28 +1,24 @@ { + "rust_crate": null, "template": { "x86_64_linux_musl": { "url": "https://github.com/anchore/syft/releases/download/v${version}/syft_${version}_linux_amd64.tar.gz", - "bin_dir": "/usr/local/bin", "bin": "syft" }, "x86_64_macos": { "url": "https://github.com/anchore/syft/releases/download/v${version}/syft_${version}_darwin_amd64.tar.gz", - "bin_dir": "/usr/local/bin", "bin": "syft" }, "x86_64_windows": { "url": "https://github.com/anchore/syft/releases/download/v${version}/syft_${version}_windows_amd64.zip", - "bin_dir": "/usr/local/bin", "bin": "syft.exe" }, "aarch64_linux_musl": { "url": "https://github.com/anchore/syft/releases/download/v${version}/syft_${version}_linux_arm64.tar.gz", - "bin_dir": "/usr/local/bin", "bin": "syft" }, "aarch64_macos": { "url": "https://github.com/anchore/syft/releases/download/v${version}/syft_${version}_darwin_arm64.tar.gz", - "bin_dir": "/usr/local/bin", "bin": "syft" } }, diff --git a/manifests/wasm-pack.json b/manifests/wasm-pack.json index e3b210b3..3d1555c3 100644 --- a/manifests/wasm-pack.json +++ b/manifests/wasm-pack.json @@ -1,4 +1,5 @@ { + "rust_crate": "wasm-pack", "template": { "x86_64_linux_musl": { "url": "https://github.com/rustwasm/wasm-pack/releases/download/v${version}/wasm-pack-v${version}-x86_64-unknown-linux-musl.tar.gz", diff --git a/manifests/wasmtime.json b/manifests/wasmtime.json index 206b3b26..4dfa02a5 100644 --- a/manifests/wasmtime.json +++ b/manifests/wasmtime.json @@ -1,4 +1,5 @@ { + "rust_crate": "wasmtime-cli", "template": null, "latest": { "version": "11.0.1" diff --git a/manifests/zola.json b/manifests/zola.json index 7923f3ca..a19bb6eb 100644 --- a/manifests/zola.json +++ b/manifests/zola.json @@ -1,4 +1,5 @@ { + "rust_crate": "zola", "template": { "x86_64_linux_gnu": { "url": "https://github.com/getzola/zola/releases/download/v${version}/zola-v${version}-x86_64-unknown-linux-gnu.tar.gz" diff --git a/tools/codegen/base/cargo-binstall.json b/tools/codegen/base/cargo-binstall.json index 8e670bde..129647ba 100644 --- a/tools/codegen/base/cargo-binstall.json +++ b/tools/codegen/base/cargo-binstall.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/cargo-bins/cargo-binstall", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-${rust_target}.tgz", "version_range": "latest", "platform": { diff --git a/tools/codegen/base/cargo-careful.json b/tools/codegen/base/cargo-careful.json index 281b93a5..65c99a0a 100644 --- a/tools/codegen/base/cargo-careful.json +++ b/tools/codegen/base/cargo-careful.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/RalfJung/cargo-careful", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}.${rust_target}", "platform": { "x86_64_linux_musl": {}, diff --git a/tools/codegen/base/cargo-deny.json b/tools/codegen/base/cargo-deny.json index c994a904..b1032158 100644 --- a/tools/codegen/base/cargo-deny.json +++ b/tools/codegen/base/cargo-deny.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/EmbarkStudios/cargo-deny", "tag_prefix": "", + "rust_crate": "${package}", "asset_name": "${package}-${version}-${rust_target}.tar.gz", "bin": "${package}-${version}-${rust_target}/${package}${exe}", "platform": { diff --git a/tools/codegen/base/cargo-dinghy.json b/tools/codegen/base/cargo-dinghy.json index 85898b12..1c3066c6 100644 --- a/tools/codegen/base/cargo-dinghy.json +++ b/tools/codegen/base/cargo-dinghy.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/sonos/dinghy", "tag_prefix": "", + "rust_crate": "${package}", "asset_name": "${package}-${os_name}-${version}.tgz", "bin": "${package}-${version}/${package}${exe}", "platform": { diff --git a/tools/codegen/base/cargo-hack.json b/tools/codegen/base/cargo-hack.json index d28801be..6e9c9b19 100644 --- a/tools/codegen/base/cargo-hack.json +++ b/tools/codegen/base/cargo-hack.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/taiki-e/cargo-hack", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": [ "${package}-${rust_target}.tar.gz", "${package}-v${version}-${rust_target}.tar.gz" diff --git a/tools/codegen/base/cargo-llvm-cov.json b/tools/codegen/base/cargo-llvm-cov.json index 024f5004..38b8d769 100644 --- a/tools/codegen/base/cargo-llvm-cov.json +++ b/tools/codegen/base/cargo-llvm-cov.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/taiki-e/cargo-llvm-cov", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-${rust_target}.tar.gz", "platform": { "x86_64_linux_musl": {}, diff --git a/tools/codegen/base/cargo-make.json b/tools/codegen/base/cargo-make.json index 50403f57..2c6253f6 100644 --- a/tools/codegen/base/cargo-make.json +++ b/tools/codegen/base/cargo-make.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/sagiegurari/cargo-make", "tag_prefix": "", + "rust_crate": "${package}", "asset_name": "${package}-v${version}-${rust_target}.zip", "bin": "${package}-v${version}-${rust_target}/${package}${exe}", "platform": { diff --git a/tools/codegen/base/cargo-minimal-versions.json b/tools/codegen/base/cargo-minimal-versions.json index 25789904..fafe3a65 100644 --- a/tools/codegen/base/cargo-minimal-versions.json +++ b/tools/codegen/base/cargo-minimal-versions.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/taiki-e/cargo-minimal-versions", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-${rust_target}.tar.gz", "platform": { "x86_64_linux_musl": {}, diff --git a/tools/codegen/base/cargo-nextest.json b/tools/codegen/base/cargo-nextest.json index 41ad233b..2250ba80 100644 --- a/tools/codegen/base/cargo-nextest.json +++ b/tools/codegen/base/cargo-nextest.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/nextest-rs/nextest", "tag_prefix": "cargo-nextest-", + "rust_crate": "${package}", "asset_name": "${package}-${version}-${rust_target}.tar.gz", "platform": { "x86_64_linux_gnu": {}, diff --git a/tools/codegen/base/cargo-no-dev-deps.json b/tools/codegen/base/cargo-no-dev-deps.json index acf4767e..168e8863 100644 --- a/tools/codegen/base/cargo-no-dev-deps.json +++ b/tools/codegen/base/cargo-no-dev-deps.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/taiki-e/cargo-no-dev-deps", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-${rust_target}.tar.gz", "platform": { "x86_64_linux_musl": {}, diff --git a/tools/codegen/base/cargo-tarpaulin.json b/tools/codegen/base/cargo-tarpaulin.json index 93a69abc..ebd0c3d7 100644 --- a/tools/codegen/base/cargo-tarpaulin.json +++ b/tools/codegen/base/cargo-tarpaulin.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/xd009642/tarpaulin", "tag_prefix": "", + "rust_crate": "${package}", "asset_name": "${package}-${rust_target}.tar.gz", "version_range": "> 0.22.0", "platform": { diff --git a/tools/codegen/base/cargo-udeps.json b/tools/codegen/base/cargo-udeps.json index 8782c6c6..92da9ea1 100644 --- a/tools/codegen/base/cargo-udeps.json +++ b/tools/codegen/base/cargo-udeps.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/est31/cargo-udeps", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-v${version}-${rust_target}.tar.gz", "bin": "./${package}-v${version}-${rust_target}/${package}${exe}", "platform": { diff --git a/tools/codegen/base/cargo-valgrind.json b/tools/codegen/base/cargo-valgrind.json index b3332c3b..c4efa895 100644 --- a/tools/codegen/base/cargo-valgrind.json +++ b/tools/codegen/base/cargo-valgrind.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/jfrimmel/cargo-valgrind", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-${version}-${rust_target}.tar.gz", "platform": { "x86_64_linux_musl": {}, diff --git a/tools/codegen/base/cross.json b/tools/codegen/base/cross.json index 25438009..939a12ae 100644 --- a/tools/codegen/base/cross.json +++ b/tools/codegen/base/cross.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/cross-rs/cross", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": [ "${package}-${rust_target}.tar.gz", "${package}-v${version}-${rust_target}.tar.gz" diff --git a/tools/codegen/base/dprint.json b/tools/codegen/base/dprint.json index 83a71ffc..43c9c54d 100644 --- a/tools/codegen/base/dprint.json +++ b/tools/codegen/base/dprint.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/dprint/dprint", "tag_prefix": "", + "rust_crate": "${package}", "asset_name": "${package}-${rust_target}.zip", "platform": { "x86_64_linux_gnu": {}, diff --git a/tools/codegen/base/grcov.json b/tools/codegen/base/grcov.json index da4fc4d8..b7a8a2a1 100644 --- a/tools/codegen/base/grcov.json +++ b/tools/codegen/base/grcov.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/mozilla/grcov", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-${rust_target}.tar.bz2", "version_range": ">= 0.8.7", "platform": { diff --git a/tools/codegen/base/just.json b/tools/codegen/base/just.json index 159f815e..2853a698 100644 --- a/tools/codegen/base/just.json +++ b/tools/codegen/base/just.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/casey/just", "tag_prefix": "", + "rust_crate": "${package}", "asset_name": "${package}-${version}-${rust_target}.tar.gz", "platform": { "x86_64_linux_musl": {}, diff --git a/tools/codegen/base/mdbook-linkcheck.json b/tools/codegen/base/mdbook-linkcheck.json index e25c86af..34f82cc2 100644 --- a/tools/codegen/base/mdbook-linkcheck.json +++ b/tools/codegen/base/mdbook-linkcheck.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/Michael-F-Bryan/mdbook-linkcheck", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}.${rust_target}.zip", "platform": { "x86_64_linux_gnu": {}, diff --git a/tools/codegen/base/mdbook.json b/tools/codegen/base/mdbook.json index 755bc715..32c301bd 100644 --- a/tools/codegen/base/mdbook.json +++ b/tools/codegen/base/mdbook.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/rust-lang/mdBook", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-v${version}-${rust_target}.tar.gz", "platform": { "x86_64_linux_musl": {}, diff --git a/tools/codegen/base/parse-changelog.json b/tools/codegen/base/parse-changelog.json index b1890cb8..83718c6c 100644 --- a/tools/codegen/base/parse-changelog.json +++ b/tools/codegen/base/parse-changelog.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/taiki-e/parse-changelog", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-${rust_target}.tar.gz", "platform": { "x86_64_linux_gnu": {}, diff --git a/tools/codegen/base/shellcheck.json b/tools/codegen/base/shellcheck.json index 0e68b7d0..6bb94e09 100644 --- a/tools/codegen/base/shellcheck.json +++ b/tools/codegen/base/shellcheck.json @@ -1,7 +1,6 @@ { "repository": "https://github.com/koalaman/shellcheck", "tag_prefix": "v", - "bin_dir": "/usr/local/bin", "bin": "${package}-v${version}/${package}${exe}", "platform": { "x86_64_linux_gnu": { diff --git a/tools/codegen/base/shfmt.json b/tools/codegen/base/shfmt.json index c2c4dba8..15ff7ac2 100644 --- a/tools/codegen/base/shfmt.json +++ b/tools/codegen/base/shfmt.json @@ -1,7 +1,6 @@ { "repository": "https://github.com/mvdan/sh", "tag_prefix": "v", - "bin_dir": "/usr/local/bin", "platform": { "x86_64_linux_gnu": { "asset_name": "${package}_v${version}_linux_amd64" diff --git a/tools/codegen/base/syft.json b/tools/codegen/base/syft.json index ad2247d5..0f73fbf9 100644 --- a/tools/codegen/base/syft.json +++ b/tools/codegen/base/syft.json @@ -1,7 +1,6 @@ { "repository": "https://github.com/anchore/syft", "tag_prefix": "v", - "bin_dir": "/usr/local/bin", "bin": "${package}${exe}", "version_range": ">= 0.83.0", "platform": { diff --git a/tools/codegen/base/wasm-pack.json b/tools/codegen/base/wasm-pack.json index 7056128b..edebbebb 100644 --- a/tools/codegen/base/wasm-pack.json +++ b/tools/codegen/base/wasm-pack.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/rustwasm/wasm-pack", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-v${version}-${rust_target}.tar.gz", "bin": "${package}-v${version}-${rust_target}/${package}${exe}", "platform": { diff --git a/tools/codegen/base/wasmtime.json b/tools/codegen/base/wasmtime.json index 7a34c4ca..c870bd50 100644 --- a/tools/codegen/base/wasmtime.json +++ b/tools/codegen/base/wasmtime.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/bytecodealliance/wasmtime", "tag_prefix": "v", + "rust_crate": "wasmtime-cli", "platform": { "x86_64_linux_gnu": { "asset_name": "${package}-v${version}-x86_64-linux.tar.xz", diff --git a/tools/codegen/base/zola.json b/tools/codegen/base/zola.json index 43fd5926..e894eeee 100644 --- a/tools/codegen/base/zola.json +++ b/tools/codegen/base/zola.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/getzola/zola", "tag_prefix": "v", + "rust_crate": "${package}", "asset_name": "${package}-v${version}-${rust_target}.tar.gz", "platform": { "x86_64_linux_gnu": {}, diff --git a/tools/codegen/src/main.rs b/tools/codegen/src/main.rs index 4bb1ee22..1f8df6b4 100644 --- a/tools/codegen/src/main.rs +++ b/tools/codegen/src/main.rs @@ -31,7 +31,7 @@ fn main() -> Result<()> { fs::create_dir_all(manifest_path.parent().unwrap())?; fs::create_dir_all(download_cache_dir)?; - let base_info: BaseManifest = serde_json::from_slice(&fs::read( + let mut base_info: BaseManifest = serde_json::from_slice(&fs::read( workspace_root .join("tools/codegen/base") .join(format!("{package}.json")), @@ -75,10 +75,15 @@ fn main() -> Result<()> { .collect(); let mut crates_io_info = None; - if base_info.bin_dir.is_none() { - eprintln!("downloading crate info from https://crates.io/api/v1/crates/{package}"); + base_info.rust_crate = base_info + .rust_crate + .as_ref() + .map(|s| replace_vars(s, package, None, None)) + .transpose()?; + if let Some(crate_name) = &base_info.rust_crate { + eprintln!("downloading crate info from https://crates.io/api/v1/crates/{crate_name}"); crates_io_info = Some( - download(&format!("https://crates.io/api/v1/crates/{package}"))? + download(&format!("https://crates.io/api/v1/crates/{crate_name}"))? .into_json::()?, ); } @@ -106,10 +111,6 @@ fn main() -> Result<()> { for (platform, d) in &mut manifest.download_info { let template = &template.download_info[platform]; d.url = Some(template.url.replace("${version}", version)); - d.bin_dir = template - .bin_dir - .as_ref() - .map(|s| s.replace("${version}", version)); d.bin = template .bin .as_ref() @@ -186,7 +187,7 @@ fn main() -> Result<()> { .with_context(|| format!("asset_name is needed for {package} on {platform:?}"))? .as_slice() .iter() - .map(|asset_name| replace_vars(asset_name, package, version, platform)) + .map(|asset_name| replace_vars(asset_name, package, Some(version), Some(platform))) .collect::>>()?; let (url, asset_name) = match asset_names.iter().find_map(|asset_name| { release @@ -227,16 +228,11 @@ fn main() -> Result<()> { ManifestDownloadInfo { url: Some(url), checksum: hash, - bin_dir: base_download_info - .bin_dir - .as_ref() - .or(base_info.bin_dir.as_ref()) - .cloned(), bin: base_download_info .bin .as_ref() .or(base_info.bin.as_ref()) - .map(|s| replace_vars(s, package, version, platform)) + .map(|s| replace_vars(s, package, Some(version), Some(platform))) .transpose()?, }, ); @@ -369,10 +365,9 @@ fn main() -> Result<()> { let t = template.as_mut().unwrap(); for (platform, d) in &mut manifest.download_info { let template_url = d.url.take().unwrap().replace(version, "${version}"); - let template_bin_dir = d.bin_dir.take().map(|s| s.replace(version, "${version}")); let template_bin = d.bin.take().map(|s| s.replace(version, "${version}")); if let Some(d) = t.download_info.get(platform) { - if template_url != d.url || template_bin_dir != d.bin_dir || template_bin != d.bin { + if template_url != d.url || template_bin != d.bin { template = None; break 'outer; } @@ -381,7 +376,6 @@ fn main() -> Result<()> { *platform, ManifestTemplateDownloadInfo { url: template_url, - bin_dir: template_bin_dir, bin: template_bin, }, ); @@ -394,6 +388,8 @@ fn main() -> Result<()> { manifests.template = template; } + manifests.rust_crate = base_info.rust_crate; + let mut buf = serde_json::to_vec_pretty(&manifests)?; buf.push(b'\n'); fs::write(manifest_path, buf)?; @@ -408,14 +404,22 @@ fn workspace_root() -> PathBuf { dir } -fn replace_vars(s: &str, package: &str, version: &str, platform: HostPlatform) -> Result { - let s = s - .replace("${package}", package) - .replace("${tool}", package) - .replace("${rust_target}", platform.rust_target()) - .replace("${os_name}", platform.os_name()) - .replace("${version}", version) - .replace("${exe}", platform.exe_suffix()); +fn replace_vars( + s: &str, + package: &str, + version: Option<&str>, + platform: Option, +) -> Result { + let mut s = s.replace("${package}", package).replace("${tool}", package); + if let Some(platform) = platform { + s = s + .replace("${rust_target}", platform.rust_target()) + .replace("${os_name}", platform.os_name()) + .replace("${exe}", platform.exe_suffix()); + } + if let Some(version) = version { + s = s.replace("${version}", version); + } if s.contains('$') { bail!("variable not fully replaced: '{s}'"); } @@ -587,6 +591,7 @@ impl<'de> Deserialize<'de> for Version { #[derive(Debug, Clone, Default, Serialize, Deserialize)] struct Manifests { + rust_crate: Option, template: Option, #[serde(flatten)] map: BTreeMap, ManifestRef>, @@ -610,9 +615,6 @@ struct ManifestDownloadInfo { #[serde(skip_serializing_if = "Option::is_none")] url: Option, checksum: String, - /// Default to ${cargo_bin} - #[serde(skip_serializing_if = "Option::is_none")] - bin_dir: Option, /// Default to ${tool}${exe} #[serde(skip_serializing_if = "Option::is_none")] bin: Option, @@ -627,9 +629,6 @@ struct ManifestTemplate { #[derive(Debug, Clone, Serialize, Deserialize)] struct ManifestTemplateDownloadInfo { url: String, - /// Default to ${cargo_bin} - #[serde(skip_serializing_if = "Option::is_none")] - bin_dir: Option, /// Default to ${tool}${exe} #[serde(skip_serializing_if = "Option::is_none")] bin: Option, @@ -642,11 +641,11 @@ struct BaseManifest { repository: String, /// Prefix of release tag. tag_prefix: String, + /// Crate name, if this is Rust crate. + rust_crate: Option, default_major_version: Option, /// Asset name patterns. asset_name: Option, - /// Directory where binary is installed. Default to `${cargo_bin}`. - bin_dir: Option, /// Path to binary in archive. Default to `${tool}${exe}`. bin: Option, platform: BTreeMap, @@ -661,8 +660,6 @@ struct BaseManifest { struct BaseManifestPlatformInfo { /// Asset name patterns. Default to the value at `BaseManifest::asset_name`. asset_name: Option, - /// Directory where binary is installed. Default to the value at `BaseManifest::bin_dir`. - bin_dir: Option, /// Path to binary in archive. Default to the value at `BaseManifest::bin`. bin: Option, }