papp-text/dos2unix: Bump to version 7.4.1
[gentoo.git] / eclass / meson.eclass
index 06e76092a6b9518ebb7b5594a5afa7ec60f37bd1..fa859ace996f2433955cd0adb4a6b503816f6045 100644 (file)
@@ -1,10 +1,11 @@
-# Copyright 2017 Gentoo Foundation
+# Copyright 2017-2019 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: meson.eclass
 # @MAINTAINER:
 # William Hubbs <williamh@gentoo.org>
 # Mike Gilbert <floppym@gentoo.org>
+# @SUPPORTED_EAPIS: 6 7
 # @BLURB: common ebuild functions for meson-based packages
 # @DESCRIPTION:
 # This eclass contains the default phase functions for packages which
 # @CODE
 
 case ${EAPI:-0} in
-       6) ;;
+       6|7) ;;
        *) die "EAPI=${EAPI} is not supported" ;;
 esac
 
-if [[ ${__MESON_AUTO_DEPEND+set} == "set" ]] ; then
-       # See if we were included already, but someone changed the value
-       # of MESON_AUTO_DEPEND on us.  We could reload the entire
-       # eclass at that point, but that adds overhead, and it's trivial
-       # to re-order inherit in eclasses/ebuilds instead.  #409611
-       if [[ ${__MESON_AUTO_DEPEND} != ${MESON_AUTO_DEPEND} ]] ; then
-               die "MESON_AUTO_DEPEND changed value between inherits; please inherit meson.eclass first! ${__MESON_AUTO_DEPEND} -> ${MESON_AUTO_DEPEND}"
-       fi
-fi
-
 if [[ -z ${_MESON_ECLASS} ]]; then
 
-inherit ninja-utils python-utils-r1 toolchain-funcs
+inherit multiprocessing ninja-utils python-utils-r1 toolchain-funcs
 
 fi
 
@@ -59,19 +50,14 @@ EXPORT_FUNCTIONS src_configure src_compile src_test src_install
 if [[ -z ${_MESON_ECLASS} ]]; then
 _MESON_ECLASS=1
 
-MESON_DEPEND=">=dev-util/meson-0.40.0
+MESON_DEPEND=">=dev-util/meson-0.48.2
        >=dev-util/ninja-1.7.2"
 
-# @ECLASS-VARIABLE: MESON_AUTO_DEPEND
-# @DESCRIPTION:
-# Set to 'no' to disable automatically adding to DEPEND.  This lets
-# ebuilds form conditional depends by using ${MESON_DEPEND} in
-# their own DEPEND string.
-: ${MESON_AUTO_DEPEND:=yes}
-if [[ ${MESON_AUTO_DEPEND} != "no" ]] ; then
+if [[ ${EAPI:-0} == [6] ]]; then
        DEPEND=${MESON_DEPEND}
+else
+       BDEPEND=${MESON_DEPEND}
 fi
-__MESON_AUTO_DEPEND=${MESON_AUTO_DEPEND} # See top of eclass
 
 # @ECLASS-VARIABLE: BUILD_DIR
 # @DEFAULT_UNSET
@@ -92,6 +78,12 @@ __MESON_AUTO_DEPEND=${MESON_AUTO_DEPEND} # See top of eclass
 # Optional meson arguments as Bash array; this should be defined before
 # calling meson_src_configure.
 
+# @VARIABLE: emesontestargs
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Optional meson test arguments as Bash array; this should be defined before
+# calling meson_src_test.
+
 
 read -d '' __MESON_ARRAY_PARSER <<"EOF"
 import shlex
