Fix bugs with %autosetup and --test builds.

Extract method, add some tests, and fixed the regex problem.
This commit is contained in:
Devan Goodwin 2016-04-14 09:04:49 -03:00
parent d802362964
commit 5d258e7d2e
2 changed files with 48 additions and 20 deletions

View file

@ -681,32 +681,45 @@ def munge_specfile(spec_file, commit_id, commit_count, fullname=None, tgz_filena
print('%s: %s' % (m.group(1), tgz_filename)) print('%s: %s' % (m.group(1), tgz_filename))
continue continue
m = re.match(r'^(\s*%(?:auto)?setup)(.*?)$', line) macro = munge_setup_macro(fullname, line)
if fullname and m: if macro is not None:
macro = m.group(1)
setup_arg = " -n %s" % fullname
args = m.group(2)
args_match = re.search(r'(.+?)\s+-n\s+\S+(.*)', args)
if args_match:
macro += args_match.group(1)
macro += args_match.group(2)
macro += setup_arg
else:
macro += args
macro += setup_arg
if "%autosetup" in macro:
args_match = re.search(r'(.+?)\s+-p[01]\s+\S+(.*)', args)
if not args_match:
macro = "{} -p1".format(macro)
print(macro) print(macro)
continue continue
print(line.rstrip('\n')) print(line.rstrip('\n'))
def munge_setup_macro(fullname, line):
"""
Adjust the %setup or %autosetup line in spec file to accomodate the renamed
test source.
Return None if the given line is not the setup or autosetup line.
"""
m = re.match(r'^(\s*%(?:auto)?setup)(.*?)$', line)
if fullname and m:
macro = m.group(1)
setup_arg = " -n %s" % fullname
args = m.group(2)
args_match = re.search(r'(.*?)\s+-n\s+\S+(.*)', args)
if args_match:
macro += args_match.group(1)
macro += args_match.group(2)
macro += setup_arg
else:
macro += args
macro += setup_arg
if "%autosetup" in macro:
args_match = re.search(r'(.+?)\s+-p[01]\s+\S+(.*)', args)
if not args_match:
macro = "{} -p1".format(macro)
return macro
return None
def scrape_version_and_release(template_file_name): def scrape_version_and_release(template_file_name):
"""Ideally, we'd let RPM report the version and release of a spec file as """Ideally, we'd let RPM report the version and release of a spec file as
in get_spec_version_and_release. However, when we are dealing with Cheetah in get_spec_version_and_release. However, when we are dealing with Cheetah

View file

@ -17,6 +17,7 @@ from tito.common import (replace_version, find_spec_like_file, increase_version,
search_for, compare_version, run_command_print, find_wrote_in_rpmbuild_output, search_for, compare_version, run_command_print, find_wrote_in_rpmbuild_output,
render_cheetah, increase_zstream, reset_release, find_file_with_extension, render_cheetah, increase_zstream, reset_release, find_file_with_extension,
normalize_class_name, extract_sha1, BugzillaExtractor, DEFAULT_BUILD_DIR, munge_specfile, normalize_class_name, extract_sha1, BugzillaExtractor, DEFAULT_BUILD_DIR, munge_specfile,
munge_setup_macro,
_out) _out)
from tito.compat import StringIO from tito.compat import StringIO
@ -632,3 +633,17 @@ class MockBug(object):
return self.flags[flag] return self.flags[flag]
else: else:
return None return None
class MungeSetupMacroTests(unittest.TestCase):
SOURCE = "tito-git-3.20362dd"
def test_setup(self):
line = "%setup -q -n tito-%{version}"
self.assertEqual("%setup -q -n " + self.SOURCE,
munge_setup_macro(self.SOURCE, line))
def test_autosetup(self):
line = "%autosetup -n tito-%{version}"
self.assertEqual("%autosetup -n " + self.SOURCE + " -p1",
munge_setup_macro(self.SOURCE, line))