Commit 6c08c56d by Mislav Marohnić

Detect number of CPU cores used for `make`

Alt. implementation of #401, #434
parent 50bf60f9
...@@ -96,6 +96,17 @@ file_is_not_empty() { ...@@ -96,6 +96,17 @@ file_is_not_empty() {
fi fi
} }
num_cpu_cores() {
local num=""
if [ "Darwin" = "$(uname -s)" ]; then
num="$(sysctl -n hw.ncpu 2>/dev/null || true)"
elif [ -r /proc/cpuinfo ]; then
num="$(grep -c ^processor /proc/cpuinfo)"
[ "$num" -gt 0 ] || num=""
fi
echo "${num:-2}"
}
install_package() { install_package() {
install_package_using "tarball" 1 "$@" install_package_using "tarball" 1 "$@"
} }
...@@ -374,7 +385,7 @@ build_package_standard() { ...@@ -374,7 +385,7 @@ build_package_standard() {
if [ "${MAKEOPTS+defined}" ]; then if [ "${MAKEOPTS+defined}" ]; then
MAKE_OPTS="$MAKEOPTS" MAKE_OPTS="$MAKEOPTS"
elif [ -z "${MAKE_OPTS+defined}" ]; then elif [ -z "${MAKE_OPTS+defined}" ]; then
MAKE_OPTS="-j 2" MAKE_OPTS="-j $(num_cpu_cores)"
fi fi
# Support YAML_CONFIGURE_OPTS, RUBY_CONFIGURE_OPTS, etc. # Support YAML_CONFIGURE_OPTS, RUBY_CONFIGURE_OPTS, etc.
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
load test_helper load test_helper
export RUBY_BUILD_CACHE_PATH="$TMP/cache" export RUBY_BUILD_CACHE_PATH="$TMP/cache"
export MAKE=make export MAKE=make
export MAKE_OPTS="-j 2"
setup() { setup() {
mkdir -p "$INSTALL_ROOT" mkdir -p "$INSTALL_ROOT"
...@@ -91,6 +92,51 @@ make -j 2 ...@@ -91,6 +92,51 @@ make -j 2
OUT OUT
} }
@test "number of CPU cores defaults to 2" {
cached_tarball "ruby-2.0.0"
stub uname '-s : echo Darwin'
stub sysctl false
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 make
assert_build_log <<OUT
ruby-2.0.0: --prefix=$INSTALL_ROOT
make -j 2
OUT
}
@test "number of CPU cores is detected on Mac" {
cached_tarball "ruby-2.0.0"
stub uname '-s : echo Darwin'
stub sysctl '-n hw.ncpu : echo 4'
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 4
OUT
}
@test "custom relative install destination" { @test "custom relative install destination" {
export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT" export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment