Gentoo Archives: gentoo-portage-dev

From: "Marijn Schouten (hkBst)" <hkBst@g.o>
To: "gentoo-dev@l.g.o" <gentoo-dev@l.g.o>
Cc: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] More general interface to use flags
Date: Fri, 02 Nov 2007 13:43:23
Message-Id: 472B2969.1070701@gentoo.org
1 Hi list,
2
3 the current interface to use flags, useq, usev, use_with, use_enable, as
4 defined in /usr/lib/portage/bin/ebuild.sh lacks generality. The common thing
5 is testing a use flag and possibly echoing a string, but there is no function
6 that implements this common behaviour.
7
8 I propose that we add such a function. Proposed name for the function is "ifuse".
9
10 I also propose to add the utility function "ifv" which is useful for writing
11 concise and clean code.
12
13 These additions would allow you to easily define your own function for
14 processing use flags in ebuilds and eclasses. One such example is
15
16 use_mime() {
17 local WORD=$(ifv "$2" "$2" "$1")
18
19 ifuse "$1" "${WORD};"
20 }
21
22 for generating a string of ';'-separated mime-types based on use flags.
23
24 The explanation of this function is:
25
26 #set WORD to argument 2 or if that is empty to argument 1
27 #output "${WORD};" if use flag $1 is set (or if it starts with ! and is unset)
28 #otherwise don't output anything
29
30 The existing interface is also simple to reimplement:
31
32 use() {
33 ifuse "${1}"
34 }
35
36 useq() {
37 ifuse "${1}"
38 }
39
40 usev() {
41 ifuse "${1}" "${1}"
42 }
43
44 use_with() {
45 local SUFFIX=$(ifv "$3" "=$3")
46 local WORD=$(ifv "$2" "$2" "$1")
47
48 ifuse "$1" "--with-${WORD}${SUFFIX}" "--without-${WORD}"
49 }
50
51 use_enable() {
52 local SUFFIX=$(ifv "$3" "=$3")
53 local WORD=$(ifv "$2" "$2" "$1")
54
55 ifuse "$1" "--enable-${WORD}${SUFFIX}" "--disable-${WORD}"
56 }
57
58 ifuse's code is much like useq's code now, but more versatile. You can find it
59 attached along with ifv.
60
61 Please comment,
62
63 Marijn
64
65 --
66 Marijn Schouten (hkBst), Gentoo Lisp project
67 <http://www.gentoo.org/proj/en/lisp/>, #gentoo-lisp on FreeNode

Attachments

File name MIME type
new_use_interface text/plain
signature.asc application/pgp-signature