From 216084d334b7ec7f8b9daff17c7a86ea2a8322c3 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 21 Sep 2023 16:23:35 +0200 Subject: [PATCH] Add RUBY_BUILD_TARBALL_OVERRIDE to override the ruby tarball URL * Update the check for whether a package is a ruby. --- README.md | 3 ++- bin/ruby-build | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 91ff27014e..ca6185b044 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,10 @@ The build process may be configured through the following environment variables: | `RUBY_BUILD_CURL_OPTS` | Additional options to pass to `curl` for downloading. | | `RUBY_BUILD_WGET_OPTS` | Additional options to pass to `wget` for downloading. | | `RUBY_BUILD_MIRROR_URL` | Custom mirror URL root. | -| `RUBY_BUILD_MIRROR_PACKAGE_URL` | Custom complete mirror URL (e.g. http://mirror.example.com/package-1.0.0.tar.gz). | +| `RUBY_BUILD_MIRROR_PACKAGE_URL` | Custom complete mirror URL (e.g. http://mirror.example.com/package-1.0.0.tar.gz). | | `RUBY_BUILD_SKIP_MIRROR` | Bypass the download mirror and fetch all package files from their original URLs. | | `RUBY_BUILD_ROOT` | Custom build definition directory. (Default: `share/ruby-build`) | +| `RUBY_BUILD_TARBALL_OVERRIDE` | Override the URL to fetch the ruby tarball from, optionally followed by `#checksum`. | | `RUBY_BUILD_DEFINITIONS` | Additional paths to search for build definitions. (Colon-separated list) | | `CC` | Path to the C compiler. | | `RUBY_CFLAGS` | Additional `CFLAGS` options (_e.g.,_ to override `-O3`). | diff --git a/bin/ruby-build b/bin/ruby-build index 51fde4bb47..b706d0f992 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -381,6 +381,10 @@ fetch_tarball() { local checksum local extracted_dir + if is_ruby_package "$1" && [ -n "$RUBY_BUILD_TARBALL_OVERRIDE" ]; then + package_url="$RUBY_BUILD_TARBALL_OVERRIDE" + fi + if [ "$package_url" != "${package_url/\#}" ]; then checksum="${package_url#*#}" package_url="${package_url%%#*}" @@ -1257,14 +1261,23 @@ isolated_gem_install() { apply_ruby_patch() { local patchfile - case "$1" in - ruby-* | jruby-* | rubinius-* | truffleruby-* ) + if is_ruby_package "$1"; then patchfile="$(mktemp "${TMP}/ruby-patch.XXXXXX")" cat "${2:--}" >"$patchfile" local striplevel=0 grep -q '^--- a/' "$patchfile" && striplevel=1 patch -p$striplevel --force -i "$patchfile" + fi +} + +is_ruby_package() { + case "$1" in + ruby-* | jruby-* | rubinius-* | truffleruby[+-]* | mruby-* | picoruby-* ) + return 0 + ;; + *) + return 1 ;; esac }