From 0bb6c7f95645b618832dea16ef2d1ecdfb5ad0ed Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 13 Jun 2023 22:49:57 +0100 Subject: [PATCH 01/11] ruby-ng.eclass: optimize: use pattern for old ruby impls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not much improvement on a grand scale, but for dev-ruby/sinatra at least, we get: ``` $ pk pkg source $(pkg) --repo ~/g/ --bench 5s # before dev-ruby/sinatra-3.0.5::/home/sam/g/: mean: 76.25ms, min: 59.23ms, max: 83.674ms, σ = 4.247ms, N = 66 dev-ruby/sinatra-3.0.5-r1::/home/sam/g/: mean: 77.465ms, min: 61.782ms, max: 85.127ms, σ = 3.592ms, N = 65 dev-ruby/sinatra-3.0.6::/home/sam/g/: mean: 80.192ms, min: 60.922ms, max: 84.951ms, σ = 3.899ms, N = 63 dev-ruby/sinatra-2.2.3::/home/sam/g/: mean: 80.389ms, min: 56.818ms, max: 86.915ms, σ = 4.508ms, N = 63 $ pk pkg source $(pkg) --repo ~/g/ --bench 5s # after dev-ruby/sinatra-3.0.6::/home/sam/g/: mean: 72.761ms, min: 58.627ms, max: 76.161ms, σ = 3.276ms, N = 69 dev-ruby/sinatra-3.0.5-r1::/home/sam/g/: mean: 72.967ms, min: 60.127ms, max: 76.75ms, σ = 3.176ms, N = 69 dev-ruby/sinatra-3.0.5::/home/sam/g/: mean: 69.004ms, min: 58.344ms, max: 73.661ms, σ = 3.3ms, N = 73 dev-ruby/sinatra-2.2.3::/home/sam/g/: mean: 71.061ms, min: 55.144ms, max: 74.563ms, σ = 3.848ms, N = 71 ``` A tiny, but seemingly consistent improvement. Thanks to mgorny for the idea. Bug: https://bugs.gentoo.org/908465 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index 8befa086ef020..5a6edb1bf6080 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -107,7 +107,7 @@ _ruby_get_all_impls() { for i in ${USE_RUBY}; do case ${i} in # removed implementations - ruby19|ruby20|ruby21|ruby22|ruby23|ruby24|ruby25|ruby26|ruby27|jruby) + ruby19|ruby2[0-7]|jruby) ;; *) found_valid_impl=1 From 89925fc4e6d343ce6f7ca36bc288ba7b62d1193e Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 13 Jun 2023 22:52:12 +0100 Subject: [PATCH 02/11] ruby-ng.eclass: optimize: use pattern substitution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can save a little bit (consistently a few ms) by using patsubs in some obvious cases. Not really any difference globally, but for sinatra: ``` $ pk pkg source $(pkg) --repo ~/g/ --bench 5s # before dev-ruby/sinatra-3.0.5::/home/sam/g/: mean: 76.25ms, min: 59.23ms, max: 83.674ms, σ = 4.247ms, N = 66 dev-ruby/sinatra-3.0.5-r1::/home/sam/g/: mean: 77.465ms, min: 61.782ms, max: 85.127ms, σ = 3.592ms, N = 65 dev-ruby/sinatra-3.0.6::/home/sam/g/: mean: 80.192ms, min: 60.922ms, max: 84.951ms, σ = 3.899ms, N = 63 dev-ruby/sinatra-2.2.3::/home/sam/g/: mean: 80.389ms, min: 56.818ms, max: 86.915ms, σ = 4.508ms, N = 63 $ pk pkg source $(pkg) --repo ~/g/ --bench 5s # after dev-ruby/sinatra-2.2.3::/home/sam/g/: mean: 66.68ms, min: 56.938ms, max: 74.248ms, σ = 4.832ms, N = 75 dev-ruby/sinatra-3.0.6::/home/sam/g/: mean: 73.618ms, min: 60.153ms, max: 77.978ms, σ = 3.195ms, N = 68 dev-ruby/sinatra-3.0.5::/home/sam/g/: mean: 72.069ms, min: 58.736ms, max: 78.223ms, σ = 3.277ms, N = 70 dev-ruby/sinatra-3.0.5-r1::/home/sam/g/: mean: 73.265ms, min: 60.738ms, max: 81.06ms, σ = 3.227ms, N = 69 ``` Bug: https://bugs.gentoo.org/908465 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index 5a6edb1bf6080..2bf1885d38031 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -183,11 +183,11 @@ _ruby_wrap_conditions() { local conditions="$1" local atoms="$2" - for condition in $conditions; do + for condition in ${conditions}; do atoms="${condition}? ( ${atoms} )" done - echo "$atoms" + echo "${atoms}" } # @FUNCTION: ruby_add_rdepend @@ -322,11 +322,9 @@ ruby_get_use_implementations() { ruby_get_use_targets() { debug-print-function ${FUNCNAME} "${@}" - local t implementation - for implementation in $(_ruby_get_all_impls); do - t+=" ruby_targets_${implementation}" - done - echo $t + + local impls="$(_ruby_get_all_impls)" + echo "${impls//ruby/ruby_targets_ruby}" } # @FUNCTION: ruby_implementations_depend From 390ad2effe1c83a7cb25a892ad988937b53c07fe Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 13 Jun 2023 22:57:53 +0100 Subject: [PATCH 03/11] ruby-ng.eclass: optimize: avoid subshell for ruby_get_all_impls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We go from ~4s -> ~3.5s for sourcing dev-ruby/*. For sinatra: ``` $ pk pkg source $(pkg) --repo ~/g/ --bench 5s # before dev-ruby/sinatra-2.2.3::/home/sam/g/: mean: 66.68ms, min: 56.938ms, max: 74.248ms, σ = 4.832ms, N = 75 dev-ruby/sinatra-3.0.6::/home/sam/g/: mean: 73.618ms, min: 60.153ms, max: 77.978ms, σ = 3.195ms, N = 68 dev-ruby/sinatra-3.0.5::/home/sam/g/: mean: 72.069ms, min: 58.736ms, max: 78.223ms, σ = 3.277ms, N = 70 dev-ruby/sinatra-3.0.5-r1::/home/sam/g/: mean: 73.265ms, min: 60.738ms, max: 81.06ms, σ = 3.227ms, N = 69 $ pk pkg source $(pkg) --repo ~/g/ --bench 5s # after dev-ruby/sinatra-3.0.5-r1::/home/sam/g/: mean: 59.677ms, min: 49.141ms, max: 63.282ms, σ = 2.511ms, N = 84 dev-ruby/sinatra-3.0.6::/home/sam/g/: mean: 59.693ms, min: 48.637ms, max: 62.862ms, σ = 2.628ms, N = 84 dev-ruby/sinatra-3.0.5::/home/sam/g/: mean: 56.697ms, min: 46.782ms, max: 60.367ms, σ = 2.822ms, N = 89 dev-ruby/sinatra-2.2.3::/home/sam/g/: mean: 54.915ms, min: 45.832ms, max: 59.513ms, σ = 3.52ms, N = 92 ``` Bug: https://bugs.gentoo.org/908465 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index 2bf1885d38031..ee2e6b89edb41 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -102,6 +102,7 @@ ruby_implementation_depend() { # @DESCRIPTION: # Return a list of valid implementations in USE_RUBY, skipping the old # implementations that are no longer supported. +_RUBY_GET_ALL_IMPLS=() _ruby_get_all_impls() { local i found_valid_impl for i in ${USE_RUBY}; do @@ -111,7 +112,8 @@ _ruby_get_all_impls() { ;; *) found_valid_impl=1 - echo ${i};; + _RUBY_GET_ALL_IMPLS+=( ${i} ) + ;; esac done @@ -131,7 +133,7 @@ ruby_samelib() { debug-print-function ${FUNCNAME} "${@}" local res= - for _ruby_implementation in $(_ruby_get_all_impls); do + for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do has -${_ruby_implementation} $@ || \ res="${res}ruby_targets_${_ruby_implementation}(-)?," done @@ -174,7 +176,7 @@ ruby_implementation_command() { _ruby_atoms_samelib() { local atoms=$(_ruby_atoms_samelib_generic "$*") - for _ruby_implementation in $(_ruby_get_all_impls); do + for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" done } @@ -310,7 +312,7 @@ ruby_get_use_implementations() { debug-print-function ${FUNCNAME} "${@}" local i implementation - for implementation in $(_ruby_get_all_impls); do + for implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do use ruby_targets_${implementation} && i+=" ${implementation}" done echo $i @@ -322,8 +324,8 @@ ruby_get_use_implementations() { ruby_get_use_targets() { debug-print-function ${FUNCNAME} "${@}" - - local impls="$(_ruby_get_all_impls)" + _ruby_get_all_impls + local impls="${_RUBY_GET_ALL_IMPLS[@]}" echo "${impls//ruby/ruby_targets_ruby}" } @@ -346,13 +348,14 @@ ruby_get_use_targets() { ruby_implementations_depend() { debug-print-function ${FUNCNAME} "${@}" - local depend - for _ruby_implementation in $(_ruby_get_all_impls); do + for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )" done echo "${depend}" } +_ruby_get_all_impls + IUSE+=" $(ruby_get_use_targets)" # If you specify RUBY_OPTIONAL you also need to take care of # ruby useflag and dependency. @@ -412,7 +415,7 @@ _ruby_invoke_environment() { _ruby_each_implementation() { local invoked=no - for _ruby_implementation in $(_ruby_get_all_impls); do + for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do # only proceed if it's requested use ruby_targets_${_ruby_implementation} || continue @@ -435,7 +438,7 @@ _ruby_each_implementation() { if [[ ${invoked} == "no" ]]; then eerror "You need to select at least one compatible Ruby installation target via RUBY_TARGETS in make.conf." - eerror "Compatible targets for this package are: $(_ruby_get_all_impls)" + eerror "Compatible targets for this package are: ${_RUBY_GET_ALL_IMPLS[@]}" eerror eerror "See https://www.gentoo.org/proj/en/prog_lang/ruby/index.xml#doc_chap3 for more information." eerror From 676e6dc3f4a921d4fcb1e320e7d0562e2ef08856 Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 13 Jun 2023 22:59:47 +0100 Subject: [PATCH 04/11] ruby-ng.eclass: optimize: avoid subshells for _ruby_atoms_samelib* - Inline ruby_atoms_samelib (only used by one caller) - Avoid repeated (subshell) calls to _ruby_atoms_samelib_generic by using a result variable instead. We go from 3.5s -> 2.5s to source dev-ruby/*. Thanks to mgorny for the ideas here. Bug: https://bugs.gentoo.org/908465 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 57 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index ee2e6b89edb41..cf66fcec2f05d 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -141,23 +141,6 @@ ruby_samelib() { echo "[${res%,}]" } -_ruby_atoms_samelib_generic() { - eshopts_push -o noglob - echo "RUBYTARGET? (" - for token in $*; do - case "$token" in - "||" | "(" | ")" | *"?") - echo "${token}" ;; - *]) - echo "${token%[*}[RUBYTARGET(-),${token/*[}" ;; - *) - echo "${token}[RUBYTARGET(-)]" ;; - esac - done - echo ")" - eshopts_pop -} - # @FUNCTION: ruby_implementation_command # @RETURN: the path to the given ruby implementation # @DESCRIPTION: @@ -173,11 +156,29 @@ ruby_implementation_command() { echo $(type -p ${_ruby_name} 2>/dev/null) } +_RUBY_ATOMS_SAMELIB_RESULT="" _ruby_atoms_samelib() { - local atoms=$(_ruby_atoms_samelib_generic "$*") + _RUBY_ATOMS_SAMELIB_RESULT="" + eshopts_push -o noglob + local token + local atoms=" RUBYTARGET? (" + for token in $*; do + case "${token}" in + "||" | "(" | ")" | *"?") + atoms+=" ${token}" ;; + *]) + atoms+=" ${token%[*}[RUBYTARGET(-),${token/*[}" ;; + *) + atoms+=" ${token}[RUBYTARGET(-)]" ;; + esac + done + atoms+=" ) " + eshopts_pop + + local _ruby_implementation for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do - echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" + _RUBY_ATOMS_SAMELIB_RESULT+="${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" done } @@ -226,15 +227,15 @@ ruby_add_rdepend() { ;; esac - local dependency=$(_ruby_atoms_samelib "$1") + _ruby_atoms_samelib "$1" - RDEPEND="${RDEPEND} $dependency" + RDEPEND="${RDEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" # Add the dependency as a test-dependency since we're going to # execute the code during test phase. case ${EAPI} in - 6) DEPEND="${DEPEND} test? ( ${dependency} )" ;; - *) BDEPEND="${BDEPEND} test? ( ${dependency} )" ;; + 6) DEPEND="${DEPEND} test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;; + *) BDEPEND="${BDEPEND} test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;; esac if ! has test "$IUSE"; then IUSE+=" test" @@ -273,11 +274,11 @@ ruby_add_bdepend() { ;; esac - local dependency=$(_ruby_atoms_samelib "$1") + _ruby_atoms_samelib "$1" case ${EAPI} in - 6) DEPEND="${DEPEND} $dependency" ;; - *) BDEPEND="${BDEPEND} $dependency" ;; + 6) DEPEND="${DEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; + *) BDEPEND="${BDEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; esac RDEPEND="${RDEPEND}" } @@ -300,9 +301,9 @@ ruby_add_depend() { *) die "bad number of arguments to $0" ;; esac - local dependency=$(_ruby_atoms_samelib "$1") + _ruby_atoms_samelib "$1" - DEPEND="${DEPEND} $dependency" + DEPEND="${DEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" } # @FUNCTION: ruby_get_use_implementations From 48a0a44098b5cdfbceaf37305b7e9eac65748cd0 Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 13 Jun 2023 23:01:11 +0100 Subject: [PATCH 05/11] ruby-ng.eclass: optimize: avoid subshells for ruby_implementations_depend, ruby_get_use_targets We go from 2.5s -> 1.9s to source dev-ruby/*. Bug: https://bugs.gentoo.org/908465 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index cf66fcec2f05d..6c5666ddeabb0 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -325,9 +325,20 @@ ruby_get_use_implementations() { ruby_get_use_targets() { debug-print-function ${FUNCNAME} "${@}" - _ruby_get_all_impls + _ruby_get_use_targets + echo "${_RUBY_GET_USE_TARGETS}" +} + +# @FUNCTION: _ruby_get_use_targets +# @INTERNAL +# @DESCRIPTION: +# Gets an array of ruby use targets that the ebuild sets +_RUBY_GET_USE_TARGETS="" +_ruby_get_use_targets() { + debug-print-function ${FUNCNAME} "${@}" + local impls="${_RUBY_GET_ALL_IMPLS[@]}" - echo "${impls//ruby/ruby_targets_ruby}" + _RUBY_GET_USE_TARGETS="${impls//ruby/ruby_targets_ruby}" } # @FUNCTION: ruby_implementations_depend @@ -346,27 +357,36 @@ ruby_get_use_targets() { # ... # DEPEND="ruby? ( $(ruby_implementations_depend) )" # RDEPEND="${DEPEND}" +_RUBY_IMPLEMENTATIONS_DEPEND="" ruby_implementations_depend() { debug-print-function ${FUNCNAME} "${@}" + _ruby_implementations_depend + echo "${_RUBY_IMPLEMENTATIONS_DEPEND}" +} + +_ruby_implementations_depend() { + local depend _ruby_implementation for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )" done - echo "${depend}" + _RUBY_IMPLEMENTATIONS_DEPEND="${depend}" } _ruby_get_all_impls +_ruby_get_use_targets +_ruby_implementations_depend -IUSE+=" $(ruby_get_use_targets)" +IUSE+=" ${_RUBY_GET_USE_TARGETS}" # If you specify RUBY_OPTIONAL you also need to take care of # ruby useflag and dependency. if [[ ${RUBY_OPTIONAL} != yes ]]; then - DEPEND="${DEPEND} $(ruby_implementations_depend)" - RDEPEND="${RDEPEND} $(ruby_implementations_depend)" - REQUIRED_USE+=" || ( $(ruby_get_use_targets) )" + DEPEND="${DEPEND} ${_RUBY_IMPLEMENTATIONS_DEPEND}" + RDEPEND="${RDEPEND} ${_RUBY_IMPLEMENTATIONS_DEPEND}" + REQUIRED_USE+=" || ( ${_RUBY_GET_USE_TARGETS} )" case ${EAPI} in 6) ;; - *) BDEPEND="${BDEPEND} $(ruby_implementations_depend)" ;; + *) BDEPEND="${BDEPEND} ${_RUBY_IMPLEMENTATIONS_DEPEND}" ;; esac fi From acf925859631ce5a5867d27244665c623fa1ad99 Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 13 Jun 2023 23:15:10 +0100 Subject: [PATCH 06/11] ruby-ng.eclass: use bash += Easier to read. Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index 6c5666ddeabb0..b20c3b4629155 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -229,13 +229,13 @@ ruby_add_rdepend() { _ruby_atoms_samelib "$1" - RDEPEND="${RDEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" + RDEPEND+=" ${_RUBY_ATOMS_SAMELIB_RESULT}" # Add the dependency as a test-dependency since we're going to # execute the code during test phase. case ${EAPI} in - 6) DEPEND="${DEPEND} test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;; - *) BDEPEND="${BDEPEND} test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;; + 6) DEPEND+=" test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;; + *) BDEPEND+=" test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;; esac if ! has test "$IUSE"; then IUSE+=" test" @@ -277,8 +277,8 @@ ruby_add_bdepend() { _ruby_atoms_samelib "$1" case ${EAPI} in - 6) DEPEND="${DEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; - *) BDEPEND="${BDEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; + 6) DEPEND+=" ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; + *) BDEPEND+=" ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; esac RDEPEND="${RDEPEND}" } @@ -303,7 +303,7 @@ ruby_add_depend() { _ruby_atoms_samelib "$1" - DEPEND="${DEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" + DEPEND+=" ${_RUBY_ATOMS_SAMELIB_RESULT}" } # @FUNCTION: ruby_get_use_implementations @@ -381,12 +381,12 @@ IUSE+=" ${_RUBY_GET_USE_TARGETS}" # If you specify RUBY_OPTIONAL you also need to take care of # ruby useflag and dependency. if [[ ${RUBY_OPTIONAL} != yes ]]; then - DEPEND="${DEPEND} ${_RUBY_IMPLEMENTATIONS_DEPEND}" - RDEPEND="${RDEPEND} ${_RUBY_IMPLEMENTATIONS_DEPEND}" + DEPEND+=" ${_RUBY_IMPLEMENTATIONS_DEPEND}" + RDEPEND+=" ${_RUBY_IMPLEMENTATIONS_DEPEND}" REQUIRED_USE+=" || ( ${_RUBY_GET_USE_TARGETS} )" case ${EAPI} in 6) ;; - *) BDEPEND="${BDEPEND} ${_RUBY_IMPLEMENTATIONS_DEPEND}" ;; + *) BDEPEND+=" ${_RUBY_IMPLEMENTATIONS_DEPEND}" ;; esac fi From 778555f772abf82743b1ee48ffc90df2eb96de66 Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 13 Jun 2023 23:15:40 +0100 Subject: [PATCH 07/11] ruby-ng.eclass: use bash tests Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index b20c3b4629155..f10c987ac44a7 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -392,7 +392,7 @@ fi _ruby_invoke_environment() { old_S=${S} - if [ -z "${RUBY_S}" ]; then + if [[ -z ${RUBY_S} ]]; then sub_S=${P} else sub_S=${RUBY_S} @@ -728,7 +728,7 @@ ruby-ng_rspec() { # Explicitly pass the expected spec directory since the versioned # rspec wrappers don't handle this automatically. - if [ ${#@} -eq 0 ]; then + if [[ $# -eq 0 ]]; then files="spec" fi From f740ce9defe9cebbbebb9958f740219da15afa54 Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 13 Jun 2023 23:17:13 +0100 Subject: [PATCH 08/11] ruby-ng.eclass: drop no-op RDEPEND assignment Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 1 - 1 file changed, 1 deletion(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index f10c987ac44a7..3269ed52cafe0 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -280,7 +280,6 @@ ruby_add_bdepend() { 6) DEPEND+=" ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; *) BDEPEND+=" ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; esac - RDEPEND="${RDEPEND}" } # @FUNCTION: ruby_add_depend From 52885a31b20f6af327ccefaa62ce74877b9b687d Mon Sep 17 00:00:00 2001 From: Sam James Date: Wed, 14 Jun 2023 01:11:43 +0100 Subject: [PATCH 09/11] ruby-ng.eclass: cater to USE_RUBY conditional calls Packages may try to restrict their test dependencies to ease bootstrapping/porting if they're not yet available for a newer Ruby implementation by setting USE_RUBY="" ruby_add_bdepend ... For example, dev-ruby/parallel does: ``` # Rails isn't yet ruby32-ready in Gentoo USE_RUBY="ruby27 ruby30 ruby31" ruby_add_bdepend " test? ( dev-ruby/activerecord[sqlite] ) ``` This isn't ideal, but we don't have a ruby_gen_cond_dep right now, so cater to this usecase by invalidating the caches we've previously added if we've detected USE_RUBY changed. Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index 3269ed52cafe0..14f4414337d6f 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -102,8 +102,9 @@ ruby_implementation_depend() { # @DESCRIPTION: # Return a list of valid implementations in USE_RUBY, skipping the old # implementations that are no longer supported. -_RUBY_GET_ALL_IMPLS=() _ruby_get_all_impls() { + _RUBY_GET_ALL_IMPLS=() + local i found_valid_impl for i in ${USE_RUBY}; do case ${i} in @@ -132,6 +133,8 @@ _ruby_get_all_impls() { ruby_samelib() { debug-print-function ${FUNCNAME} "${@}" + _ruby_set_globals_invalidate_if_stale + local res= for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do has -${_ruby_implementation} $@ || \ @@ -176,6 +179,7 @@ _ruby_atoms_samelib() { atoms+=" ) " eshopts_pop + _ruby_set_globals_invalidate_if_stale local _ruby_implementation for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do _RUBY_ATOMS_SAMELIB_RESULT+="${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" @@ -227,6 +231,7 @@ ruby_add_rdepend() { ;; esac + _ruby_set_globals_invalidate_if_stale _ruby_atoms_samelib "$1" RDEPEND+=" ${_RUBY_ATOMS_SAMELIB_RESULT}" @@ -274,6 +279,7 @@ ruby_add_bdepend() { ;; esac + _ruby_set_globals_invalidate_if_stale _ruby_atoms_samelib "$1" case ${EAPI} in @@ -300,6 +306,7 @@ ruby_add_depend() { *) die "bad number of arguments to $0" ;; esac + _ruby_set_globals_invalidate_if_stale _ruby_atoms_samelib "$1" DEPEND+=" ${_RUBY_ATOMS_SAMELIB_RESULT}" @@ -311,6 +318,8 @@ ruby_add_depend() { ruby_get_use_implementations() { debug-print-function ${FUNCNAME} "${@}" + _ruby_set_globals_invalidate_if_stale + local i implementation for implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do use ruby_targets_${implementation} && i+=" ${implementation}" @@ -324,6 +333,7 @@ ruby_get_use_implementations() { ruby_get_use_targets() { debug-print-function ${FUNCNAME} "${@}" + _ruby_set_globals_invalidate_if_stale _ruby_get_use_targets echo "${_RUBY_GET_USE_TARGETS}" } @@ -336,6 +346,8 @@ _RUBY_GET_USE_TARGETS="" _ruby_get_use_targets() { debug-print-function ${FUNCNAME} "${@}" + _ruby_set_globals_invalidate_if_stale + local impls="${_RUBY_GET_ALL_IMPLS[@]}" _RUBY_GET_USE_TARGETS="${impls//ruby/ruby_targets_ruby}" } @@ -360,11 +372,14 @@ _RUBY_IMPLEMENTATIONS_DEPEND="" ruby_implementations_depend() { debug-print-function ${FUNCNAME} "${@}" + _ruby_set_globals_invalidate_if_stale _ruby_implementations_depend echo "${_RUBY_IMPLEMENTATIONS_DEPEND}" } _ruby_implementations_depend() { + _ruby_set_globals_invalidate_if_stale + local depend _ruby_implementation for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )" @@ -372,9 +387,24 @@ _ruby_implementations_depend() { _RUBY_IMPLEMENTATIONS_DEPEND="${depend}" } -_ruby_get_all_impls -_ruby_get_use_targets -_ruby_implementations_depend +_ruby_set_globals() { + _RUBY_SET_GLOBALS_USE_RUBY="${USE_RUBY}" + _ruby_get_all_impls + _ruby_get_use_targets + _ruby_implementations_depend +} + +_ruby_set_globals_invalidate_if_stale() { + # Packages may try to restrict their test dependencies to ease bootstrapping/porting + # if they're not yet available for a newer Ruby implementation by setting + # USE_RUBY="" ruby_add_bdepend ... + if [[ ${_RUBY_SET_GLOBALS_USE_RUBY} != ${USE_RUBY} && -z ${_RUBY_SET_GLOBALS_INVALIDATING} ]] ; then + local _RUBY_SET_GLOBALS_INVALIDATING=1 + _ruby_set_globals + fi +} + +_ruby_set_globals IUSE+=" ${_RUBY_GET_USE_TARGETS}" # If you specify RUBY_OPTIONAL you also need to take care of @@ -434,6 +464,8 @@ _ruby_invoke_environment() { } _ruby_each_implementation() { + _ruby_set_globals_invalidate_if_stale + local invoked=no for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do # only proceed if it's requested From 8478835a7fc4226bcbf6c79475e1ba6d41d42298 Mon Sep 17 00:00:00 2001 From: Sam James Date: Wed, 14 Jun 2023 21:47:35 +0100 Subject: [PATCH 10/11] ruby-ng.eclass: use shopt directly, not via estack.eclass ulm points out that estack.eclass is particularly inefficient (although it'll get slightly better once https://github.com/gentoo/gentoo/pull/31437 is fixed). Let's just manually roll it like llvm.eclass does. Bug: https://bugs.gentoo.org/908465 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index 14f4414337d6f..2f14c22ace373 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -75,7 +75,7 @@ if [[ -z ${_RUBY_NG_ECLASS} ]]; then _RUBY_NG_ECLASS=1 [[ ${EAPI} == 6 ]] && inherit eqawarn toolchain-funcs -inherit estack multilib ruby-utils +inherit multilib ruby-utils # S is no longer automatically assigned when it doesn't exist. S="${WORKDIR}" @@ -163,7 +163,8 @@ _RUBY_ATOMS_SAMELIB_RESULT="" _ruby_atoms_samelib() { _RUBY_ATOMS_SAMELIB_RESULT="" - eshopts_push -o noglob + local shopt_save=$(shopt -p -o noglob) + set -f local token local atoms=" RUBYTARGET? (" for token in $*; do @@ -177,7 +178,7 @@ _ruby_atoms_samelib() { esac done atoms+=" ) " - eshopts_pop + ${shopt_save} _ruby_set_globals_invalidate_if_stale local _ruby_implementation From 5f7ad4a0e3ddd944c094ebc9719fdd5982ea76f6 Mon Sep 17 00:00:00 2001 From: Sam James Date: Wed, 14 Jun 2023 22:38:12 +0100 Subject: [PATCH 11/11] ruby-ng.eclass: add _ruby_get_use_targets comment I don't see us adding a non-ruby* target any time soon so this should be fine. Closes: https://github.com/gentoo/gentoo/pull/31428 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index 2f14c22ace373..5cea44101593c 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -105,6 +105,8 @@ ruby_implementation_depend() { _ruby_get_all_impls() { _RUBY_GET_ALL_IMPLS=() + # XXX: Please update _ruby_get_use_targets if adding a non-'ruby*' + # target. local i found_valid_impl for i in ${USE_RUBY}; do case ${i} in @@ -350,6 +352,7 @@ _ruby_get_use_targets() { _ruby_set_globals_invalidate_if_stale local impls="${_RUBY_GET_ALL_IMPLS[@]}" + # XXX: This assumes all targets begin with 'ruby'. _RUBY_GET_USE_TARGETS="${impls//ruby/ruby_targets_ruby}" }