Sophie

Sophie

distrib > Mageia > 1 > i586 > media > core-updates-src > by-pkgid > 2d27fe3dff73e21c1aac97aebe0dff40 > files > 42

rpm-4.8.1-10.5.mga1.src.rpm

commit 12647c57e7550c5238d9a45a3d660a5cb3a8b8ce
Author: unknown author <cooker@mandrivalinux.org>
Date:   Mon Jan 5 13:29:57 2009 +0000

    rpmbuild check useless tags in non existant binary packages
    
    Two new fatal errors (during package build, but only for mdv packages and when
    %_missing_subpackage_terminate_build is set):
    
    - "%files foo" for subpackages is now mandatory
      (otherwise what's the use creating the subpackage in the first place)
    
    - disallow scriptlets for non packaged binary packages
      (eg: detect mistakes like "%post -p /sbin/ldconfig" instead of "%post -n libfoo -p /sbin/ldconfig")

diff --git a/build/parseSpec.c b/build/parseSpec.c
index ceb59c6..2da496d 100644
--- a/build/parseSpec.c
+++ b/build/parseSpec.c
@@ -421,6 +421,65 @@ void closeSpec(rpmSpec spec)
 	ofi = _free(ofi);
     }
 }
+static const char *_headerName(Header h)
+{
+  return headerGetString(h, RPMTAG_NAME);
+}
+
+static const char *_headerRelease(Header h)
+{
+  return headerGetString(h, RPMTAG_RELEASE);
+}
+
+static int checkNonPackagedRPM(Header h, int is_main_subpackage)
+{
+    int res = 0;
+    struct rpmtd_s td;
+
+    /* those checks are Mandriva only (May 2008),
+       and must not break non Mandriva packages */    
+    if ((strstr(_headerRelease(h), "mdv") == 0) || (strstr(_headerRelease(h), "mga") == 0)) return 0;
+
+    /* Check that no %pre, %post ... do not exist in this header, since they will be dropped */
+    HeaderIterator hi = headerInitIterator(h);
+    while (headerNext(hi, &td)) {
+      int tag = rpmtdTag(&td);
+      switch (tag) {
+      case RPMTAG_PREIN:
+      case RPMTAG_POSTIN:
+      case RPMTAG_PREUN:
+      case RPMTAG_POSTUN:
+      case RPMTAG_PREINPROG:
+      case RPMTAG_POSTINPROG:
+      case RPMTAG_PREUNPROG:
+      case RPMTAG_POSTUNPROG:
+      case RPMTAG_TRIGGERIN:
+      case RPMTAG_TRIGGERUN:
+      case RPMTAG_TRIGGERPOSTUN:
+
+	rpmlog(RPMLOG_ERR, _("Useless %%%s on non existant binary package \"%s\"\n"),
+		 rpmTagGetName(tag), _headerName(h));
+	res = 1;
+      }
+      rpmtdFreeData(&td);
+    }
+    hi = headerFreeIterator(hi);
+
+    if (!is_main_subpackage) {
+	 /* "%files foo" for subpackages is now mandatory */
+	 /* (otherwise what's the use creating the subpackage in the first place) */
+
+	 /* we must skip the *-__restore__ fake subpackage used after *-debug subpackage */
+	 if (strstr(_headerName(h), "__restore__") == NULL) {
+	      rpmlog(RPMLOG_ERR, _("Missing %%files for subpackage %s\n"),
+		       _headerName(h));
+	      res = 1;
+	 }
+    }
+
+
+    return res && rpmExpandNumeric("%{?_missing_subpackage_terminate_build}");
+}
 
 extern int noLang;		/* XXX FIXME: pass as arg */
 
@@ -596,6 +655,9 @@ int parseSpec(rpmts ts, const char *specFile, const char *rootDir,
 		   headerGetString(pkg->header, RPMTAG_NAME));
 	    goto errxit;
 	}
+	if (!pkg->fileList && checkNonPackagedRPM(pkg->header, pkg == spec->packages)) {
+	    goto errxit;
+	}
 
 	headerPutString(pkg->header, RPMTAG_OS, os);
 	/* noarch subpackages already have arch set here, leave it alone */