Skip to content

Commit b034b8c

Browse files
committed
Add RUBY_BUILD_MIRROR_PACKAGE_URL to specify the complete mirror URL
Signed-off-by: Mingxiang Xue <mingxiangxue@gmail.com>
1 parent 1642176 commit b034b8c

File tree

3 files changed

+90
-24
lines changed

3 files changed

+90
-24
lines changed

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,29 @@ definitions.
6464

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

67-
| Variable | Function |
68-
| ------------------------ | ------------------------------------------------------------------------------------------------ |
69-
| `TMPDIR` | Where temporary files are stored. |
70-
| `RUBY_BUILD_BUILD_PATH` | Where sources are downloaded and built. (Default: a timestamped subdirectory of `TMPDIR`) |
71-
| `RUBY_BUILD_CACHE_PATH` | Where to cache downloaded package files. (Default: `~/.rbenv/cache` if invoked as rbenv plugin) |
72-
| `RUBY_BUILD_HTTP_CLIENT` | One of `aria2c`, `curl`, or `wget` to use for downloading. (Default: first one found in PATH) |
73-
| `RUBY_BUILD_ARIA2_OPTS` | Additional options to pass to `aria2c` for downloading. |
74-
| `RUBY_BUILD_CURL_OPTS` | Additional options to pass to `curl` for downloading. |
75-
| `RUBY_BUILD_WGET_OPTS` | Additional options to pass to `wget` for downloading. |
76-
| `RUBY_BUILD_MIRROR_URL` | Custom mirror URL root. |
77-
| `RUBY_BUILD_SKIP_MIRROR` | Bypass the download mirror and fetch all package files from their original URLs. |
78-
| `RUBY_BUILD_ROOT` | Custom build definition directory. (Default: `share/ruby-build`) |
79-
| `RUBY_BUILD_DEFINITIONS` | Additional paths to search for build definitions. (Colon-separated list) |
80-
| `CC` | Path to the C compiler. |
81-
| `RUBY_CFLAGS` | Additional `CFLAGS` options (_e.g.,_ to override `-O3`). |
82-
| `CONFIGURE_OPTS` | Additional `./configure` options. |
83-
| `MAKE` | Custom `make` command (_e.g.,_ `gmake`). |
84-
| `MAKE_OPTS` / `MAKEOPTS` | Additional `make` options. |
85-
| `MAKE_INSTALL_OPTS` | Additional `make install` options. |
86-
| `RUBY_CONFIGURE_OPTS` | Additional `./configure` options (applies only to Ruby source). |
87-
| `RUBY_MAKE_OPTS` | Additional `make` options (applies only to Ruby source). |
88-
| `RUBY_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Ruby source). |
67+
| Variable | Function |
68+
| ------------------------------- | ------------------------------------------------------------------------------------------------ |
69+
| `TMPDIR` | Where temporary files are stored. |
70+
| `RUBY_BUILD_BUILD_PATH` | Where sources are downloaded and built. (Default: a timestamped subdirectory of `TMPDIR`) |
71+
| `RUBY_BUILD_CACHE_PATH` | Where to cache downloaded package files. (Default: `~/.rbenv/cache` if invoked as rbenv plugin) |
72+
| `RUBY_BUILD_HTTP_CLIENT` | One of `aria2c`, `curl`, or `wget` to use for downloading. (Default: first one found in PATH) |
73+
| `RUBY_BUILD_ARIA2_OPTS` | Additional options to pass to `aria2c` for downloading. |
74+
| `RUBY_BUILD_CURL_OPTS` | Additional options to pass to `curl` for downloading. |
75+
| `RUBY_BUILD_WGET_OPTS` | Additional options to pass to `wget` for downloading. |
76+
| `RUBY_BUILD_MIRROR_URL` | Custom mirror URL root. |
77+
| `RUBY_BUILD_MIRROR_PACKAGE_URL` | Custom complete mirror URL (e.g. http://mirror.example.com/package-1.0.0.tar.gz). |
78+
| `RUBY_BUILD_SKIP_MIRROR` | Bypass the download mirror and fetch all package files from their original URLs. |
79+
| `RUBY_BUILD_ROOT` | Custom build definition directory. (Default: `share/ruby-build`) |
80+
| `RUBY_BUILD_DEFINITIONS` | Additional paths to search for build definitions. (Colon-separated list) |
81+
| `CC` | Path to the C compiler. |
82+
| `RUBY_CFLAGS` | Additional `CFLAGS` options (_e.g.,_ to override `-O3`). |
83+
| `CONFIGURE_OPTS` | Additional `./configure` options. |
84+
| `MAKE` | Custom `make` command (_e.g.,_ `gmake`). |
85+
| `MAKE_OPTS` / `MAKEOPTS` | Additional `make` options. |
86+
| `MAKE_INSTALL_OPTS` | Additional `make install` options. |
87+
| `RUBY_CONFIGURE_OPTS` | Additional `./configure` options (applies only to Ruby source). |
88+
| `RUBY_MAKE_OPTS` | Additional `make` options (applies only to Ruby source). |
89+
| `RUBY_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Ruby source). |
8990

9091
#### Applying Patches
9192

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

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

138+
If a mirror site doesn't conform to the above URL format, you can specify the
139+
complete URL by setting `RUBY_BUILD_MIRROR_PACKAGE_URL`. It behaves the same as
140+
`RUBY_BUILD_MIRROR_URL` except being a complete URL.
141+
137142
The default ruby-build download mirror is sponsored by
138143
[Basecamp](https://basecamp.com/).
139144

bin/ruby-build

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ fetch_tarball() {
365365
if [[ -z "$RUBY_BUILD_DEFAULT_MIRROR" || $package_url != */cache.ruby-lang.org/* ]]; then
366366
mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
367367
fi
368+
elif [ -n "$RUBY_BUILD_MIRROR_PACKAGE_URL" ]; then
369+
mirror_url="$RUBY_BUILD_MIRROR_PACKAGE_URL"
368370
fi
369371
fi
370372

@@ -1377,7 +1379,7 @@ else
13771379
unset RUBY_BUILD_CACHE_PATH
13781380
fi
13791381

1380-
if [ -z "$RUBY_BUILD_MIRROR_URL" ]; then
1382+
if [ -z "$RUBY_BUILD_MIRROR_URL" -a -z "$RUBY_BUILD_MIRROR_PACKAGE_URL" ]; then
13811383
RUBY_BUILD_MIRROR_URL="https://dqw8nmjcqpjn7.cloudfront.net"
13821384
RUBY_BUILD_DEFAULT_MIRROR=1
13831385
else
@@ -1386,7 +1388,7 @@ else
13861388
fi
13871389

13881390
if [ -n "$RUBY_BUILD_SKIP_MIRROR" ] || ! has_checksum_support compute_sha2; then
1389-
unset RUBY_BUILD_MIRROR_URL
1391+
unset RUBY_BUILD_MIRROR_URL RUBY_BUILD_MIRROR_PACKAGE_URL
13901392
fi
13911393

13921394
ARIA2_OPTS="${RUBY_BUILD_ARIA2_OPTS} ${IPV4+--disable-ipv6=true} ${IPV6+--disable-ipv6=false}"

test/mirror.bats

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,62 @@ DEF
126126
unstub curl
127127
unstub shasum
128128
}
129+
130+
131+
@test "package is fetched from complete mirror URL" {
132+
export RUBY_BUILD_MIRROR_URL=
133+
export RUBY_BUILD_MIRROR_PACKAGE_URL=http://mirror.example.com/package-1.0.0.tar.gz
134+
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
135+
136+
stub shasum true "echo $checksum"
137+
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : true" \
138+
"-q -o * -*S* $RUBY_BUILD_MIRROR_PACKAGE_URL : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
139+
140+
install_fixture definitions/with-checksum
141+
142+
assert_success
143+
assert [ -x "${INSTALL_ROOT}/bin/package" ]
144+
145+
unstub curl
146+
unstub shasum
147+
}
148+
149+
150+
@test "package is fetched from original URL if complete mirror URL download fails" {
151+
export RUBY_BUILD_MIRROR_URL=
152+
export RUBY_BUILD_MIRROR_PACKAGE_URL=http://mirror.example.com/package-1.0.0.tar.gz
153+
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
154+
155+
stub shasum true "echo $checksum"
156+
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : false" \
157+
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
158+
159+
install_fixture definitions/with-checksum
160+
161+
assert_success
162+
assert [ -x "${INSTALL_ROOT}/bin/package" ]
163+
164+
unstub curl
165+
unstub shasum
166+
}
167+
168+
169+
@test "package is fetched from original URL if complete mirror URL download checksum is invalid" {
170+
export RUBY_BUILD_MIRROR_URL=
171+
export RUBY_BUILD_MIRROR_PACKAGE_URL=http://mirror.example.com/package-1.0.0.tar.gz
172+
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
173+
174+
stub shasum true "echo invalid" "echo $checksum"
175+
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : true" \
176+
"-q -o * -*S* $RUBY_BUILD_MIRROR_PACKAGE_URL : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
177+
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
178+
179+
install_fixture definitions/with-checksum
180+
echo "$output" >&2
181+
182+
assert_success
183+
assert [ -x "${INSTALL_ROOT}/bin/package" ]
184+
185+
unstub curl
186+
unstub shasum
187+
}

0 commit comments

Comments
 (0)