Re: rpmbuild-nonroot %{version} interpreted incorrectly

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

 



Hi,

I wrote,

> I've come up with a patch that fixes the macros %{PACKAGE_VERSION} and
> %{PACKAGE_RELEASE} so one can use
> 
> %_sourcedir	%{_topdir}/%{name}-%{PACKAGE_VERSION}
> 
> Fixing the preferred macros %{version} and %{release} via
> headerAddEntry() is much more intrusive, so I'm not sure if creating
> such a patch is worth the time spent (not even sure if inclusion would
> be considered as the above bug is a WONTFIX).

The patch to fix the other macros was not as intrusive as I thought. The
attached patch now distinguishes between PART_PREAMBLE and PART_PACKAGE
(newly introduced). It sets initialPackage to 0 only after the first
%package tag is found and sets the macros conditionally.

This patch seems to work as intended. You can now use
%_sourcedir	%{_topdir}/%{name}-%{version}

The only question remaining is if there are other macros apart from
%{version} and %{release} that should not be overwritten when a next
package is parsed.

Leonard.

-- 
mount -t life -o ro /dev/dna /genetic/research

--- rpm-4.2.1/build/rpmbuild.h.000	2002-12-24 07:02:26.000000000 +0100
+++ rpm-4.2.1/build/rpmbuild.h	2004-06-21 12:48:42.000000000 +0200
@@ -69,7 +69,8 @@
     PART_VERIFYSCRIPT	= 16,	/*!< */
     PART_BUILDARCHITECTURES= 17,/*!< */
     PART_TRIGGERPOSTUN	= 18,	/*!< */
-    PART_LAST		= 19	/*!< */
+    PART_PACKAGE	= 19,	/*!< */
+    PART_LAST		= 20	/*!< */
 } rpmParseState;
 
 #define STRIP_NOTHING             0
--- rpm-4.2.1/build/parseSpec.c.000	2003-05-15 15:38:57.000000000 +0200
+++ rpm-4.2.1/build/parseSpec.c	2004-06-21 04:46:31.000000000 +0200
@@ -25,7 +25,9 @@
 /*@observer@*/ /*@null@*/
     const char * token;
 } partList[] = {
-    { PART_PREAMBLE,      0, "%package"},
+/* PART_PREAMBLE is not associated with a tag
+   initialPackage now gets unset when first PART_PACKAGE is reached */
+    { PART_PACKAGE,       0, "%package"},
     { PART_PREP,          0, "%prep"},
     { PART_BUILD,         0, "%build"},
     { PART_INSTALL,       0, "%install"},
@@ -456,7 +458,10 @@
 	switch (parsePart) {
 	case PART_PREAMBLE:
 	    parsePart = parsePreamble(spec, initialPackage);
+	    /*@switchbreak@*/ break;
+	case PART_PACKAGE:
 	    initialPackage = 0;
+	    parsePart = parsePreamble(spec, initialPackage);
 	    /*@switchbreak@*/ break;
 	case PART_PREP:
 	    parsePart = parsePrep(spec);
--- rpm-4.2.1/build/parsePreamble.c.000	2002-12-21 18:26:43.000000000 +0100
+++ rpm-4.2.1/build/parsePreamble.c	2004-06-21 04:50:33.000000000 +0200
@@ -459,7 +459,7 @@
  */
 /*@-boundswrite@*/
 static int handlePreambleTag(Spec spec, Package pkg, int tag, const char *macro,
-			     const char *lang)
+			     const char *lang, const int initialPackage)
 	/*@globals rpmGlobalMacroContext, fileSystem, internalState @*/
 	/*@modifies spec->macros, spec->st, spec->buildRootURL,
 		spec->sources, spec->numSources, spec->noSource,
@@ -521,14 +521,16 @@
 		    spec->lineNum, "version", spec->line);
 		return RPMERR_BADSPEC;
 	    }
-	    addMacro(spec->macros, "PACKAGE_VERSION", NULL, field, RMIL_OLDSPEC);
+	    if (initialPackage)
+		addMacro(spec->macros, "PACKAGE_VERSION", NULL, field, RMIL_OLDSPEC);
 	} else if (tag == RPMTAG_RELEASE) {
 	    if (strchr(field, '-') != NULL) {
 		rpmError(RPMERR_BADSPEC, _("line %d: Illegal char '-' in %s: %s\n"),
 		    spec->lineNum, "release", spec->line);
 		return RPMERR_BADSPEC;
 	    }
-	    addMacro(spec->macros, "PACKAGE_RELEASE", NULL, field, RMIL_OLDSPEC-1);
+	    if (initialPackage)
+		addMacro(spec->macros, "PACKAGE_RELEASE", NULL, field, RMIL_OLDSPEC-1);
 	}
 	(void) headerAddEntry(pkg->header, tag, RPM_STRING_TYPE, field, 1);
 	break;
@@ -712,9 +714,20 @@
 	return RPMERR_INTERNAL;
     }
 
-    if (macro)
-	addMacro(spec->macros, macro, NULL, field, RMIL_SPEC);
-    
+    if (macro) {
+	if (initialPackage) {
+	    addMacro(spec->macros, macro, NULL, field, RMIL_SPEC);
+	} else {
+	    switch (tag) {
+		case RPMTAG_VERSION:
+		case RPMTAG_RELEASE:
+		/* Which other macros should not be rewritten? */
+		    break;
+		default:
+		    addMacro(spec->macros, macro, NULL, field, RMIL_SPEC);
+	    }
+	}
+    }
     return 0;
 }
 /*@=boundswrite@*/
@@ -906,7 +918,7 @@
 				spec->lineNum, spec->line);
 		    return RPMERR_BADSPEC;
 		}
-		if (handlePreambleTag(spec, pkg, tag, macro, lang))
+		if (handlePreambleTag(spec, pkg, tag, macro, lang, initialPackage))
 		    return RPMERR_BADSPEC;
 		if (spec->BANames && !spec->recursing)
 		    return PART_BUILDARCHITECTURES;

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux