From 8fcdcec5fbdd0e3a77391e4f354218014f59f358 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Fri, 5 Jan 2018 20:45:13 +0000 Subject: gentoo resync : 05.01.2018 --- eclass/Manifest.gz | Bin 41369 -> 41202 bytes eclass/cdrom.eclass | 12 ++- eclass/l10n.eclass | 42 ++++---- eclass/multiprocessing.eclass | 230 ++-------------------------------------- eclass/tests/multiprocessing.sh | 42 -------- 5 files changed, 41 insertions(+), 285 deletions(-) delete mode 100755 eclass/tests/multiprocessing.sh (limited to 'eclass') diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz index 160dae7a3fc4..4b20b08a5c7f 100644 Binary files a/eclass/Manifest.gz and b/eclass/Manifest.gz differ diff --git a/eclass/cdrom.eclass b/eclass/cdrom.eclass index 47e2c6342e06..7b0eb9c6c3b5 100644 --- a/eclass/cdrom.eclass +++ b/eclass/cdrom.eclass @@ -71,7 +71,12 @@ fi # eclass, see that function's description. cdrom_get_cds() { unset CDROM_SET - export CDROM_CURRENT_CD=0 CDROM_CHECKS=( "${@}" ) + export CDROM_CURRENT_CD=0 + export CDROM_NUM_CDS="${#}" + local i + for i in $(seq ${#}); do + export CDROM_CHECK_${i}="${!i}" + done # If the user has set CD_ROOT or CD_ROOT_1, don't bother informing # them about which discs are needed as they presumably already know. @@ -190,7 +195,8 @@ cdrom_load_next_cd() { local i cdset : CD_ROOT_${CDROM_CURRENT_CD} export CDROM_ROOT=${CD_ROOT:-${!_}} - IFS=: read -r -a cdset -d "" <<< "${CDROM_CHECKS[$((${CDROM_CURRENT_CD} - 1))]}" + local var="CDROM_CHECK_${CDROM_CURRENT_CD}" + IFS=: read -r -a cdset -d "" <<< "${!var}" for i in $(seq ${CDROM_SET:-0} ${CDROM_SET:-$((${#cdset[@]} - 1))}); do local f=${cdset[${i}]} point= node= fs= opts= @@ -222,7 +228,7 @@ cdrom_load_next_cd() { fi if [[ ${showedmsg} -eq 0 ]] ; then - if [[ ${#CDROM_CHECKS[@]} -eq 1 ]] ; then + if [[ ${CDROM_NUM_CDS} -eq 1 ]] ; then einfo "Please insert+mount the ${CDROM_NAME:-CD for ${PN}} now !" else local var="CDROM_NAME_${CDROM_CURRENT_CD}" diff --git a/eclass/l10n.eclass b/eclass/l10n.eclass index 2283088d0d0a..4b0111934d72 100644 --- a/eclass/l10n.eclass +++ b/eclass/l10n.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2016 Gentoo Foundation +# Copyright 1999-2017 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # @ECLASS: l10n.eclass @@ -12,8 +12,7 @@ # conveniently handle localizations (translations) offered by packages. # These are meant to prevent code duplication for such boring tasks as # determining the cross-section between the user's set LINGUAS and what -# is offered by the package; and generating the right list of linguas_* -# USE flags. +# is offered by the package. # @ECLASS-VARIABLE: PLOCALES # @DEFAULT_UNSET @@ -33,11 +32,6 @@ # # Example: PLOCALE_BACKUP="en_US" -# Add linguas useflags -for u in ${PLOCALES}; do - IUSE+=" linguas_${u}" -done - # @FUNCTION: l10n_for_each_locale_do # @USAGE: # @DESCRIPTION: @@ -103,23 +97,31 @@ l10n_find_plocales_changes() { # @FUNCTION: l10n_get_locales # @USAGE: [disabled] # @DESCRIPTION: -# Determine which LINGUAS USE flags the user has enabled that are offered -# by the package, as listed in PLOCALES, and return them. In case no locales -# are selected, fall back on PLOCALE_BACKUP. When the disabled argument is -# given, return the disabled useflags instead of the enabled ones. +# Determine which LINGUAS the user has enabled that are offered by the +# package, as listed in PLOCALES, and return them. In case no locales +# are selected, fall back on PLOCALE_BACKUP. When the disabled argument +# is given, return the disabled locales instead of the enabled ones. l10n_get_locales() { local disabled_locales enabled_locales loc locs - for loc in ${PLOCALES}; do - if use linguas_${loc}; then - enabled_locales+="${loc} " - else - disabled_locales+="${loc} " - fi - done + if [[ -z ${LINGUAS+set} ]]; then + # enable all if unset + enabled_locales=${PLOCALES} + elif [[ -z ${LINGUAS} ]]; then + # disable all if empty + disabled_locales=${PLOCALES} + else + for loc in ${PLOCALES}; do + if has ${loc} ${LINGUAS}; then + enabled_locales+="${loc} " + else + disabled_locales+="${loc} " + fi + done + fi if [[ ${1} == disabled ]]; then locs=${disabled_locales} else - locs=${enabled_locales:-$PLOCALE_BACKUP} + locs=${enabled_locales:-${PLOCALE_BACKUP}} fi printf "%s" "${locs}" } diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass index b6e92976f73e..3e8b2f9d2540 100644 --- a/eclass/multiprocessing.eclass +++ b/eclass/multiprocessing.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2014 Gentoo Foundation +# Copyright 1999-2017 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # @ECLASS: multiprocessing.eclass @@ -7,51 +7,25 @@ # @AUTHOR: # Brian Harring # Mike Frysinger -# @BLURB: parallelization with bash (wtf?) +# @BLURB: multiprocessing helper functions # @DESCRIPTION: -# The multiprocessing eclass contains a suite of functions that allow ebuilds -# to quickly run things in parallel using shell code. +# The multiprocessing eclass contains a suite of utility functions +# that could be helpful to controlling parallel multiple job execution. +# The most common use is processing MAKEOPTS in order to obtain job +# count. # -# It has two modes: pre-fork and post-fork. If you don't want to dive into any -# more nuts & bolts, just use the pre-fork mode. For main threads that mostly -# spawn children and then wait for them to finish, use the pre-fork mode. For -# main threads that do a bit of processing themselves, use the post-fork mode. -# You may mix & match them for longer computation loops. # @EXAMPLE: # # @CODE -# # First initialize things: -# multijob_init -# -# # Then hash a bunch of files in parallel: -# for n in {0..20} ; do -# multijob_child_init md5sum data.${n} > data.${n} -# done -# -# # Then wait for all the children to finish: -# multijob_finish +# src_compile() { +# # custom build system that does not support most of MAKEOPTS +# ./mybs -j$(makeopts_jobs) +# } # @CODE if [[ -z ${_MULTIPROCESSING_ECLASS} ]]; then _MULTIPROCESSING_ECLASS=1 -# @FUNCTION: bashpid -# @DESCRIPTION: -# Return the process id of the current sub shell. This is to support bash -# versions older than 4.0 that lack $BASHPID support natively. Simply do: -# echo ${BASHPID:-$(bashpid)} -# -# Note: Using this func in any other way than the one above is not supported. -bashpid() { - # Running bashpid plainly will return incorrect results. This func must - # be run in a subshell of the current subshell to get the right pid. - # i.e. This will show the wrong value: - # bashpid - # But this will show the right value: - # (bashpid) - sh -c 'echo ${PPID}' -} - # @FUNCTION: get_nproc # @USAGE: [${fallback:-1}] # @DESCRIPTION: @@ -126,188 +100,4 @@ makeopts_loadavg() { echo ${lavg:-${2:-999}} } -# @FUNCTION: multijob_init -# @USAGE: [${MAKEOPTS}] -# @DESCRIPTION: -# Setup the environment for executing code in parallel. -# You must call this before any other multijob function. -multijob_init() { - # When something goes wrong, try to wait for all the children so we - # don't leave any zombies around. - has wait ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" wait " - - # Setup a pipe for children to write their pids to when they finish. - # We have to allocate two fd's because POSIX has undefined behavior - # when using one single fd for both read and write. #487056 - # However, opening an fd for read or write only will block until the - # opposite end is opened as well. Thus we open the first fd for both - # read and write to not block ourselve, but use it for reading only. - # The second fd really is opened for write only, as Cygwin supports - # just one single read fd per FIFO. #583962 - local pipe="${T}/multijob.pipe" - mkfifo -m 600 "${pipe}" - redirect_alloc_fd mj_read_fd "${pipe}" - redirect_alloc_fd mj_write_fd "${pipe}" '>' - rm -f "${pipe}" - - # See how many children we can fork based on the user's settings. - mj_max_jobs=$(makeopts_jobs "$@") - mj_num_jobs=0 -} - -# @FUNCTION: multijob_child_init -# @USAGE: [--pre|--post] [command to run in background] -# @DESCRIPTION: -# This function has two forms. You can use it to execute a simple command -# in the background (and it takes care of everything else), or you must -# call this first thing in your forked child process. -# -# The --pre/--post options allow you to select the child generation mode. -# -# @CODE -# # 1st form: pass the command line as arguments: -# multijob_child_init ls /dev -# # Or if you want to use pre/post fork modes: -# multijob_child_init --pre ls /dev -# multijob_child_init --post ls /dev -# -# # 2nd form: execute multiple stuff in the background (post fork): -# ( -# multijob_child_init -# out=`ls` -# if echo "${out}" | grep foo ; then -# echo "YEAH" -# fi -# ) & -# multijob_post_fork -# -# # 2nd form: execute multiple stuff in the background (pre fork): -# multijob_pre_fork -# ( -# multijob_child_init -# out=`ls` -# if echo "${out}" | grep foo ; then -# echo "YEAH" -# fi -# ) & -# @CODE -multijob_child_init() { - local mode="pre" - case $1 in - --pre) mode="pre" ; shift ;; - --post) mode="post"; shift ;; - esac - - if [[ $# -eq 0 ]] ; then - trap 'echo ${BASHPID:-$(bashpid)} $? >&'${mj_write_fd} EXIT - trap 'exit 1' INT TERM - else - local ret - [[ ${mode} == "pre" ]] && { multijob_pre_fork; ret=$?; } - ( multijob_child_init ; "$@" ) & - [[ ${mode} == "post" ]] && { multijob_post_fork; ret=$?; } - return ${ret} - fi -} - -# @FUNCTION: _multijob_fork -# @INTERNAL -# @DESCRIPTION: -# Do the actual book keeping. -_multijob_fork() { - [[ $# -eq 1 ]] || die "incorrect number of arguments" - - local ret=0 - [[ $1 == "post" ]] && : $(( ++mj_num_jobs )) - if [[ ${mj_num_jobs} -ge ${mj_max_jobs} ]] ; then - multijob_finish_one - ret=$? - fi - [[ $1 == "pre" ]] && : $(( ++mj_num_jobs )) - return ${ret} -} - -# @FUNCTION: multijob_pre_fork -# @DESCRIPTION: -# You must call this in the parent process before forking a child process. -# If the parallel limit has been hit, it will wait for one child to finish -# and return its exit status. -multijob_pre_fork() { _multijob_fork pre "$@" ; } - -# @FUNCTION: multijob_post_fork -# @DESCRIPTION: -# You must call this in the parent process after forking a child process. -# If the parallel limit has been hit, it will wait for one child to finish -# and return its exit status. -multijob_post_fork() { _multijob_fork post "$@" ; } - -# @FUNCTION: multijob_finish_one -# @DESCRIPTION: -# Wait for a single process to exit and return its exit code. -multijob_finish_one() { - [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments" - - local pid ret - read -r -u ${mj_read_fd} pid ret || die - : $(( --mj_num_jobs )) - return ${ret} -} - -# @FUNCTION: multijob_finish -# @DESCRIPTION: -# Wait for all pending processes to exit and return the bitwise or -# of all their exit codes. -multijob_finish() { - local ret=0 - while [[ ${mj_num_jobs} -gt 0 ]] ; do - multijob_finish_one - : $(( ret |= $? )) - done - # Let bash clean up its internal child tracking state. - wait - - # Do this after reaping all the children. - [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments" - - # No need to hook anymore. - EBUILD_DEATH_HOOKS=${EBUILD_DEATH_HOOKS/ wait / } - - return ${ret} -} - -# @FUNCTION: redirect_alloc_fd -# @USAGE: [redirection] -# @DESCRIPTION: -# Find a free fd and redirect the specified file via it. Store the new -# fd in the specified variable. Useful for the cases where we don't care -# about the exact fd #. -redirect_alloc_fd() { - local var=$1 file=$2 redir=${3:-"<>"} - - # Make sure /dev/fd is sane on Linux hosts. #479656 - if [[ ! -L /dev/fd && ${CBUILD} == *linux* ]] ; then - eerror "You're missing a /dev/fd symlink to /proc/self/fd." - eerror "Please fix the symlink and check your boot scripts (udev/etc...)." - die "/dev/fd is broken" - fi - - if [[ $(( (BASH_VERSINFO[0] << 8) + BASH_VERSINFO[1] )) -ge $(( (4 << 8) + 1 )) ]] ; then - # Newer bash provides this functionality. - eval "exec {${var}}${redir}'${file}'" - else - # Need to provide the functionality ourselves. - local fd=10 - while :; do - # Make sure the fd isn't open. It could be a char device, - # or a symlink (possibly broken) to something else. - if [[ ! -e /dev/fd/${fd} ]] && [[ ! -L /dev/fd/${fd} ]] ; then - eval "exec ${fd}${redir}'${file}'" && break - fi - [[ ${fd} -gt 1024 ]] && die 'could not locate a free temp fd !?' - : $(( ++fd )) - done - : $(( ${var} = fd )) - fi -} - fi diff --git a/eclass/tests/multiprocessing.sh b/eclass/tests/multiprocessing.sh deleted file mode 100755 index 1ceb7f7fa7b2..000000000000 --- a/eclass/tests/multiprocessing.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# Copyright 1999-2015 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -source tests-common.sh - -inherit multiprocessing - -tbegin "simple" -MAKEOPTS="-j1" multijob_init -multijob_child_init ls -d / >/dev/null || die "fail!" -multijob_finish -tend $? - -tbegin "less simple" -multijob_init -j3 -multijob_child_init true || die "fail!" -multijob_child_init false || die "fail!" -multijob_child_init true || die "fail!" -multijob_finish -tend $(( $? == 1 ? 0 : 1 )) - -tbegin "less less simple" -multijob_init -j1 -multijob_child_init true || die "fail!" -multijob_child_init false || die "fail!" -multijob_child_init true && die "fail!" -multijob_finish -tend $? - -tbegin "less less less simple" -multijob_init -j10 -multijob_child_init true || die "fail!" -multijob_finish_one || die "fail!" -multijob_child_init false || die "fail!" -multijob_finish_one && die "fail!" -multijob_child_init true || die "fail!" -multijob_finish_one || die "fail!" -multijob_finish -tend $? - -texit -- cgit v1.2.3