Re: [gentoo-portage-dev] use* cleanup

2007-10-30 Thread Mike Frysinger
On Tuesday 30 October 2007, Marijn Schouten (hkBst) wrote:
> The purpose of this patch is to expose a generic function, namely _use,
> which can be used to build your own use* variant if you need that. I
> reimplemented all other current use function using _use (and _if) to cut
> out duplicate and verbose code. Comments expected. I didn't test this code.

i guess i dont really see it ... there isnt that much duplicate code to begin 
with, and the end result is kind of hard to understand at first glance which 
is a bad thing ...
-mike


signature.asc
Description: This is a digitally signed message part.


Re: [gentoo-portage-dev] use* cleanup

2007-10-30 Thread Mike Frysinger
On Tuesday 30 October 2007, Marius Mauch wrote:
> On Tue, 30 Oct 2007 19:32:52 +0100
>
> "Marijn Schouten (hkBst)" <[EMAIL PROTECTED]> wrote:
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA1
> >
> > The purpose of this patch is to expose a generic function, namely
> > _use, which can be used to build your own use* variant if you need
> > that. I reimplemented all other current use function using _use (and
> > _if) to cut out duplicate and verbose code. Comments expected. I
> > didn't test this code.
>
> Please don't post patches inline, there are these things called
> attachments that work so much better for such things.

posting inline only works if done right ... but this wasnt done right ;)

ignoring the word wrappings, whitespacing looks broken/inconsistent
-mike


signature.asc
Description: This is a digitally signed message part.


Re: [gentoo-portage-dev] use* cleanup

2007-10-30 Thread Marius Mauch
On Tue, 30 Oct 2007 19:32:52 +0100
"Marijn Schouten (hkBst)" <[EMAIL PROTECTED]> wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> The purpose of this patch is to expose a generic function, namely
> _use, which can be used to build your own use* variant if you need
> that. I reimplemented all other current use function using _use (and
> _if) to cut out duplicate and verbose code. Comments expected. I
> didn't test this code.

Please don't post patches inline, there are these things called
attachments that work so much better for such things.

Marius
-- 
[EMAIL PROTECTED] mailing list



[gentoo-portage-dev] use* cleanup

2007-10-30 Thread Marijn Schouten (hkBst)
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

The purpose of this patch is to expose a generic function, namely _use, which
can be used to build your own use* variant if you need that. I reimplemented
all other current use function using _use (and _if) to cut out duplicate and
verbose code. Comments expected. I didn't test this code.

Marijn

diff -uw /usr/lib64/portage/bin/ebuild.sh ~/ebuild.sh
@@ -150,40 +150,68 @@
return 0
 }

