diff options
author | Ulrich Müller <ulm@gentoo.org> | 2020-09-09 17:17:57 +0200 |
---|---|---|
committer | Ulrich Müller <ulm@gentoo.org> | 2020-09-12 18:02:59 +0200 |
commit | 5b4288a15ca2d2d92c280bcd9895a2a862163f23 (patch) | |
tree | 8cb0ff8f8b576e0da771fb5b58292005e3f83f7d /eclass | |
parent | edos2unix.eclass: New eclass, split off from eutils. (diff) | |
download | gentoo-5b4288a15ca2d2d92c280bcd9895a2a862163f23.tar.gz gentoo-5b4288a15ca2d2d92c280bcd9895a2a862163f23.tar.bz2 gentoo-5b4288a15ca2d2d92c280bcd9895a2a862163f23.zip |
wrapper.eclass: New eclass, split off from eutils.
Signed-off-by: Ulrich Müller <ulm@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/eutils.eclass | 51 | ||||
-rw-r--r-- | eclass/wrapper.eclass | 61 |
2 files changed, 63 insertions, 49 deletions
diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass index 3b3e328ba30d..0072f4ccf3e7 100644 --- a/eclass/eutils.eclass +++ b/eclass/eutils.eclass @@ -22,9 +22,9 @@ _EUTILS_ECLASS=1 case ${EAPI:-0} in 0|1|2|3|4|5|6) inherit desktop edos2unix epatch estack ltprune multilib \ - preserve-libs toolchain-funcs vcs-clean + preserve-libs toolchain-funcs vcs-clean wrapper ;; - 7) inherit edos2unix ;; + 7) inherit edos2unix wrapper ;; *) die "${ECLASS} is banned in EAPI ${EAPI}" ;; esac @@ -112,53 +112,6 @@ strip-linguas() { export LINGUAS=${newls:1} } -# @FUNCTION: make_wrapper -# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] -# @DESCRIPTION: -# Create a shell wrapper script named wrapper in installpath -# (defaults to the bindir) to execute target (default of wrapper) by -# first optionally setting LD_LIBRARY_PATH to the colon-delimited -# libpaths followed by optionally changing directory to chdir. -make_wrapper() { - local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 - local tmpwrapper=$(emktemp) - has "${EAPI:-0}" 0 1 2 && local EPREFIX="" - - ( - echo '#!/bin/sh' - if [[ -n ${libdir} ]] ; then - local var - if [[ ${CHOST} == *-darwin* ]] ; then - var=DYLD_LIBRARY_PATH - else - var=LD_LIBRARY_PATH - fi - cat <<-EOF - if [ "\${${var}+set}" = "set" ] ; then - export ${var}="\${${var}}:${EPREFIX}${libdir}" - else - export ${var}="${EPREFIX}${libdir}" - fi - EOF - fi - [[ -n ${chdir} ]] && printf 'cd "%s" &&\n' "${EPREFIX}${chdir}" - # We don't want to quote ${bin} so that people can pass complex - # things as ${bin} ... "./someprog --args" - printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}" - ) > "${tmpwrapper}" - chmod go+rx "${tmpwrapper}" - - if [[ -n ${path} ]] ; then - ( - exeopts -m 0755 - exeinto "${path}" - newexe "${tmpwrapper}" "${wrapper}" - ) || die - else - newbin "${tmpwrapper}" "${wrapper}" || die - fi -} - path_exists() { eerror "path_exists has been removed. Please see the following post" eerror "for a replacement snippet:" diff --git a/eclass/wrapper.eclass b/eclass/wrapper.eclass new file mode 100644 index 000000000000..8cde94979d1a --- /dev/null +++ b/eclass/wrapper.eclass @@ -0,0 +1,61 @@ +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: wrapper.eclass +# @MAINTAINER: +# base-system@gentoo.org +# @BLURB: create a shell wrapper script + +if [[ -z ${_WRAPPER_ECLASS} ]]; then +_WRAPPER_ECLASS=1 + +inherit eutils # for emktemp + +# @FUNCTION: make_wrapper +# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] +# @DESCRIPTION: +# Create a shell wrapper script named wrapper in installpath +# (defaults to the bindir) to execute target (default of wrapper) +# by first optionally setting LD_LIBRARY_PATH to the colon-delimited +# libpaths followed by optionally changing directory to chdir. +make_wrapper() { + local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 + local tmpwrapper=$(emktemp) + has "${EAPI:-0}" 0 1 2 && local EPREFIX="" + + ( + echo '#!/bin/sh' + if [[ -n ${libdir} ]] ; then + local var + if [[ ${CHOST} == *-darwin* ]] ; then + var=DYLD_LIBRARY_PATH + else + var=LD_LIBRARY_PATH + fi + cat <<-EOF + if [ "\${${var}+set}" = "set" ] ; then + export ${var}="\${${var}}:${EPREFIX}${libdir}" + else + export ${var}="${EPREFIX}${libdir}" + fi + EOF + fi + [[ -n ${chdir} ]] && printf 'cd "%s" &&\n' "${EPREFIX}${chdir}" + # We don't want to quote ${bin} so that people can pass complex + # things as ${bin} ... "./someprog --args" + printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}" + ) > "${tmpwrapper}" + chmod go+rx "${tmpwrapper}" + + if [[ -n ${path} ]] ; then + ( + exeopts -m 0755 + exeinto "${path}" + newexe "${tmpwrapper}" "${wrapper}" + ) || die + else + newbin "${tmpwrapper}" "${wrapper}" || die + fi +} + +fi |