public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] More general interface to use flags
@ 2007-11-02 13:44 Marijn Schouten (hkBst)
  2007-11-02 14:04 ` Roy Marples
  2007-11-04 10:54 ` [gentoo-dev] " Steve Long
  0 siblings, 2 replies; 38+ messages in thread
From: Marijn Schouten (hkBst) @ 2007-11-02 13:44 UTC (permalink / raw
  To: gentoo-dev@lists.gentoo.org; +Cc: gentoo-portage-dev


[-- Attachment #1.1: Type: text/plain, Size: 1725 bytes --]

Hi list,

the current interface to use flags, useq, usev, use_with, use_enable, as
defined in /usr/lib/portage/bin/ebuild.sh lacks generality. The common thing
is testing a use flag and possibly echoing a string, but there is no function
that implements this common behaviour.

I propose that we add such a function. Proposed name for the function is "ifuse".

I also propose to add the utility function "ifv" which is useful for writing
concise and clean code.

These additions would allow you to easily define your own function for
processing use flags in ebuilds and eclasses. One such example is

use_mime() {
    local WORD=$(ifv "$2" "$2" "$1")

    ifuse "$1" "${WORD};"
}

for generating a string of ';'-separated mime-types based on use flags.

The explanation of this function is:

#set WORD to argument 2 or if that is empty to argument 1
#output "${WORD};" if use flag $1 is set (or if it starts with ! and is unset)
#otherwise don't output anything

The existing interface is also simple to reimplement:

use() {
    ifuse "${1}"
}

useq() {
    ifuse "${1}"
}

usev() {
    ifuse "${1}" "${1}"
}

use_with() {
    local SUFFIX=$(ifv "$3" "=$3")
    local WORD=$(ifv "$2" "$2" "$1")

    ifuse "$1" "--with-${WORD}${SUFFIX}" "--without-${WORD}"
}

use_enable() {
    local SUFFIX=$(ifv "$3" "=$3")
    local WORD=$(ifv "$2" "$2" "$1")

    ifuse "$1" "--enable-${WORD}${SUFFIX}" "--disable-${WORD}"
}

ifuse's code is much like useq's code now, but more versatile. You can find it
attached along with ifv.

Please comment,

Marijn

-- 
Marijn Schouten (hkBst), Gentoo Lisp project
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-lisp on FreeNode

[-- Attachment #1.2: new_use_interface --]
[-- Type: text/plain, Size: 785 bytes --]

# test a use flag and return the result, possibly echo a non-empty string
ifuse() {
    local flag=$1
    local string_success=$2
    local string_failure=$3
    local success=0

    # invert the return value for "!blah" and strip the '!'
    [[ ${flag} = !* ]] && { success=1 ; flag=${flag:1} }

    # Make sure we have this USE flag in IUSE
    if ! hasq "${flag}" ${IUSE} ${E_IUSE} && ! hasq "${flag}" ${PORTAGE_ARCHLIST} selinux; then
        eqawarn "QA Notice: USE Flag '${flag}' not in IUSE for ${CATEGORY}/${PF}"
    fi

    hasq "${flag}" ${USE} || ((success=1-success))

    string=$( (( ${success} == 0 )) && echo ${string_success} || echo ${string_failure} )
    [[ -n ${string} ]] && echo ${string}
    return ${success}
}

ifv() {
    [[ -n $1 ]] && echo $2 || echo $3
}

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2007-11-06 11:57 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-02 13:44 [gentoo-dev] More general interface to use flags Marijn Schouten (hkBst)
2007-11-02 14:04 ` Roy Marples
2007-11-02 14:27   ` Marijn Schouten (hkBst)
2007-11-02 14:52     ` Roy Marples
2007-11-02 14:59   ` Mike Frysinger
2007-11-02 15:30     ` Roy Marples
2007-11-02 15:38       ` Mike Frysinger
2007-11-02 15:48         ` Roy Marples
2007-11-02 15:58           ` Mike Frysinger
2007-11-02 16:10             ` Roy Marples
2007-11-02 16:30               ` Bo Ørsted Andresen
2007-11-02 16:52                 ` Roy Marples
2007-11-02 17:17                   ` Bo Ørsted Andresen
2007-11-02 17:35                     ` Roy Marples
2007-11-03  0:19                       ` [gentoo-dev] POSIX shell and "portable" Fabian Groffen
2007-11-03  0:47                         ` Roy Marples
2007-11-05  9:22                           ` Michael Haubenwallner
2007-11-05 10:13                             ` Roy Marples
2007-11-05 13:21                               ` Michael Haubenwallner
2007-11-05 20:21                                 ` Mike Frysinger
2007-11-05 23:18                                   ` Roy Marples
2007-11-06  7:12                                     ` Ciaran McCreesh
2007-11-06  7:40                                       ` Roy Marples
2007-11-06  8:03                                         ` Ciaran McCreesh
2007-11-06  8:25                                           ` Roy Marples
2007-11-06  9:04                                     ` Michael Haubenwallner
2007-11-05 20:32                                 ` Roy Marples
2007-11-05 20:55                                   ` Fabian Groffen
2007-11-05 22:27                                   ` Mike Frysinger
2007-11-03  0:57                         ` Natanael copa
2007-11-03  1:06                         ` Roy Marples
2007-11-03 16:19                           ` [gentoo-dev] " Steve Long
2007-11-03  1:10                         ` [gentoo-dev] " Roy Marples
     [not found]                       ` <b41005390711022225i4f30bb01jbf5a040c60c4b088@mail.gmail.com>
2007-11-03  5:26                         ` Fwd: [gentoo-dev] More general interface to use flags Alec Warner
2007-11-03 21:57                           ` Mike Frysinger
2007-11-04 10:54 ` [gentoo-dev] " Steve Long
2007-11-04 21:54   ` Alec Warner
2007-11-06 11:50     ` Steve Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox