Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull ruby build #901

Merged
merged 12 commits into from
Jun 1, 2024
68 changes: 37 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,30 @@ definitions.

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

| Variable | Function |
| ------------------------ | -------------------------------------------------------------------------------------------------- |
| `TMPDIR` | Where temporary files are stored. |
| `NODE_BUILD_BUILD_PATH` | Where sources are downloaded and built. (Default: a timestamped subdirectory of `TMPDIR`) |
| `NODE_BUILD_CACHE_PATH` | Where to cache downloaded package files. (Default: `~/.nodenv/cache` if invoked as nodenv plugin) |
| `NODE_BUILD_HTTP_CLIENT` | One of `aria2c`, `curl`, or `wget` to use for downloading. (Default: first one found in PATH) |
| `NODE_BUILD_ARIA2_OPTS` | Additional options to pass to `aria2c` for downloading. |
| `NODE_BUILD_CURL_OPTS` | Additional options to pass to `curl` for downloading. |
| `NODE_BUILD_WGET_OPTS` | Additional options to pass to `wget` for downloading. |
| `NODE_BUILD_MIRROR_CMD` | A command to construct the package mirror URL. |
| `NODE_BUILD_MIRROR_URL` | Custom mirror URL root. |
| `NODE_BUILD_SKIP_MIRROR` | Bypass the download mirror and fetch all package files from their original URLs. |
| `NODE_BUILD_ROOT` | Custom build definition directory. (Default: `share/node-build`) |
| `NODE_BUILD_DEFINITIONS` | Additional paths to search for build definitions. (Colon-separated list) |
| `CC` | Path to the C compiler. |
| `NODE_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. |
| `NODE_CONFIGURE_OPTS` | Additional `./configure` options (applies only to Node source). |
| `NODE_MAKE_OPTS` | Additional `make` options (applies only to Node source). |
| `NODE_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Node source). |
| Variable | Function |
| ------------------------------- | -------------------------------------------------------------------------------------------------- |
| `TMPDIR` | Where temporary files are stored. |
| `NODE_BUILD_BUILD_PATH` | Where sources are downloaded and built. (Default: a timestamped subdirectory of `TMPDIR`) |
| `NODE_BUILD_CACHE_PATH` | Where to cache downloaded package files. (Default: `~/.nodenv/cache` if invoked as nodenv plugin) |
| `NODE_BUILD_HTTP_CLIENT` | One of `aria2c`, `curl`, or `wget` to use for downloading. (Default: first one found in PATH) |
| `NODE_BUILD_ARIA2_OPTS` | Additional options to pass to `aria2c` for downloading. |
| `NODE_BUILD_CURL_OPTS` | Additional options to pass to `curl` for downloading. |
| `NODE_BUILD_WGET_OPTS` | Additional options to pass to `wget` for downloading. |
| `NODE_BUILD_MIRROR_CMD` | A command to construct the package mirror URL. |
| `NODE_BUILD_MIRROR_URL` | Custom mirror URL root. |
| `NODE_BUILD_MIRROR_PACKAGE_URL` | Custom complete mirror URL (e.g. http://mirror.example.com/package-1.0.0.tar.gz). |
| `NODE_BUILD_SKIP_MIRROR` | Bypass the download mirror and fetch all package files from their original URLs. |
| `NODE_BUILD_ROOT` | Custom build definition directory. (Default: `share/node-build`) |
| `NODE_BUILD_DEFINITIONS` | Additional paths to search for build definitions. (Colon-separated list) |
| `CC` | Path to the C compiler. |
| `NODE_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. |
| `NODE_CONFIGURE_OPTS` | Additional `./configure` options (applies only to Node source). |
| `NODE_MAKE_OPTS` | Additional `make` options (applies only to Node source). |
| `NODE_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Node source). |

#### Applying Patches

Expand Down Expand Up @@ -169,21 +170,17 @@ definition. All definitions bundled with node-build include checksums.

#### Package Mirrors

By default, node-build downloads package files from the official URL specified in the definition file.
To speed up downloads, node-build can fetch package files from a mirror.
To benefit from this, the packages must specify their checksum:

```sh
# example:
install_package "node-v12.0.0" "https://nodejs.org/dist/v12.0.0/node-v12.0.0.tar.gz#<SHA2>"
```

node-build will attempt to construct a mirror url by invoking `NODE_BUILD_MIRROR_CMD` with two arguments: `package_url` and `checksum`.
The provided command should print the desired mirror's complete package URL.
If `NODE_BUILD_MIRROR_CMD` is unset, package mirror URL construction defaults to replacing `https://nodejs.org/dist` with `NODE_BUILD_MIRROR_URL`.

node-build will first try to fetch this package from `$NODE_BUILD_MIRROR_URL/<SHA2>`
(note: this is the complete URL), where `<SHA2>` is the checksum for the file.

It will fall back to downloading the package from the original location if:
(note: this is the complete URL), where `<SHA2>` is the checksum for the file. It
will fall back to downloading the package from the original location if:
- the package was not found on the mirror;
- the mirror is down;
- the download is corrupt, i.e. the file's checksum doesn't match;
Expand All @@ -192,6 +189,15 @@ It will fall back to downloading the package from the original location if:

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

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

For more control over the construction of the mirror url, you can specify a command
by setting `NODE_BUILD_MIRROR_CMD`. node-build will invoke `NODE_BUILD_MIRROR_CMD`
with two arguments: `package_url` and `checksum`. The provided command should
print the desired mirror's complete package URL to `STDOUT`.

#### Keeping the build directory after installation

Both `node-build` and `nodenv install` accept the `-k` or `--keep` flag, which
Expand Down
9 changes: 7 additions & 2 deletions bin/node-build
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OLDIFS="$IFS"
set -E
exec 3<&2 # preserve original stderr at fd 3


lib() {
parse_options() {
OPTIONS=()
Expand Down Expand Up @@ -213,7 +214,11 @@ mirror() {
local package_url="$1"
local checksum="$2"

echo "${package_url/https:\/\/nodejs.org\/dist/$NODE_BUILD_MIRROR_URL}"
if [ -n "$NODE_BUILD_MIRROR_URL" ]; then
echo "${package_url/https:\/\/nodejs.org\/dist/$NODE_BUILD_MIRROR_URL}"
elif [ -n "$NODE_BUILD_MIRROR_PACKAGE_URL" ]; then
echo "$NODE_BUILD_MIRROR_PACKAGE_URL"
fi
}

try_binary(){
Expand Down Expand Up @@ -1011,7 +1016,7 @@ WGET_OPTS="${NODE_BUILD_WGET_OPTS} ${IPV4+--inet4-only} ${IPV6+--inet6-only}"
NODE_BUILD_MIRROR_URL="${NODE_BUILD_MIRROR_URL%/}"

if ! has_checksum_support compute_sha2 ||
{ [ -z "$NODE_BUILD_MIRROR_URL" ] && [ -z "$NODE_BUILD_MIRROR_CMD" ]; } then
[ -z "$NODE_BUILD_MIRROR_URL" -a -z "$NODE_BUILD_MIRROR_CMD" -a -z "$NODE_BUILD_MIRROR_PACKAGE_URL" ]; then
NODE_BUILD_SKIP_MIRROR=true
fi

Expand Down
2 changes: 1 addition & 1 deletion bin/nodenv-install
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ for option in "${OPTIONS[@]}"; do
{
echo
echo "Only latest stable releases for each Node implementation are shown."
echo "Use 'nodenv install --list-all' to show all local versions."
echo "Use 'nodenv install --list-all / -L' to show all local versions."
} 1>&2
exit
;;
Expand Down
68 changes: 68 additions & 0 deletions test/mirror.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load test_helper
export NODE_BUILD_SKIP_MIRROR=
export NODE_BUILD_CACHE_PATH=
export NODE_BUILD_MIRROR_URL=http://mirror.example.com
# TODO move into tests so mirror_cmd doesn't need stubbed in _every_ test
export NODE_BUILD_MIRROR_CMD=mirror_stub


Expand Down Expand Up @@ -90,3 +91,70 @@ export NODE_BUILD_MIRROR_CMD=mirror_stub
unstub curl
unstub shasum
}


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

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

install_fixture definitions/with-checksum

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

unstub mirror_stub
unstub curl
unstub shasum
}


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

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

install_fixture definitions/with-checksum

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

unstub mirror_stub
unstub curl
unstub shasum
}


@test "package is fetched from original URL if complete mirror URL download checksum is invalid" {
export NODE_BUILD_MIRROR_URL=
export NODE_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 "-q -o * -*S* $NODE_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"
stub mirror_stub ": echo $NODE_BUILD_MIRROR_PACKAGE_URL"

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

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

unstub mirror_stub
unstub curl
unstub shasum
}

@test "package is fetched from mirror URL constructed from MIRROR_CMD" {
skip "TODO: test this scenario"
}