summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-01-07 13:56:14 +0200
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-04-03 10:11:41 +0300
commit7b749bcdf027fabdf756dd0b8e129073600eb816 (patch)
tree81191dbc05b8dcbacc35b369ab70d02915c15f7a
parent64bb75e63040e2cf3f4c0b92c106cc8a0a5ac643 (diff)
downloadgit-buildpackage-7b749bcdf027fabdf756dd0b8e129073600eb816.tar.gz
git-buildpackage-7b749bcdf027fabdf756dd0b8e129073600eb816.tar.bz2
git-buildpackage-7b749bcdf027fabdf756dd0b8e129073600eb816.zip
rpm: fix crash when building broken spec
Fixes a crash when spec contains setup macro for non-existent source. The package build would fail but gbp shouldn't crash, of course. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/rpm/__init__.py2
-rw-r--r--tests/test_rpm.py8
-rw-r--r--tests/test_rpm_data/specs/gbp-test-quirks.spec18
3 files changed, 27 insertions, 1 deletions
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py
index 3f501791..5b1007ec 100644
--- a/gbp/rpm/__init__.py
+++ b/gbp/rpm/__init__.py
@@ -379,7 +379,7 @@ class SpecFile(object):
srcnum = int(opts.unpack_after)
else:
srcnum = 0
- if srcnum != None:
+ if srcnum != None and srcnum in self.sources:
self.sources[srcnum]['setup_options'] = opts
# Save the occurrence of last setup macro
ret['setupmacro'] = lineobj
diff --git a/tests/test_rpm.py b/tests/test_rpm.py
index 55eab93b..a651fe2c 100644
--- a/tests/test_rpm.py
+++ b/tests/test_rpm.py
@@ -177,6 +177,14 @@ class TestSpecFile(object):
spec.write_spec_file()
assert filecmp.cmp(tmp_spec, reference_spec) is True
+ def test_quirks(self):
+ """Test spec that is broken/has anomalities"""
+ spec_filepath = os.path.join(SPEC_DIR, 'gbp-test-quirks.spec')
+ spec = SpecFile(spec_filepath)
+
+ # Check that we quess orig source and prefix correctly
+ assert spec.orig_src['prefix'] == 'foobar/'
+
class TestUtilityFunctions(object):
"""Test utility functions of L{gbp.rpm}"""
diff --git a/tests/test_rpm_data/specs/gbp-test-quirks.spec b/tests/test_rpm_data/specs/gbp-test-quirks.spec
new file mode 100644
index 00000000..64db07fb
--- /dev/null
+++ b/tests/test_rpm_data/specs/gbp-test-quirks.spec
@@ -0,0 +1,18 @@
+#
+# Spec for testing some quirks of spec parsing
+#
+
+Name: pkg_name
+Summary: Spec for testing some quirks of spec parsing
+Version: 0.1
+Release: 1.2
+License: GPLv2
+Source1: foobar.tar.gz
+
+%description
+Spec for testing some quirks of spec parsing. No intended for building an RPM.
+
+%prep
+# We don't have Source0 so rpmbuild would fail, but gbp shouldn't crash
+%setup -q
+