libshit

Just some random shit
git clone https://git.neptards.moe/neptards/libshit.git
Log | Files | Refs | Submodules | README | LICENSE

ninja-utils.eclass (2594B)


      1 # Copyright 1999-2022 Gentoo Authors
      2 # Distributed under the terms of the GNU General Public License v2
      3 
      4 # @ECLASS: ninja-utils.eclass
      5 # @MAINTAINER:
      6 # Michał Górny <mgorny@gentoo.org>
      7 # Mike Gilbert <floppym@gentoo.org>
      8 # @AUTHOR:
      9 # Michał Górny <mgorny@gentoo.org>
     10 # Mike Gilbert <floppym@gentoo.org>
     11 # @SUPPORTED_EAPIS: 5 6 7 8
     12 # @BLURB: common bits to run dev-util/ninja builder
     13 # @DESCRIPTION:
     14 # This eclass provides a single function -- eninja -- that can be used
     15 # to run the ninja builder alike emake. It does not define any
     16 # dependencies, you need to depend on dev-util/ninja yourself. Since
     17 # ninja is rarely used stand-alone, most of the time this eclass will
     18 # be used indirectly by the eclasses for other build systems (CMake,
     19 # Meson).
     20 
     21 case ${EAPI} in
     22 	5|6|7|8) ;;
     23 	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
     24 esac
     25 
     26 if [[ -z ${_NINJA_UTILS_ECLASS} ]]; then
     27 _NINJA_UTILS_ECLASS=1
     28 
     29 # @ECLASS_VARIABLE: NINJA
     30 # @PRE_INHERIT
     31 # @DESCRIPTION:
     32 # Specify a compatible ninja implementation to be used by eninja().
     33 # At this point only "ninja" and "samu" are explicitly supported,
     34 # but other values can be set where NINJA_DEPEND will then be set
     35 # to a blank variable.
     36 # The default is set to "ninja".
     37 : ${NINJA:=ninja}
     38 
     39 # @ECLASS_VARIABLE: NINJA_DEPEND
     40 # @OUTPUT_VARIABLE
     41 # @DESCRIPTION:
     42 # Contains a set of build-time depenendencies based on the NINJA setting.
     43 
     44 # @ECLASS_VARIABLE: NINJAOPTS
     45 # @DEFAULT_UNSET
     46 # @DESCRIPTION:
     47 # The default set of options to pass to Ninja. Similar to MAKEOPTS,
     48 # supposed to be set in make.conf. If unset, eninja() will convert
     49 # MAKEOPTS instead.
     50 
     51 inherit multiprocessing
     52 
     53 case "${NINJA}" in
     54 	ninja)
     55 		NINJA_DEPEND=">=dev-util/ninja-1.8.2"
     56 	;;
     57 	samu)
     58 		NINJA_DEPEND="dev-util/samurai"
     59 	;;
     60 	*)
     61 		NINJA_DEPEND=""
     62 	;;
     63 esac
     64 
     65 # @FUNCTION: get_NINJAOPTS
     66 # @DESCRIPTION:
     67 # Get the value of NINJAOPTS, inferring them from MAKEOPTS if unset.
     68 get_NINJAOPTS() {
     69 	if [[ -z ${NINJAOPTS+set} ]]; then
     70 		NINJAOPTS="-j$(makeopts_jobs "${MAKEOPTS}" 999) -l$(makeopts_loadavg "${MAKEOPTS}" 0)"
     71 	fi
     72 	echo "${NINJAOPTS}"
     73 }
     74 
     75 # @FUNCTION: eninja
     76 # @USAGE: [<args>...]
     77 # @DESCRIPTION:
     78 # Call Ninja, passing the NINJAOPTS (or converted MAKEOPTS), followed
     79 # by the supplied arguments. This function dies if ninja fails. Starting
     80 # with EAPI 6, it also supports being called via 'nonfatal'.
     81 eninja() {
     82 	local nonfatal_args=()
     83 	[[ ${EAPI} != 5 ]] && nonfatal_args+=( -n )
     84 
     85 	[[ -n "${NINJA_DEPEND}" ]] || ewarn "Unknown value '${NINJA}' for \${NINJA}"
     86 	set -- "${NINJA}" -v $(get_NINJAOPTS) "$@"
     87 	echo "$@" >&2
     88 	"$@" || die "${nonfatal_args[@]}" "${*} failed"
     89 }
     90 
     91 fi