A new saner interface for parsing spec files
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 1 Sep 2010 13:49:43 +0000 (16:49 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 1 Sep 2010 13:49:43 +0000 (16:49 +0300)
- For now just a wrapper around parseSpec() that returns *gasp*
  a pointer to a parsed spec structure.
- Limit the amount of goo that needs passing - optimally we'd only need
  the spec + parsing flags, but due to %{buildroot} macro abuse in specs
  we'll need that for now too.

build/parseSpec.c
build/rpmbuild.h
build/rpmspec.h

index 3d99ec6..f48a132 100644 (file)
@@ -696,3 +696,18 @@ errxit:
     spec = freeSpec(spec);
     return PART_ERROR;
 }
+
+rpmSpec rpmSpecParse(const char *specFile, rpmSpecFlags flags,
+                    const char *buildRoot)
+{
+    rpmts ts = rpmtsCreate();
+    rpmSpec spec = NULL;
+
+    if (parseSpec(ts, specFile, NULL, buildRoot, 0, NULL, NULL,
+                 (flags & RPMSPEC_ANYARCH), (flags & RPMSPEC_FORCE)) == 0) {
+       spec = rpmtsSetSpec(ts, NULL);
+    }
+
+    rpmtsFree(ts);
+    return spec;
+}
index 36bb1c6..a923909 100644 (file)
@@ -71,6 +71,18 @@ extern int _noDirTokens;
 
 /** \ingroup rpmbuild
  * Parse spec file into spec control structure.
+ * @todo Eliminate buildRoot from here, its a build, not spec property
+ *
+ * @param specFile     path to spec file
+ * @param flags                flags to control operation
+ * @param buildRoot    buildRoot override or NULL for default
+ * @return             new spec control structure
+ */
+rpmSpec rpmSpecParse(const char *specFile, rpmSpecFlags flags,
+                    const char *buildRoot);
+
+/** \ingroup rpmbuild
+ * Parse spec file into spec control structure.
  * @param ts           transaction set (spec file control in ts->spec)
  * @param specFile
  * @param rootDir      (unused)
index 450f264..5f4331b 100644 (file)
@@ -24,6 +24,12 @@ typedef struct Package_s * Package;
 
 #define RPMBUILD_DEFAULT_LANG "C"
 
+typedef enum rpmSpecFlags_e {
+    RPMSPEC_NONE       = 0,
+    RPMSPEC_ANYARCH    = (1 << 0),
+    RPMSPEC_FORCE      = (1 << 1),
+} rpmSpecFlags;
+
 /** \ingroup rpmbuild
  */
 struct Source {