From 4e2177d5c2b5dfe963e58f8bbdde5272808bf5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 16 Aug 2014 19:56:40 -0700 Subject: [PATCH 1/3] Add test for ruby-build definitions --- test/definitions.bats | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/definitions.bats diff --git a/test/definitions.bats b/test/definitions.bats new file mode 100644 index 00000000..4a9c1468 --- /dev/null +++ b/test/definitions.bats @@ -0,0 +1,18 @@ +#!/usr/bin/env bats + +load test_helper +NUM_DEFINITIONS="$(ls "$BATS_TEST_DIRNAME"/../share/ruby-build | wc -l)" + +@test "list built-in definitions" { + run ruby-build --definitions + assert_success + assert_output_contains "1.9.3-p194" + assert_output_contains "jruby-1.7.9" + assert [ "${#lines[*]}" -eq "$NUM_DEFINITIONS" ] +} + +@test "installing nonexistent definition" { + run ruby-build "nonexistent" "${TMP}/install" + assert [ "$status" -eq 2 ] + assert_output "ruby-build: definition not found: nonexistent" +} From ff75ca72045ce54b4c47d1b5c51e3d921cc63c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 16 Aug 2014 19:58:43 -0700 Subject: [PATCH 2/3] Support changing RUBY_BUILD_ROOT This is to allow specifying an alternate path where `share/ruby-build/*` definitions reside. Useful in tests as well. --- README.md | 2 ++ bin/ruby-build | 7 ++++++- test/definitions.bats | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d8e8997..53457c13 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,8 @@ You can set certain environment variables to control the build process. choosing. * `RUBY_BUILD_SKIP_MIRROR`, if set, forces ruby-build to download packages from their original source URLs instead of using a mirror. +* `RUBY_BUILD_ROOT` overrides the default location from where build definitions + in `share/ruby-build/` are looked up. * `CC` sets the path to the C compiler. * `RUBY_CFLAGS` lets you pass additional options to the default `CFLAGS`. Use this to override, for instance, the `-O3` option. diff --git a/bin/ruby-build b/bin/ruby-build index e3c65452..cea18318 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -907,10 +907,12 @@ usage() { } list_definitions() { + shopt -s nullglob { for definition in "${RUBY_BUILD_ROOT}/share/ruby-build/"*; do echo "${definition##*/}" done } | sort + shopt -u nullglob } @@ -918,7 +920,10 @@ list_definitions() { unset VERBOSE unset KEEP_BUILD_PATH unset HAS_PATCH -RUBY_BUILD_ROOT="$(abs_dirname "$0")/.." + +if [ -z "$RUBY_BUILD_ROOT" ]; then + RUBY_BUILD_ROOT="$(abs_dirname "$0")/.." +fi parse_options "$@" diff --git a/test/definitions.bats b/test/definitions.bats index 4a9c1468..59084bc3 100644 --- a/test/definitions.bats +++ b/test/definitions.bats @@ -11,6 +11,21 @@ NUM_DEFINITIONS="$(ls "$BATS_TEST_DIRNAME"/../share/ruby-build | wc -l)" assert [ "${#lines[*]}" -eq "$NUM_DEFINITIONS" ] } +@test "custom RUBY_BUILD_ROOT: nonexistent" { + export RUBY_BUILD_ROOT="$TMP" + assert [ ! -e "${RUBY_BUILD_ROOT}/share/ruby-build" ] + run ruby-build --definitions + assert_success "" +} + +@test "custom RUBY_BUILD_ROOT: single definition" { + export RUBY_BUILD_ROOT="$TMP" + mkdir -p "${RUBY_BUILD_ROOT}/share/ruby-build" + touch "${RUBY_BUILD_ROOT}/share/ruby-build/1.9.3-test" + run ruby-build --definitions + assert_success "1.9.3-test" +} + @test "installing nonexistent definition" { run ruby-build "nonexistent" "${TMP}/install" assert [ "$status" -eq 2 ] From f118b173af0671ab35f2d10f7c2e33818e847a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 16 Aug 2014 20:01:00 -0700 Subject: [PATCH 3/3] Extra definitions paths via RUBY_BUILD_DEFINITIONS This is a colon-separated list of directories that will get searched for build definition in order from left to right. --- README.md | 2 ++ bin/ruby-build | 22 ++++++++++++++-------- test/definitions.bats | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 53457c13..378b9321 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,8 @@ You can set certain environment variables to control the build process. their original source URLs instead of using a mirror. * `RUBY_BUILD_ROOT` overrides the default location from where build definitions in `share/ruby-build/` are looked up. +* `RUBY_BUILD_DEFINITIONS` can be a list of colon-separated paths that get + additionally searched when looking up build definitions. * `CC` sets the path to the C compiler. * `RUBY_CFLAGS` lets you pass additional options to the default `CFLAGS`. Use this to override, for instance, the `-O3` option. diff --git a/bin/ruby-build b/bin/ruby-build index cea18318..5fee8a3f 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -907,12 +907,10 @@ usage() { } list_definitions() { - shopt -s nullglob - { for definition in "${RUBY_BUILD_ROOT}/share/ruby-build/"*; do - echo "${definition##*/}" + { for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do + [ -d "$DEFINITION_DIR" ] && ls "$DEFINITION_DIR" done } | sort - shopt -u nullglob } @@ -925,6 +923,10 @@ if [ -z "$RUBY_BUILD_ROOT" ]; then RUBY_BUILD_ROOT="$(abs_dirname "$0")/.." fi +OLDIFS="$IFS" +IFS=: RUBY_BUILD_DEFINITIONS=($RUBY_BUILD_DEFINITIONS ${RUBY_BUILD_ROOT}/share/ruby-build) +IFS="$OLDIFS" + parse_options "$@" for option in "${OPTIONS[@]}"; do @@ -964,10 +966,14 @@ DEFINITION_PATH="${ARGUMENTS[0]}" if [ -z "$DEFINITION_PATH" ]; then usage elif [ ! -f "$DEFINITION_PATH" ]; then - BUILTIN_DEFINITION_PATH="${RUBY_BUILD_ROOT}/share/ruby-build/${DEFINITION_PATH}" - if [ -e "$BUILTIN_DEFINITION_PATH" ]; then - DEFINITION_PATH="$BUILTIN_DEFINITION_PATH" - else + for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do + if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then + DEFINITION_PATH="${DEFINITION_DIR}/${DEFINITION_PATH}" + break + fi + done + + if [ ! -f "$DEFINITION_PATH" ]; then echo "ruby-build: definition not found: ${DEFINITION_PATH}" >&2 exit 2 fi diff --git a/test/definitions.bats b/test/definitions.bats index 59084bc3..51692ccc 100644 --- a/test/definitions.bats +++ b/test/definitions.bats @@ -26,6 +26,39 @@ NUM_DEFINITIONS="$(ls "$BATS_TEST_DIRNAME"/../share/ruby-build | wc -l)" assert_success "1.9.3-test" } +@test "one path via RUBY_BUILD_DEFINITIONS" { + export RUBY_BUILD_DEFINITIONS="${TMP}/definitions" + mkdir -p "$RUBY_BUILD_DEFINITIONS" + touch "${RUBY_BUILD_DEFINITIONS}/1.9.3-test" + run ruby-build --definitions + assert_success + assert_output_contains "1.9.3-test" + assert [ "${#lines[*]}" -eq "$((NUM_DEFINITIONS + 1))" ] +} + +@test "multiple paths via RUBY_BUILD_DEFINITIONS" { + export RUBY_BUILD_DEFINITIONS="${TMP}/definitions:${TMP}/other" + mkdir -p "${TMP}/definitions" + touch "${TMP}/definitions/1.9.3-test" + mkdir -p "${TMP}/other" + touch "${TMP}/other/2.1.2-test" + run ruby-build --definitions + assert_success + assert_output_contains "1.9.3-test" + assert_output_contains "2.1.2-test" + assert [ "${#lines[*]}" -eq "$((NUM_DEFINITIONS + 2))" ] +} + +@test "installing definition from RUBY_BUILD_DEFINITIONS by priority" { + export RUBY_BUILD_DEFINITIONS="${TMP}/definitions:${TMP}/other" + mkdir -p "${TMP}/definitions" + echo true > "${TMP}/definitions/1.9.3-test" + mkdir -p "${TMP}/other" + echo false > "${TMP}/other/1.9.3-test" + run bin/ruby-build "1.9.3-test" "${TMP}/install" + assert_success "" +} + @test "installing nonexistent definition" { run ruby-build "nonexistent" "${TMP}/install" assert [ "$status" -eq 2 ]