Merge branch 'provide-bundle-rake'

This commit is contained in:
Mislav Marohnić 2013-10-26 18:35:10 +02:00
commit de409790d2
4 changed files with 100 additions and 15 deletions

View file

@ -699,6 +699,34 @@ build_package_verify_openssl() {
end' >&4 2>&1
}
rake() {
if [ -e "./Gemfile" ]; then
bundle exec rake "$@"
else
isolated_gem_dependency "rake --version" rake -v '~> 10.1.0'
command rake "$@"
fi
}
bundle() {
isolated_gem_dependency "bundle --version" bundler -v '~> 1.3.5'
command bundle "$@"
}
isolated_gem_dependency() {
local output="$(command $1 2>/dev/null || true)"
if [ -z "$output" ]; then
shift 1
isolated_gem_install "$@"
fi
}
isolated_gem_install() {
export GEM_HOME="${PWD}/.gem"
export PATH="${GEM_HOME}/bin:${PATH}"
gem install "$@"
}
version() {
echo "ruby-build ${RUBY_BUILD_VERSION}"
}

View file

@ -13,7 +13,7 @@ setup() {
cached_tarball() {
mkdir -p "$RUBY_BUILD_CACHE_PATH"
pushd "$RUBY_BUILD_CACHE_PATH" >/dev/null
tarball "$1"
tarball "$@"
popd >/dev/null
}
@ -21,14 +21,20 @@ tarball() {
local name="$1"
local path="$PWD/$name"
local configure="$path/configure"
shift 1
mkdir -p "$path"
cat > "$configure" <<OUT
#!$BASH
echo "$name: \$@" > build.log
echo "$name: \$@" >> build.log
OUT
chmod +x "$configure"
for file; do
mkdir -p "$(dirname "${path}/${file}")"
touch "${path}/${file}"
done
tar czf "${path}.tar.gz" -C "${path%/*}" "$name"
}
@ -122,23 +128,18 @@ OUT
}
@test "mruby strategy overwrites non-writable files" {
mkdir -p "$RUBY_BUILD_CACHE_PATH"
cd "$RUBY_BUILD_CACHE_PATH"
mkdir -p "mruby-1.0/build/host/bin"
touch "mruby-1.0/build/host/bin"/{mruby,mirb}
tar czf "mruby-1.0.tar.gz" "mruby-1.0"
cached_tarball "mruby-1.0" build/host/bin/{mruby,mirb}
mkdir -p "$INSTALL_ROOT/bin"
touch "$INSTALL_ROOT/bin/mruby"
chmod -w "$INSTALL_ROOT/bin/mruby"
cat > "definition" <<DEF
stub gem false
stub rake '--version : echo 1' true
run_inline_definition <<DEF
install_package "mruby-1.0" "http://ruby-lang.org/pub/mruby-1.0.tar.gz" mruby
DEF
stub rake true
run ruby-build "definition" "$INSTALL_ROOT"
assert_success
unstub rake
@ -147,3 +148,43 @@ DEF
assert [ -e "$INSTALL_ROOT/bin/ruby" ]
assert [ -e "$INSTALL_ROOT/bin/irb" ]
}
@test "mruby strategy fetches rake if missing" {
cached_tarball "mruby-1.0" build/host/bin/mruby
stub rake '--version : false' true
stub gem 'install rake -v *10.1.0 : true'
run_inline_definition <<DEF
install_package "mruby-1.0" "http://ruby-lang.org/pub/mruby-1.0.tar.gz" mruby
DEF
assert_success
unstub gem
unstub rake
}
@test "rbx uses bundle then rake" {
cached_tarball "rubinius-2.0.0" "Gemfile"
stub gem false
stub rake false
stub bundle \
'--version : echo 1' \
' : echo bundle >> build.log' \
'--version : echo 1' \
" exec rake install : { cat build.log; echo bundle \"\$@\"; } >> '$INSTALL_ROOT/build.log'"
run_inline_definition <<DEF
install_package "rubinius-2.0.0" "http://releases.rubini.us/rubinius-2.0.0.tar.gz" rbx
DEF
assert_success
unstub bundle
assert_build_log <<OUT
bundle
rubinius-2.0.0: --prefix=$INSTALL_ROOT
bundle exec rake install
OUT
}

View file

@ -11,6 +11,11 @@ _STUB_RUN="${PROGRAM}_STUB_RUN"
_STUB_INDEX="${PROGRAM}_STUB_INDEX"
_STUB_RESULT="${PROGRAM}_STUB_RESULT"
_STUB_END="${PROGRAM}_STUB_END"
_STUB_DEBUG="${PROGRAM}_STUB_DEBUG"
if [ -n "${!_STUB_DEBUG}" ]; then
echo "$program" "$@" >&${!_STUB_DEBUG}
fi
[ -e "${!_STUB_PLAN}" ] || exit 1
[ -n "${!_STUB_RUN}" ] || eval "${_STUB_RUN}"="${TMPDIR}/${program}-stub-run"

View file

@ -3,8 +3,10 @@ export TMP="$BATS_TEST_DIRNAME/tmp"
if [ "$FIXTURE_ROOT" != "$BATS_TEST_DIRNAME/fixtures" ]; then
export FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures"
export INSTALL_ROOT="$TMP/install"
export PATH="$BATS_TEST_DIRNAME/../bin:$PATH"
export PATH="$TMP/bin:$PATH"
PATH=/usr/bin:/usr/sbin:/bin/:/sbin
PATH="$BATS_TEST_DIRNAME/../bin:$PATH"
PATH="$TMP/bin:$PATH"
export PATH
fi
teardown() {
@ -34,9 +36,18 @@ unstub() {
export "${prefix}_STUB_END"=1
"$path"
local STATUS=0
"$path" || STATUS="$?"
rm -f "$path"
rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run"
return "$STATUS"
}
run_inline_definition() {
local definition="${TMP}/build-definition"
cat > "$definition"
run ruby-build "$definition" "${1:-$INSTALL_ROOT}"
}
install_fixture() {