Unverified Commit 784d7b71 authored by Mislav Marohnić's avatar Mislav Marohnić Committed by GitHub
Browse files

Merge pull request #1929 from dreyks/homebrew-ruby

Automatically detect and link to Homebrew's libyaml
parents 99cb5e3f 4cc9dc3b
Loading
Loading
Loading
Loading
+22 −19
Original line number Diff line number Diff line
@@ -558,9 +558,22 @@ build_package_standard_build() {
  local PACKAGE_CFLAGS="${package_var_name}_CFLAGS"

  if [ "$package_var_name" = "RUBY" ]; then
      use_homebrew_readline || use_freebsd_pkg ||true
    if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-readline-dir=* ]]; then
      use_homebrew_readline || use_freebsd_readline || true
    fi
    if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-libyaml-dir=* ]]; then
      use_homebrew_yaml || true
    fi
    if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-gmp-dir=* ]]; then
      use_homebrew_gmp || true
    fi
    if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-openssl-dir=* ]]; then
      if [ "FreeBSD" = "$(uname -s)" ] && [ -f /usr/local/include/openssl/ssl.h ]; then
        # use openssl installed from Ports Collection
        package_option ruby configure --with-openssl-dir="/usr/local"
      fi
    fi
  fi

  ( if [ "${CFLAGS+defined}" ] || [ "${!PACKAGE_CFLAGS+defined}" ]; then
      export CFLAGS="$CFLAGS ${!PACKAGE_CFLAGS}"
@@ -1037,18 +1050,10 @@ use_homebrew_gmp() {
  fi
}

use_freebsd_pkg() {
  # check if FreeBSD
use_freebsd_readline() {
  if [ "FreeBSD" = "$(uname -s)" ]; then
    # use openssl if installed from Ports Collection
    if [ -f /usr/local/include/openssl/ssl.h ]; then
      package_option ruby configure --with-openssl-dir="/usr/local"
    fi

    # check if 11-R or later
    release="$(uname -r)"
    local release="$(uname -r)"
    if [ "${release%%.*}" -ge 11 ]; then
      # prefers readline to compile most of ruby versions
      if pkg info -e readline > /dev/null; then
        # use readline from Ports Collection
        package_option ruby configure --with-readline-dir="/usr/local"
@@ -1062,7 +1067,6 @@ use_freebsd_pkg() {
}

use_homebrew_readline() {
  if [[ "$RUBY_CONFIGURE_OPTS" != *--with-readline-dir=* ]]; then
  local libdir="$(brew --prefix readline 2>/dev/null || true)"
  if [ -d "$libdir" ]; then
    echo "ruby-build: using readline from homebrew"
@@ -1070,7 +1074,6 @@ use_homebrew_readline() {
  else
    return 1
  fi
  fi
}

has_broken_mac_openssl() {
+27 −21
Original line number Diff line number Diff line
@@ -61,8 +61,8 @@ assert_build_log() {
  cached_tarball "yaml-0.1.6"
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Linux'
  stub brew false
  stub_repeated uname '-s : echo Linux'
  stub_repeated brew false
  stub_make_install
  stub_make_install

@@ -70,6 +70,7 @@ assert_build_log() {
  assert_success

  unstub uname
  unstub brew
  unstub make

  assert_build_log <<OUT
@@ -86,8 +87,8 @@ OUT
  cached_tarball "yaml-0.1.6"
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Linux'
  stub brew false
  stub_repeated uname '-s : echo Linux'
  stub_repeated brew false
  stub_make_install
  stub_make_install
  stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
@@ -100,6 +101,7 @@ PATCH
  assert_success

  unstub uname
  unstub brew
  unstub make
  unstub patch

@@ -118,8 +120,8 @@ OUT
  cached_tarball "yaml-0.1.6"
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Linux'
  stub brew false
  stub_repeated uname '-s : echo Linux'
  stub_repeated brew false
  stub_make_install
  stub_make_install
  stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
@@ -132,6 +134,7 @@ PATCH
  assert_success

  unstub uname
  unstub brew
  unstub make
  unstub patch

@@ -150,8 +153,8 @@ OUT
  cached_tarball "yaml-0.1.6"
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Linux'
  stub brew false
  stub_repeated uname '-s : echo Linux'
  stub_repeated brew false
  stub_make_install
  stub_make_install
  stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
@@ -165,6 +168,7 @@ PATCH
  assert_success

  unstub uname
  unstub brew
  unstub make
  unstub patch

@@ -185,11 +189,13 @@ OUT
  brew_libdir="$TMP/homebrew-yaml"
  mkdir -p "$brew_libdir"

  stub uname '-s : echo Linux'
  stub brew "--prefix libyaml : echo '$brew_libdir'" false false
  stub_repeated uname '-s : echo Linux'
  stub_repeated brew "--prefix libyaml : echo '$brew_libdir'"
  stub_make_install

  install_fixture definitions/needs-yaml
  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 uname
@@ -209,7 +215,7 @@ OUT
  gmp_libdir="$TMP/homebrew-gmp"
  mkdir -p "$gmp_libdir"

  stub brew false "--prefix gmp : echo '$gmp_libdir'"
  stub_repeated brew "--prefix gmp : echo '$gmp_libdir'"
  stub_make_install

  run_inline_definition <<DEF
@@ -233,7 +239,7 @@ OUT
  readline_libdir="$TMP/homebrew-readline"
  mkdir -p "$readline_libdir"

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

  run_inline_definition <<DEF
@@ -254,7 +260,7 @@ OUT
@test "readline is not linked from Homebrew when explicitly defined" {
  cached_tarball "ruby-2.0.0"

  stub brew false
  stub_repeated brew false
  stub_make_install

  export RUBY_CONFIGURE_OPTS='--with-readline-dir=/custom'
@@ -276,7 +282,7 @@ OUT
@test "number of CPU cores defaults to 2" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Darwin' false
  stub_repeated uname '-s : echo Darwin'
  stub sysctl false
  stub_make_install

@@ -299,7 +305,7 @@ OUT
@test "number of CPU cores is detected on Mac" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Darwin' false
  stub_repeated uname '-s : echo Darwin'
  stub sysctl '-n hw.ncpu : echo 4'
  stub_make_install

@@ -323,7 +329,7 @@ OUT
@test "number of CPU cores is detected on FreeBSD" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo FreeBSD' false
  stub_repeated uname '-s : echo FreeBSD'
  stub sysctl '-n hw.ncpu : echo 1'
  stub_make_install

@@ -347,7 +353,7 @@ OUT
@test "setting RUBY_MAKE_INSTALL_OPTS to a multi-word string" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Linux'
  stub_repeated uname '-s : echo Linux'
  stub_make_install

  export RUBY_MAKE_INSTALL_OPTS="DOGE=\"such wow\""
@@ -369,7 +375,7 @@ OUT
@test "setting MAKE_INSTALL_OPTS to a multi-word string" {
  cached_tarball "ruby-2.0.0"

  stub uname '-s : echo Linux'
  stub_repeated uname '-s : echo Linux'
  stub_make_install

  export MAKE_INSTALL_OPTS="DOGE=\"such wow\""
@@ -400,7 +406,7 @@ OUT
@test "make on FreeBSD defaults to gmake" {
  cached_tarball "ruby-2.0.0"

  stub uname "-s : echo FreeBSD" false
  stub_repeated uname "-s : echo FreeBSD"
  MAKE=gmake stub_make_install

  MAKE= install_fixture definitions/vanilla-ruby
@@ -419,7 +425,7 @@ apply -p1 -i /my/patch.diff
exec ./configure "\$@"
CONF

  stub uname '-s : echo Linux'
  stub_repeated uname '-s : echo Linux'
  stub apply 'echo apply "$@" >> build.log'
  stub_make_install

+20 −10
Original line number Diff line number Diff line
@@ -8,9 +8,9 @@ export -n CC
export -n RUBY_CONFIGURE_OPTS

@test "require_gcc on OS X 10.9" {
  stub uname '-s : echo Darwin'
  stub_repeated uname '-s : echo Darwin'
  stub sw_vers '-productVersion : echo 10.9.5'
  stub gcc '--version : echo 4.2.1' '--version : echo 4.2.1'
  stub_repeated gcc '--version : echo 4.2.1'

  run_inline_definition <<DEF
require_gcc
@@ -22,12 +22,16 @@ DEF
CC=${TMP}/bin/gcc
MACOSX_DEPLOYMENT_TARGET=no
OUT

  unstub uname
  unstub sw_vers
  unstub gcc
}

@test "require_gcc on OS X 10.10" {
  stub uname '-s : echo Darwin'
  stub_repeated uname '-s : echo Darwin'
  stub sw_vers '-productVersion : echo 10.10'
  stub gcc '--version : echo 4.2.1' '--version : echo 4.2.1'
  stub_repeated gcc '--version : echo 4.2.1'

  run_inline_definition <<DEF
require_gcc
@@ -39,6 +43,10 @@ DEF
CC=${TMP}/bin/gcc
MACOSX_DEPLOYMENT_TARGET=10.9
OUT

  unstub uname
  unstub sw_vers
  unstub gcc
}

@test "require_gcc silences warnings" {
@@ -55,13 +63,10 @@ DEF
  mkdir -p "$INSTALL_ROOT"
  cd "$INSTALL_ROOT"

  stub uname '-s : echo Darwin' '-s : echo Darwin'
  stub_repeated uname '-s : echo Darwin'
  stub sw_vers '-productVersion : echo 10.10'
  stub cc 'false'
  stub brew 'false'
  stub make \
    'echo make $@' \
    'echo make $@'
  stub_repeated brew 'false'
  stub_repeated make 'echo make $@'

  cat > ./configure <<CON
#!${BASH}
@@ -83,4 +88,9 @@ CFLAGS=no
make -j 2
make install
OUT

  unstub uname
  unstub sw_vers
  unstub brew
  unstub make
}
+2 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ OUT
}

@test "nonexistent version" {
  stub brew false
  stub_repeated brew false
  stub_ruby_build 'echo ERROR >&2 && exit 2' \
    "--definitions : echo 1.8.7 1.9.3-p0 1.9.3-p194 2.1.2 | tr ' ' $'\\n'"

@@ -97,6 +97,7 @@ If the version you need is missing, try upgrading ruby-build:
  git -C ${BATS_TEST_DIRNAME}/.. pull
OUT

  unstub brew
  unstub ruby-build
}

+6 −4
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -e

status=0
status=127
program="${0##*/}"
PROGRAM="$(echo "$program" | tr a-z- A-Z_)"
[ -n "$TMPDIR" ] || TMPDIR="/tmp"
@@ -9,6 +9,7 @@ PROGRAM="$(echo "$program" | tr a-z- A-Z_)"
_STUB_PLAN="${PROGRAM}_STUB_PLAN"
_STUB_RUN="${PROGRAM}_STUB_RUN"
_STUB_INDEX="${PROGRAM}_STUB_INDEX"
_STUB_NOINDEX="${PROGRAM}_STUB_NOINDEX"
_STUB_RESULT="${PROGRAM}_STUB_RESULT"
_STUB_END="${PROGRAM}_STUB_END"
_STUB_DEBUG="${PROGRAM}_STUB_DEBUG"
@@ -32,7 +33,7 @@ index=0
while IFS= read -r line; do
  index=$(($index + 1))

  if [ -z "${!_STUB_END}" ] && [ $index -eq "${!_STUB_INDEX}" ]; then
  if [[ -z "${!_STUB_END}" && -n "${!_STUB_NOINDEX}" || $index -eq "${!_STUB_INDEX}" ]]; then
    # We found the plan line we're interested in.
    # Start off by assuming success.
    result=0
@@ -72,7 +73,8 @@ while IFS= read -r line; do
      ( eval "$command" )
      status="$?"
      set -e
    else
      [ -z "${!_STUB_NOINDEX}" ] || break
    elif [ -z "${!_STUB_NOINDEX}" ]; then
      eval "${_STUB_RESULT}"=1
    fi
  fi
@@ -95,7 +97,7 @@ if [ -n "${!_STUB_END}" ]; then
else
  # If the requested index is larger than the number
  # of lines in the plan file, we failed.
  if [ "${!_STUB_INDEX}" -gt $index ]; then
  if [[ -z "${!_STUB_NOINDEX}" && "${!_STUB_INDEX}" -gt $index ]]; then
    eval "${_STUB_RESULT}"=1
  fi

Loading