@@ -157,13 +149,18 @@ _meson_create_cross_file() {
        # This may require adjustment based on CFLAGS
        local cpu=${CHOST%%-*}
 
-       cat > "${T}/meson.${CHOST}" <<-EOF
+       cat > "${T}/meson.${CHOST}.${ABI}" <<-EOF
        [binaries]
-       ar = '$(tc-getAR)'
-       c = '$(tc-getCC)'
-       cpp = '$(tc-getCXX)'
+       ar = $(_meson_env_array "$(tc-getAR)")
+       c = $(_meson_env_array "$(tc-getCC)")
+       cpp = $(_meson_env_array "$(tc-getCXX)")
+       fortran = $(_meson_env_array "$(tc-getFC)")
+       llvm-config = '$(tc-getPROG LLVM_CONFIG llvm-config)'
+       objc = $(_meson_env_array "$(tc-getPROG OBJC cc)")
+       objcpp = $(_meson_env_array "$(tc-getPROG OBJCXX c++)")
        pkgconfig = '$(tc-getPKG_CONFIG)'
-       strip = '$(tc-getSTRIP)'
+       strip = $(_meson_env_array "$(tc-getSTRIP)")
+       windres = $(_meson_env_array "$(tc-getRC)")
 
        [properties]
        c_args = $(_meson_env_array "${CFLAGS} ${CPPFLAGS}")
@@ -198,7 +195,21 @@ meson_use() {
        usex "$1" "-D${2-$1}=true" "-D${2-$1}=false"
 }
 
+# @FUNCTION: meson_feature
+# @USAGE: <USE flag> [option name]
+# @DESCRIPTION:
+# Given a USE flag and meson project option, outputs a string like:
+#
+#   -Doption=enabled
+#   -Doption=disabled
+#
+# If the project option is unspecified, it defaults to the USE flag.
+meson_feature() {
+       usex "$1" "-D${2-$1}=enabled" "-D${2-$1}=disabled"
+}
+
 # @FUNCTION: meson_src_configure
+# @USAGE: [extra meson arguments]
 # @DESCRIPTION:
 # This is the meson_src_configure function.
 meson_src_configure() {
@@ -214,9 +225,9 @@ meson_src_configure() {
                --wrap-mode nodownload
                )
 
-       if tc-is-cross-compiler; then
+       if tc-is-cross-compiler || [[ ${ABI} != ${DEFAULT_ABI-${ABI}} ]]; then
                _meson_create_cross_file || die "unable to write meson cross file"
-               mesonargs+=( --cross-file "${T}/meson.${CHOST}" )
+               mesonargs+=( --cross-file "${T}/meson.${CHOST}.${ABI}" )
        fi
 
        # https://bugs.gentoo.org/625396
@@ -233,30 +244,46 @@ meson_src_configure() {
 }
 
 # @FUNCTION: meson_src_compile
+# @USAGE: [extra ninja arguments]
 # @DESCRIPTION:
 # This is the meson_src_compile function.
 meson_src_compile() {
        debug-print-function ${FUNCNAME} "$@"
 
-       eninja -C "${BUILD_DIR}"
+       eninja -C "${BUILD_DIR}" "$@"
 }
 
 # @FUNCTION: meson_src_test
+# @USAGE: [extra meson test arguments]
 # @DESCRIPTION:
 # This is the meson_src_test function.
 meson_src_test() {
        debug-print-function ${FUNCNAME} "$@"
 
-       eninja -C "${BUILD_DIR}" test
+       local mesontestargs=(
+               -C "${BUILD_DIR}"
+       )
+       [[ -n ${NINJAOPTS} || -n ${MAKEOPTS} ]] &&
+               mesontestargs+=(
+                       --num-processes "$(makeopts_jobs ${NINJAOPTS:-${MAKEOPTS}})"
+               )
+
+       # Append additional arguments from ebuild
+       mesontestargs+=("${emesontestargs[@]}")
+
+       set -- meson test "${mesontestargs[@]}" "$@"
+       echo "$@" >&2
+       "$@" || die "tests failed"
 }
 
 # @FUNCTION: meson_src_install
+# @USAGE: [extra ninja install arguments]
 # @DESCRIPTION:
 # This is the meson_src_install function.
 meson_src_install() {
        debug-print-function ${FUNCNAME} "$@"
 
-       DESTDIR="${D}" eninja -C "${BUILD_DIR}" install
+       DESTDIR="${D}" eninja -C "${BUILD_DIR}" install "$@"
        einstalldocs
 }