- -use() {
- -   useq ${1}
+_if() {
+$1 && echo $2 || echo $3
 }

- -usev() {
- -   if useq ${1}; then
- -   echo "${1}"
- -   return 0
- -   fi
+# Fully generic conditional use flag function.
+# $1: calling function
+# $2: use flag to check
+# $3: string to echo on success
+# $4: string to echo on failure
+_use() {
+   if [[ $# = 1 ]]; then
+   echo "!!! $1() called without a parameter." >&2
+   echo "!!! $1  [ [value]]" >&2
return 1
- -}
+   fi

- -useq() {
- -   local u=$1
+   local flag=$2
+   local string_success=$3
+   local string_failure=$4
local found=0

- -   # if we got something like '!flag', then invert the return value
- -   if [[ ${u:0:1} == "!" ]] ; then
- -   u=${u:1}
- -   found=1
- -   fi
+# when $flag is '!blah', invert the return value and strip the '!' from 
flag
+   [[ ${flag} = !* ]] && { found=1 ; flag=${flag:1} }

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

- -   if hasq ${u} ${USE} ; then
- -   return ${found}
+   if hasq ${flag} ${USE} ; then
+   echo ${string_success}; return ${found}
else
- -   return $((!found))
+   echo ${string_failure}; return $((!found))
fi
 }

+use() {
+   _use ${FUNCNAME[0]} ${1}
+}
+
+useq() {
+   _use ${FUNCNAME[0]} ${1}
+}
+
+usev() {
+_use ${FUNCNAME[0]} ${1} ${1}
+}
+
+use_with() {
+   local SUFFIX="$(_if [ -z $3 ] "" "=$3")"
+   local WORD="$(_if [ -z $2 ] $1 $2)"
+
+   _use ${FUNCNAME[0]} $1 "--with-${WORD}${SUFFIX}" "--without-${WORD}"
+}
+
+use_enable() {
+   local SUFFIX="$(_if [ -z $3 ] "" "=$3")"
+   local WORD="$(_if [ -z $2 ] $1 $2)"
+
+   _use ${FUNCNAME[0]} $1 "--enable-${WORD}${SUFFIX}" "--disable-${WORD}"
+}
+
 has_version() {
if [ "${EBUILD_PHASE}" == "depend" ]; then
die "portageq calls (has_version calls portageq) are not
allowed in the global scope"
@@ -227,56 +255,6 @@
"${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
 }

- -use_with() {
- -   if [ -z "$1" ]; then
- -   echo "!!! use_with() called without a parameter." >&2
- -   echo "!!! use_with  [ [value]]" >&2
- -   return 1
- -   fi
- -
- -   local UW_SUFFIX=""
- -   if [ ! -z "${3}" ]; then
- -   UW_SUFFIX="=${3}"
- -   fi
- -
- -   local UWORD="$2"
- -   if [ -z "${UWORD}" ]; then
- -   UWORD="$1"
- -   fi
- -
- -   if useq $1; then
- -   echo "--with-${UWORD}${UW_SUFFIX}"
- -   else
- -   echo "--without-${UWORD}"
- -   fi
- -   return 0
- -}
- -
- -use_enable() {
- -   if [ -z "$1" ]; then
- -   echo "!!! use_enable() called without a parameter." >&2
- -   echo "!!! use_enable  [ [value]]" >&2
- -   return 1
- -   fi
- -
- -   local UE_SUFFIX=""
- -   if [ ! -z "${3}" ]; then
- -   UE_SUFFIX="=${3}"
- -   fi
- -
- -   local UWORD="$2"
- -   if [ -z "${UWORD}" ]; then
- -   UWORD="$1"
- -   fi
- -
- -   if useq $1; then
- -   echo "--enable-${UWORD}${UE_SUFFIX}"
- -   else
- -   echo "--disable-${UWORD}"
- -   fi
- -   return 0
- -}
- -

- --
Marijn Schouten (hkBst), Gentoo Lisp project
, #gentoo-lisp on FreeNode
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHJ3jUp/VmCx0OL2wRAnduAJ9BkYDzf7ROLUeVVOQ4m5oVZ3TNoQCeIlQ9
9XN6WDbj4CtojnRX9Zc9ny8=
=4pj9
-END PGP SIGNATURE-
-- 
[EMAIL PROTECTED] mailing list



[gentoo-portage-dev] src_test cleanup

2007-10-30 Thread Marijn Schouten (hkBst)
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

The following patch was also on gentoo-dev before. It eliminates some dead
code paths from default src_test and in the process eliminates references to
FEATURES which is good for allowing ebuild.sh to be shared with other package
managers.

Marijn

diff -uw /usr/lib64/portage/bin/ebuild.sh ~/ebuild.sh
@@ -709,16 +666,10 @@
 src_test() {
if emake -j1 check -n &> /dev/null; then
vecho ">>> Test phase [check]: ${CATEGORY}/${PF}"
- -   if ! emake -j1 check; then
- -   hasq test $FEATURES && die "Make check failed. See
above for details."
- -   hasq test $FEATURES || eerror "Make check failed. See
above for details."
- -   fi
+emake -j1 check || die "Make check failed. See above for details."
elif emake -j1 test -n &> /dev/null; then
vecho ">>> Test phase [test]: ${CATEGORY}/${PF}"
- -   if ! emake -j1 test; then
- -   hasq test $FEATURES && die "Make test failed. See
above for details."
- -   hasq test $FEATURES || eerror "Make test failed. See
above for details."
- -   fi
+emake -j1 test || die "Make test failed. See above for details."
else
vecho ">>> Test phase [none]: ${CATEGORY}/${PF}"
fi

- --
Marijn Schouten (hkBst), Gentoo Lisp project
, #gentoo-lisp on FreeNode
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHJ2usp/VmCx0OL2wRArFMAKC7kPj/i9pxUNOM3nsG99qzIFP9AQCfepvh
HmpExOB6pc4ZZFlxOFC3G1I=
=eboG
-END PGP SIGNATURE-
-- 
[EMAIL PROTECTED] mailing list