Skip to content

Commit

Permalink
Merge pull request #1457 from uzxmx/feature/specify-complete-mirror-url
Browse files Browse the repository at this point in the history
Support specifying the complete mirror URL
  • Loading branch information
hsbt committed Dec 3, 2020
2 parents 5038d9e + b034b8c commit 99f6bcb
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 24 deletions.
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,29 @@ definitions.

The build process may be configured through the following environment variables:

| Variable | Function |
| ------------------------ | ------------------------------------------------------------------------------------------------ |
| `TMPDIR` | Where temporary files are stored. |
| `RUBY_BUILD_BUILD_PATH` | Where sources are downloaded and built. (Default: a timestamped subdirectory of `TMPDIR`) |
| `RUBY_BUILD_CACHE_PATH` | Where to cache downloaded package files. (Default: `~/.rbenv/cache` if invoked as rbenv plugin) |
| `RUBY_BUILD_HTTP_CLIENT` | One of `aria2c`, `curl`, or `wget` to use for downloading. (Default: first one found in PATH) |
| `RUBY_BUILD_ARIA2_OPTS` | Additional options to pass to `aria2c` for downloading. |
| `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_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_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`). |
| `CONFIGURE_OPTS` | Additional `./configure` options. |
| `MAKE` | Custom `make` command (_e.g.,_ `gmake`). |
| `MAKE_OPTS` / `MAKEOPTS` | Additional `make` options. |
| `MAKE_INSTALL_OPTS` | Additional `make install` options. |
| `RUBY_CONFIGURE_OPTS` | Additional `./configure` options (applies only to Ruby source). |
| `RUBY_MAKE_OPTS` | Additional `make` options (applies only to Ruby source). |
| `RUBY_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Ruby source). |
| Variable | Function |
| ------------------------------- | ------------------------------------------------------------------------------------------------ |
| `TMPDIR` | Where temporary files are stored. |
| `RUBY_BUILD_BUILD_PATH` | Where sources are downloaded and built. (Default: a timestamped subdirectory of `TMPDIR`) |
| `RUBY_BUILD_CACHE_PATH` | Where to cache downloaded package files. (Default: `~/.rbenv/cache` if invoked as rbenv plugin) |
| `RUBY_BUILD_HTTP_CLIENT` | One of `aria2c`, `curl`, or `wget` to use for downloading. (Default: first one found in PATH) |
| `RUBY_BUILD_ARIA2_OPTS` | Additional options to pass to `aria2c` for downloading. |
| `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_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_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`). |
| `CONFIGURE_OPTS` | Additional `./configure` options. |
| `MAKE` | Custom `make` command (_e.g.,_ `gmake`). |
| `MAKE_OPTS` / `MAKEOPTS` | Additional `make` options. |
| `MAKE_INSTALL_OPTS` | Additional `make install` options. |
| `RUBY_CONFIGURE_OPTS` | Additional `./configure` options (applies only to Ruby source). |
| `RUBY_MAKE_OPTS` | Additional `make` options (applies only to Ruby source). |
| `RUBY_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Ruby source). |

#### Applying Patches

Expand Down Expand Up @@ -134,6 +135,10 @@ will fall back to downloading the package from the original location if:

You may specify a custom mirror by setting `RUBY_BUILD_MIRROR_URL`.

If a mirror site doesn't conform to the above URL format, you can specify the
complete URL by setting `RUBY_BUILD_MIRROR_PACKAGE_URL`. It behaves the same as
`RUBY_BUILD_MIRROR_URL` except being a complete URL.

The default ruby-build download mirror is sponsored by
[Basecamp](https://basecamp.com/).

Expand Down
6 changes: 4 additions & 2 deletions bin/ruby-build
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ fetch_tarball() {
if [[ -z "$RUBY_BUILD_DEFAULT_MIRROR" || $package_url != */cache.ruby-lang.org/* ]]; then
mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
fi
elif [ -n "$RUBY_BUILD_MIRROR_PACKAGE_URL" ]; then
mirror_url="$RUBY_BUILD_MIRROR_PACKAGE_URL"
fi
fi

Expand Down Expand Up @@ -1409,7 +1411,7 @@ else
unset RUBY_BUILD_CACHE_PATH
fi

if [ -z "$RUBY_BUILD_MIRROR_URL" ]; then
if [ -z "$RUBY_BUILD_MIRROR_URL" -a -z "$RUBY_BUILD_MIRROR_PACKAGE_URL" ]; then
RUBY_BUILD_MIRROR_URL="https://dqw8nmjcqpjn7.cloudfront.net"
RUBY_BUILD_DEFAULT_MIRROR=1
else
Expand All @@ -1418,7 +1420,7 @@ else
fi

if [ -n "$RUBY_BUILD_SKIP_MIRROR" ] || ! has_checksum_support compute_sha2; then
unset RUBY_BUILD_MIRROR_URL
unset RUBY_BUILD_MIRROR_URL RUBY_BUILD_MIRROR_PACKAGE_URL
fi

ARIA2_OPTS="${RUBY_BUILD_ARIA2_OPTS} ${IPV4+--disable-ipv6=true} ${IPV6+--disable-ipv6=false}"
Expand Down
59 changes: 59 additions & 0 deletions test/mirror.bats
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,62 @@ DEF
unstub curl
unstub shasum
}


@test "package is fetched from complete mirror URL" {
export RUBY_BUILD_MIRROR_URL=
export RUBY_BUILD_MIRROR_PACKAGE_URL=http://mirror.example.com/package-1.0.0.tar.gz
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"

stub shasum true "echo $checksum"
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : true" \
"-q -o * -*S* $RUBY_BUILD_MIRROR_PACKAGE_URL : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"

install_fixture definitions/with-checksum

assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]

unstub curl
unstub shasum
}


@test "package is fetched from original URL if complete mirror URL download fails" {
export RUBY_BUILD_MIRROR_URL=
export RUBY_BUILD_MIRROR_PACKAGE_URL=http://mirror.example.com/package-1.0.0.tar.gz
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"

stub shasum true "echo $checksum"
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : false" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"

install_fixture definitions/with-checksum

assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]

unstub curl
unstub shasum
}


@test "package is fetched from original URL if complete mirror URL download checksum is invalid" {
export RUBY_BUILD_MIRROR_URL=
export RUBY_BUILD_MIRROR_PACKAGE_URL=http://mirror.example.com/package-1.0.0.tar.gz
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"

stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : true" \
"-q -o * -*S* $RUBY_BUILD_MIRROR_PACKAGE_URL : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"

install_fixture definitions/with-checksum
echo "$output" >&2

assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]

unstub curl
unstub shasum
}

0 comments on commit 99f6bcb

Please sign in to comment.