Commit f4c2fe67 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Fix detecting of CPU cores on FreeBSD

On FreeBSD, use the same approach as OS X with `sysctl`.
parent bff583b2
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -115,13 +115,16 @@ file_is_not_empty() {
}

num_cpu_cores() {
  local num=""
  if [ "Darwin" = "$(uname -s)" ]; then
  local num
  case "$(uname -s)" in
  Darwin | *BSD )
    num="$(sysctl -n hw.ncpu 2>/dev/null || true)"
  elif [ -r /proc/cpuinfo ]; then
    num="$(grep ^processor /proc/cpuinfo | wc -l)"
    [ "$num" -gt 0 ] || num=""
  fi
    ;;
  * )
    num="$(grep ^processor /proc/cpuinfo 2>/dev/null | wc -l | xargs)"
    num="${num#0}"
    ;;
  esac
  echo "${num:-2}"
}

+24 −0
Original line number Diff line number Diff line
@@ -245,6 +245,30 @@ make install
OUT
}

@test "number of CPU cores is detected on FreeBSD" {
  cached_tarball "ruby-2.0.0"

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

  export -n MAKE_OPTS
  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
  unstub sysctl
  unstub make

  assert_build_log <<OUT
ruby-2.0.0: --prefix=$INSTALL_ROOT
make -j 1
make install
OUT
}

@test "setting RUBY_MAKE_INSTALL_OPTS to a multi-word string" {
  cached_tarball "ruby-2.0.0"