Commit 94c15a54 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Auto-detect and link to Homebrew's readline

I thought this was not necessary, but a number of people had problems
when linking to OS X's "readline" (actually Editline wrapper):

- Some components of Pry wouldn't work
- Writing literal Unicode characters was not possible #379
- The compilation would downright fail in some cases #82 #461

Fixes #461
parent 6f9647d7
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -398,6 +398,8 @@ build_package_standard() {
  local PACKAGE_MAKE_OPTS_ARRAY="${package_var_name}_MAKE_OPTS_ARRAY[@]"
  local PACKAGE_CFLAGS="${package_var_name}_CFLAGS"

  [ "$package_var_name" = "RUBY" ] && use_homebrew_readline || true

  ( if [ "${CFLAGS+defined}" ] || [ "${!PACKAGE_CFLAGS+defined}" ]; then
      export CFLAGS="$CFLAGS ${!PACKAGE_CFLAGS}"
    fi
@@ -664,6 +666,17 @@ use_homebrew_yaml() {
  fi
}

use_homebrew_readline() {
  if [[ "$RUBY_CONFIGURE_OPTS" != *--with-readline-dir=* ]]; then
    local libdir="$(brew --prefix readline 2>/dev/null || true)"
    if [ -d "$libdir" ]; then
      package_option ruby configure --with-readline-dir="$libdir"
    else
      return 1
    fi
  fi
}

has_broken_mac_openssl() {
  [ "$(uname -s)" = "Darwin" ] &&
  [[ "$(openssl version 2>/dev/null || true)" = "OpenSSL 0.9.8"?* ]] &&
+45 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ OUT
  brew_libdir="$TMP/homebrew-yaml"
  mkdir -p "$brew_libdir"

  stub brew "--prefix libyaml : echo '$brew_libdir'"
  stub brew "--prefix libyaml : echo '$brew_libdir'" false
  stub_make_install

  install_fixture definitions/needs-yaml
@@ -92,6 +92,50 @@ make -j 2
OUT
}

@test "readline is linked from Homebrew" {
  cached_tarball "ruby-2.0.0"

  readline_libdir="$TMP/homebrew-readline"
  mkdir -p "$readline_libdir"

  stub brew "--prefix readline : echo '$readline_libdir'"
  stub_make_install

  run_inline_definition <<DEF
install_package "ruby-2.0.0" "http://ruby-lang.org/ruby/2.0/ruby-2.0.0.tar.gz"
DEF
  assert_success

  unstub brew
  unstub make

  assert_build_log <<OUT
ruby-2.0.0: --prefix=$INSTALL_ROOT --with-readline-dir=$readline_libdir
make -j 2
OUT
}

@test "readline is not linked from Homebrew when explicitly defined" {
  cached_tarball "ruby-2.0.0"

  stub brew
  stub_make_install

  export RUBY_CONFIGURE_OPTS='--with-readline-dir=/custom'
  run_inline_definition <<DEF
install_package "ruby-2.0.0" "http://ruby-lang.org/ruby/2.0/ruby-2.0.0.tar.gz"
DEF
  assert_success

  unstub brew
  unstub make

  assert_build_log <<OUT
ruby-2.0.0: --prefix=$INSTALL_ROOT --with-readline-dir=/custom
make -j 2
OUT
}

@test "number of CPU cores defaults to 2" {
  cached_tarball "ruby-2.0.0"