diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-01-07 13:56:14 +0200 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-03-08 14:04:00 +0200 |
commit | cd9b53a87fc9b710e9b7f04522d35d894ac45a7c (patch) | |
tree | 9bc81783284442effce8c65f3729a09aad0757f5 | |
parent | 77ab2ba0b22a8ce7d7e54e73264e12b9cabf64a5 (diff) | |
download | git-buildpackage-cd9b53a87fc9b710e9b7f04522d35d894ac45a7c.tar.gz git-buildpackage-cd9b53a87fc9b710e9b7f04522d35d894ac45a7c.tar.bz2 git-buildpackage-cd9b53a87fc9b710e9b7f04522d35d894ac45a7c.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__.py | 2 | ||||
-rw-r--r-- | tests/test_rpm.py | 8 | ||||
-rw-r--r-- | tests/test_rpm_data/specs/gbp-test-quirks.spec | 18 |
3 files changed, 27 insertions, 1 deletions
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index 713208a2..e4da707a 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 + |