rpm helpers: support all tags
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 3 Jan 2013 15:08:36 +0000 (17:08 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 7 Jan 2014 14:21:30 +0000 (16:21 +0200)
Support all 'non-list' tags that we know of.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/rpm/__init__.py
gbp/rpm/policy.py
tests/test_rpm.py
tests/test_rpm_data/specs/gbp-test-tags.spec [new file with mode: 0644]

index 6e1d4ff20cc9b75fe244382c55f597d05c626412..08e782a4a866f0c4529c939d76d544cd9a3c8cce 100644 (file)
@@ -137,6 +137,13 @@ class SpecFile(object):
         # Use rpm-python to parse the spec file content
         self._filtertags = ("excludearch", "excludeos", "exclusivearch",
                             "exclusiveos","buildarch")
+        self._listtags = self._filtertags + ('source', 'patch',
+                                  'requires', 'conflicts', 'recommends',
+                                  'suggests', 'supplements', 'enhances',
+                                  'provides', 'obsoletes', 'buildrequires',
+                                  'buildconflicts', 'buildrecommends',
+                                  'buildsuggests', 'buildsupplements',
+                                  'buildenhances', 'collections')
         self._specinfo = self._parse_filtered_spec(self._filtertags)
 
         # Other initializations
@@ -282,11 +289,15 @@ class SpecFile(object):
         except AttributeError:
             tagvalue = None
         # We don't support "multivalue" tags like "Provides:" or "SourceX:"
-        if type(tagvalue) is list:
+        # Rpm python doesn't support many of these, thus the explicit list
+        if type(tagvalue) is int or type(tagvalue) is long:
+            tagvalue = str(tagvalue)
+        elif type(tagvalue) is list or tagname in self._listtags:
             tagvalue = None
         elif not tagvalue:
-            # Rpm python doesn't give BuildRequires, for some reason
-            if tagname not in ('buildrequires',) + self._filtertags:
+            # Rpm python doesn't give the following, for reason or another
+            if tagname not in ('buildroot', 'nopatch', 'nosource', 'autoprov',
+                               'autoreq', 'autoreqprov') + self._filtertags:
                 gbp.log.warn("BUG: '%s:' tag not found by rpm" % tagname)
             tagvalue = matchobj.group('value')
         linerecord = {'line': lineobj,
index f73f1d9236e0db11c8208047b4ea65cc0f69df91..d5b096baf107d4b484cbb2b53f8c738f4e4766a2 100644 (file)
@@ -23,7 +23,7 @@ class RpmPkgPolicy(PkgPolicy):
     """Packaging policy for RPM"""
 
     # Special rpmlib python module for GBP (only)
-    python_rpmlib_module_name = "rpmlibgbp"
+    python_rpmlib_module_name = "rpm_tizen"
 
     alnum = 'a-zA-Z0-9'
     # Valid characters for RPM pkg name
index ec2c834aeadb191cfdd40301e12771cc2a25d643..ad4525b8772c0ace240c1392884ab758cc1341a5 100644 (file)
@@ -230,6 +230,25 @@ class TestSpecFile(object):
         # Check that we quess orig source and prefix correctly
         assert spec.orig_src['prefix'] == 'foobar/'
 
+    def test_tags(self):
+        """Test parsing of all the different tags of spec file"""
+        spec_filepath = os.path.join(SPEC_DIR, 'gbp-test-tags.spec')
+        spec = SpecFileTester(spec_filepath)
+
+        # Check all the tags
+        for name, val in spec.protected('_tags').iteritems():
+            rval = None
+            if name in ('version', 'release', 'epoch', 'nosource', 'nopatch'):
+                rval = '0'
+            elif name in ('autoreq', 'autoprov', 'autoreqprov'):
+                rval = 'No'
+            elif name not in spec.protected('_listtags'):
+                rval = 'my_%s' % name
+            if rval:
+                assert val['value'] == rval, ("'%s:' is '%s', expecting '%s'" %
+                                              (name, val['value'], rval))
+            assert spec.ignorepatches == []
+
 
 class TestUtilityFunctions(object):
     """Test utility functions of L{gbp.rpm}"""
diff --git a/tests/test_rpm_data/specs/gbp-test-tags.spec b/tests/test_rpm_data/specs/gbp-test-tags.spec
new file mode 100644 (file)
index 0000000..9841a39
--- /dev/null
@@ -0,0 +1,70 @@
+#
+# Spec file for testing all RPM tags (that we know of
+#
+
+%define suse_release %(test -e /etc/SuSE-release && head -n1 /etc/SuSE-release | cut -d ' ' -f2 | cut --output-delimiter=0 -d. -f1,2 || echo 0)
+%if "%{suse_release}" >= "1201"
+%define test_weak_dep_tags 1
+%endif
+
+%define test_arch_os_tags %(test -n "$GBP_SKIP_ARCH_OS_TAGS" && echo 0 || echo 1)
+
+# Gbp-Undefined-Tag: foobar
+
+# Test that we accept different cases
+NAME:           my_name
+version:        0
+ReLeasE:        0
+
+# Rest of the tags
+Epoch:          0
+Summary:        my_summary
+License:        my_license
+Distribution:   my_distribution
+Vendor:         my_vendor
+Group:          my_group
+Packager:       my_packager
+Url:            my_url
+Vcs:            my_vcs
+Source:         my_source
+Patch0:         my_patch
+Nosource:       0
+Nopatch:        0
+#Icon:           my_icon
+BuildRoot:      my_buildroot
+Provides:       my_provides
+Requires:       my_requires
+Conflicts:      my_conflicts
+Obsoletes:      my_obsoletes
+BuildConflicts: my_buildconflicts
+BuildRequires:  my_buildrequires
+AutoReqProv:    No
+AutoReq:        No
+AutoProv:       No
+DistTag:        my_disttag
+BugUrl:         my_bugurl
+Collections:    my_collections
+
+%if 0%{?test_weak_dep_tags}
+Recommends:     my_recommends
+Suggests:       my_suggests
+Supplements:    my_supplements
+Enhances:       my_enhances
+BuildRecommends:my_buildrecommends
+BuildSuggests:  my_buildsuggests
+BuildSupplements:my_buildsupplements
+BuildEnhances:  my_buildenhances
+%endif
+
+# These should be filtered out by GBP
+%if "%{test_arch_os_tags}" != "0"
+BuildArch:      my_buildarch
+ExcludeArch:    my_excludearch
+ExclusiveArch:  my_exclusivearch
+ExcludeOs:      my_excludeos
+ExclusiveOs:    my_exclusiveos
+%endif
+
+%description
+Package for testing GBP.
+