gbp.log.debug("Failed to import '%s' as rpm python module, using host's default rpm library instead" % RpmPkgPolicy.python_rpmlib_module_name)
import rpm
-# define a large number to check the valid id of source file
-MAX_SOURCE_NUMBER = 99999
-
class NoSpecError(Exception):
"""Spec file parsing error"""
'setup_options': None, }
# 'Patch:' tags
elif tagname == 'patch':
- tagnum = 0 if tagnum is None else tagnum
+ tagnum = -1 if tagnum is None else tagnum
new_patch = {'name': matchobj.group('name').strip(),
'filename': matchobj.group('name'),
'apply': False,
elif opts.patchnum:
directiveid = int(opts.patchnum)
else:
- directiveid = 0
+ directiveid = -1
if opts.strip:
self.patches[directiveid]['strip'] = opts.strip
# And, double-check that we parsed spec content correctly
for (name, num, typ) in self._specinfo.sources:
# workaround rpm parsing bug
- if num >= MAX_SOURCE_NUMBER:
- num = 0
if typ == 1 or typ == 9:
if num in self.sources:
self.sources[num]['filename'] = os.path.basename(name)
else:
gbp.log.err("BUG: we didn't correctly parse all 'Source' tags!")
if typ == 2 or typ == 10:
+ # Patch tag without any number defined is treated by RPM as
+ # having number (2^31-1), we use number -1
+ if num >= pow(2,30):
+ num = -1
if num in self.patches:
self.patches[num]['filename'] = name
else:
prev = spec.protected('_delete_tag')('Vendor', None)
spec.protected('_set_tag')('License', None, 'new license', prev)
spec.protected('_delete_tag')('source', 0)
- spec.protected('_delete_tag')('patch', 1)
spec.protected('_delete_tag')('patch', 0)
+ spec.protected('_delete_tag')('patch', -1)
prev = spec.protected('_delete_tag')('invalidtag', None)
with assert_raises(GbpError):
spec.set_tag('invalidtag', None, 'value')
# Mangle macros
- prev = spec.protected('_delete_special_macro')('patch', 0)
+ prev = spec.protected('_delete_special_macro')('patch', -1)
spec.protected('_delete_special_macro')('patch', 123)
- spec.protected('_set_special_macro')('patch', 1, 'my new args', prev)
+ spec.protected('_set_special_macro')('patch', 0, 'my new args', prev)
with assert_raises(GbpError):
spec.protected('_delete_special_macro')('invalidmacro', 0)
with assert_raises(GbpError):
(name, val['value'], rval))
assert spec.ignorepatches == []
+ assert spec.patches.keys() == [0, -1]
+
class TestUtilityFunctions(object):
"""Test utility functions of L{gbp.rpm}"""