[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Doubts about nested %if in spec file



On Tue, May 21, 2002 at 09:51:56AM +0200, Simon J Mudd wrote:
> Hello all,
> 
> I'm a little unsure of whether nested %if s are allowed.

They are allowed, but actually, they don't work. Rpm doesn't expand
macros on the false branch of the %if, but tries to evaluate the
expression even when the macros were not expanded.

> 
[snip]
> 
> My spec file has various different build time options and under the ones I 
> personally use I don't experience this error.
> 
> Perhaps nested %if macros are not recommended or the use of %if macros 
> around %triggerin macros needs to be done a certain way.

IMO, sometimes, when you have many build time options, it's almost
impossible to make a maintainable specfile without using nested %if macros.

> 
> Any suggestions would be welcome.
> 

A few months ago, I've posted to this list a patch that fixes it.
But I didn't received any replies. Here it is again:


--- rpm-4.0.3/build/parseSpec.c.orig	Wed Mar 20 19:10:01 2002
+++ rpm-4.0.3/build/parseSpec.c	Wed Mar 20 19:12:20 2002
@@ -266,12 +266,23 @@
 	os = _free(os);
     } else if (! strncmp("%if", s, sizeof("%if")-1)) {
 	s += 3;
-        match = parseExpressionBoolean(spec, s);
-	if (match < 0) {
-	    rpmError(RPMERR_UNMATCHEDIF,
-			_("%s:%d: parseExpressionBoolean returns %d\n"),
-			ofi->fileName, ofi->lineNum, match);
-	    return RPMERR_BADSPEC;
+        /* When nesting %if's, don't try to parse %if expression on
+         * the false branch of the parent %if
+         */
+	if ( spec->readStack->reading ) {
+	    match = parseExpressionBoolean(spec, s);
+	    if (match < 0) {
+		rpmError(RPMERR_UNMATCHEDIF,
+			    _("%s:%d: parseExpressionBoolean returns %d\n"),
+			    ofi->fileName, ofi->lineNum, match);
+		return RPMERR_BADSPEC;
+	    }
+	} else {
+	    /* The match value doesn't matter, we are in the
+	     * false branch of the %if, anyway.
+	     * It just needs to be != -1
+	     */
+	    match = 0;
 	}
     } else if (! strncmp("%else", s, sizeof("%else")-1)) {
 	s += 5;



-- 
Eduardo Pereira Habkost <ehabkost@conectiva.com.br>
04BE D2EF 5A56 E446 D424  4785 71A4 49EB AC35 9568
----
QOTD:
die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs);
	2.2.16 /usr/src/linux/arch/sparc/kernel/traps.c

Attachment: pgp00004.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []