Implement filtering of autogenerated dependencies
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 10 Dec 2010 14:18:15 +0000 (16:18 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 10 Dec 2010 15:05:22 +0000 (17:05 +0200)
- This allows both excluding entire paths from dependency generation
  and also excluding individual generated dependencies by regexes
  settable from spec or other configuration.
- %__(provides|requires)_exclude regex controls is matched against
  generated dependencies, %__(provides|requires)_exclude_from is
  matched against the currently processed path, with buildroot
  stripped out.
- We'll probably want some "higher level" macros to go with this,
  but the mechanism is usable as-is already.
(cherry picked from commit 185de185262b2772fa692efc69633f41afc5832a)

build/rpmfc.c

index 2efe0eb..56bcb12 100644 (file)
@@ -455,6 +455,8 @@ static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep)
     rpmsenseFlags dsContext;
     rpmTagVal tagN;
     int pac;
+    regex_t *exclude = NULL;
+    regex_t *exclude_from = NULL;
 
     switch (deptype) {
     default:
@@ -478,9 +480,17 @@ static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep)
        break;
     }
 
+    /* If the entire path is filtered out, there's nothing more to do */
+    exclude_from = rpmfcAttrReg(depname, "exclude_from");
+    if (regMatch(exclude_from, fn+fc->brlen))
+       goto exit;
+
     pav = runCmd(nsdep, depname, fc->buildRoot, fn);
     pac = argvCount(pav);
 
+    if (pav)
+       exclude = rpmfcAttrReg(depname, "exclude");
+
     for (int i = 0; i < pac; i++) {
        rpmds ds = NULL;
        const char *N = pav[i];
@@ -509,17 +519,20 @@ static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep)
 
        ds = rpmdsSingle(tagN, N, EVR, Flags);
 
-       /* Add to package dependencies. */
-       (void) rpmdsMerge(depsp, ds);
-
-       /* Add to file dependencies. */
-       rpmfcAddFileDep(&fc->ddict, fc->ix, ds, deptype);
+       /* Add to package and file dependencies unless filtered */
+       if (regMatch(exclude, rpmdsDNEVR(ds)+2) == 0) {
+           (void) rpmdsMerge(depsp, ds);
+           rpmfcAddFileDep(&fc->ddict, fc->ix, ds, deptype);
+       }
 
        ds = rpmdsFree(ds);
     }
 
     argvFree(pav);
 
+exit:
+    regFree(exclude);
+    regFree(exclude_from);
     return 0;
 }