Unverified Commit 56242478 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Simplify build_package_rbx

This removes the `isolated_gem_dependency` hack as well as the `rake` &
`bundle` shell wrapper functions. The main reason is to avoid having to
use the `command` shell builtin to be able to invoke the real `rake` and
`bundle`. In my testing on bash 3.2, `command` does not respect the
usual bash error handling rules, and thus a failed `command` invocation
can trigger the ERR trap mechanism even when we don't want it to.
parent ae653983
Loading
Loading
Loading
Loading
+46 −78
Original line number Diff line number Diff line
@@ -743,9 +743,12 @@ build_package_ree_installer() {
}

build_package_rbx() {
  local package_name="$1"
  export PATH="${PWD}/.gem/bin:${PATH}"
  if [ -e "Gemfile" ]; then
    bundle --version &>/dev/null || GEM_HOME="${PWD}/.gem" capture_command gem install bundler -v '~> 1.3.5'
    capture_command bundle --path=vendor/bundle
  fi

  { [ ! -e "Gemfile" ] || bundle --path=vendor/bundle
  if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
    mkdir -p vendor
    ln -s "$RUBY_BUILD_CACHE_PATH" vendor/prebuilt
@@ -764,11 +767,33 @@ build_package_rbx() {
  done

  # shellcheck disable=SC2086
    RUBYOPT="-rrubygems $RUBYOPT" ./configure --prefix="$PREFIX_PATH" "${configure_opts[@]}" $RUBY_CONFIGURE_OPTS
    rake install
    fix_rbx_gem_binstubs "$PREFIX_PATH"
    fix_rbx_irb "$PREFIX_PATH"
  } >&4 2>&1
  RUBYOPT="-rrubygems $RUBYOPT" capture_command ./configure --prefix="$PREFIX_PATH" "${configure_opts[@]}" $RUBY_CONFIGURE_OPTS
  if [ -e "Gemfile" ]; then
    capture_command bundle exec rake install
  else
    rake --version &>/dev/null || GEM_HOME="${PWD}/.gem" capture_command gem install rake -v '~> 10.1.0'
    capture_command rake install
  fi

  local gemdir="${PREFIX_PATH}/gems/bin"
  local file binstub
  # Symlink Rubinius' `gems/bin/` into `bin/`
  if [ -d "$gemdir" ] && [ ! -L "$gemdir" ]; then
    for file in "$gemdir"/*; do
      binstub="${PREFIX_PATH}/bin/${file##*/}"
      rm -f "$binstub"
      { echo "#!${PREFIX_PATH}/bin/ruby"
        grep -v '^#!' "$file"
      } > "$binstub"
      chmod +x "$binstub"
    done
    rm -rf "$gemdir"
    ln -s ../bin "$gemdir"
  fi

  "${PREFIX_PATH}/bin/irb" --version &>/dev/null ||
    capture_command "${PREFIX_PATH}/bin/gem" install rubysl-tracer -v '~> 2.0' --no-rdoc --no-ri ||
    true
}

build_package_mruby() {
@@ -902,33 +927,6 @@ after_install_package() {
  local stub=1
}

fix_rbx_gem_binstubs() {
  local prefix="$1"
  local gemdir="${prefix}/gems/bin"
  local bindir="${prefix}/bin"
  local file binstub
  # Symlink Rubinius' `gems/bin/` into `bin/`
  if [ -d "$gemdir" ] && [ ! -L "$gemdir" ]; then
    for file in "$gemdir"/*; do
      binstub="${bindir}/${file##*/}"
      rm -f "$binstub"
      { echo "#!${bindir}/ruby"
        grep -v '^#!' "$file"
      } > "$binstub"
      chmod +x "$binstub"
    done
    rm -rf "$gemdir"
    ln -s ../bin "$gemdir"
  fi
}

fix_rbx_irb() {
  local prefix="$1"
  "${prefix}/bin/irb" --version &>/dev/null ||
    capture_command "${prefix}/bin/gem" install rubysl-tracer -v '~> 2.0' --no-rdoc --no-ri ||
    true
}

require_java() {
  local required="$1"
  local java_version version_string
@@ -1271,36 +1269,6 @@ build_package_auto_tcltk() {
  fi
}

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() {
  set +E
  ( command $1 &>/dev/null ) || {
    set -E
    shift 1
    isolated_gem_install "$@"
  }
  set -E
}

isolated_gem_install() {
  export GEM_HOME="${PWD}/.gem"
  export PATH="${GEM_HOME}/bin:${PATH}"
  gem install "$@"
}

apply_ruby_patch() {
  local patchfile
  if is_ruby_package "$1"; then
+1 −2
Original line number Diff line number Diff line
@@ -667,7 +667,6 @@ OUT
  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