self._special_directives[key].append(linerec)
return ret
- def update_patches(self, patchfilenames):
+ def update_patches(self, patches, commands):
"""Update spec with new patch tags and patch macros"""
# Remove non-ignored patches
tag_prev = None
# Remove '%patch:' macros
for macro in self._special_directives['patch']:
if not macro['id'] in ignored:
+ macro_prev = self._delete_special_macro('patch', macro['id'])
+ # Remove surrounding if-else
+ macro_next = macro_prev.next
+ if (str(macro_prev).startswith('%if') and
+ str(macro_next).startswith('%endif')):
+ self._content.delete(macro_next)
+ macro_prev = self._content.delete(macro_prev)
+
# Remove a preceding comment line if it ends with '.patch' or
# '.diff' plus an optional compression suffix
- macro_prev = self._delete_special_macro('patch', macro['id'])
if re.match("^\s*#.+(patch|diff)(\.(gz|bz2|xz|lzma))?\s*$",
str(macro_prev), flags=re.I):
macro_prev = self._content.delete(macro_prev)
- if len(patchfilenames) == 0:
+ if len(patches) == 0:
return
# Determine where to add Patch tag lines
# Add a comment indicating gbp generated patch tags
comment_text = "# Patches auto-generated by git-buildpackage:\n"
tag_line = self._content.insert_after(tag_line, comment_text)
- for ind, name in enumerate(patchfilenames):
+ for ind, patch in enumerate(patches):
+ cmds = commands[patch] if patch in commands else {}
patchnum = startnum + ind
- tag_line = self._set_tag("Patch", patchnum, name, tag_line)
+ tag_line = self._set_tag("Patch", patchnum, patch, tag_line)
# Add '%patch' macro and a preceding comment line
- comment_text = "# %s\n" % name
+ comment_text = "# %s\n" % patch
macro_line = self._content.insert_after(macro_line, comment_text)
macro_line = self._set_special_macro('patch', patchnum, '-p1',
macro_line)
+ for cmd, args in cmds.iteritems():
+ if cmd in ('if', 'ifarch'):
+ self._content.insert_before(macro_line, '%%%s %s\n' %
+ (cmd, args))
+ macro_line = self._content.insert_after(macro_line,
+ '%endif\n')
+ # We only support one command per patch, for now
+ break
def patchseries(self, unapplied=False, ignored=False):
"""Return non-ignored patches of the RPM as a gbp patchseries"""
gbp.log.info("Removing imported patch files from spec and packaging dir")
rm_patch_files(spec)
try:
- spec.update_patches([])
+ spec.update_patches([], {})
spec.write_spec_file()
except GbpError:
repo.force_head('HEAD', hard=True)
# Generate patches
for commit in reversed(repo.get_commits(start, end_commit)):
info = repo.get_commit_info(commit)
- cmds = parse_gbp_commands(info, 'gbp-rpm', ('ignore'), None)
+ cmds = parse_gbp_commands(info, 'gbp-rpm', ('ignore'), ('if', 'ifarch'))
if not 'ignore' in cmds:
patch_fn = format_patch(outdir, repo, info, patches,
options.patch_numbers,
# Unlink old patch files and generate new patches
rm_patch_files(spec)
- patches, _commands = generate_patches(repo, start, squash, end,
- spec.specdir, options)
- spec.update_patches(patches)
+ patches, commands = generate_patches(repo, start, squash, end,
+ spec.specdir, options)
+ spec.update_patches(patches, commands)
spec.write_spec_file()
reference_spec = os.path.join(SPEC_DIR, 'gbp-test-reference.spec')
spec = SpecFile(tmp_spec)
- spec.update_patches(['new.patch'])
+ spec.update_patches(['new.patch'], {})
spec.write_spec_file()
assert filecmp.cmp(tmp_spec, reference_spec) is True
reference_spec = os.path.join(SPEC_DIR, 'gbp-test2-reference2.spec')
spec = SpecFile(tmp_spec)
- spec.update_patches(['1.patch', '2.patch'])
+ spec.update_patches(['1.patch', '2.patch'],
+ {'1.patch': {'if': 'true'},
+ '2.patch': {'ifarch': '%ix86'}})
spec.set_tag('VCS', None, 'myvcstag')
- spec.update_patches(['new.patch'])
spec.write_spec_file()
assert filecmp.cmp(tmp_spec, reference_spec) is True
- # Test removing the VCS tag
+ # Test updating patches again and removing the VCS tag
reference_spec = os.path.join(SPEC_DIR, 'gbp-test2-reference.spec')
+ spec.update_patches(['new.patch'], {'new.patch': {'if': '1'}})
spec.set_tag('VCS', None, '')
spec.write_spec_file()
assert filecmp.cmp(tmp_spec, reference_spec) is True
spec = SpecFileTester(spec_filepath)
assert len(spec.patchseries()) == 0
- spec.update_patches(['1.patch', '2.patch', '3.patch'])
+ spec.update_patches(['1.patch', '2.patch', '3.patch'], {})
assert len(spec.patchseries()) == 3
spec.protected('_gbp_tags')['ignore-patches'].append({'args': "0"})
- spec.update_patches(['4.patch'])
+ spec.update_patches(['4.patch'], {})
assert len(spec.patchseries()) == 1
assert len(spec.patchseries(ignored=True)) == 2
spec.protected('_delete_special_macro')('patch', 0)
# Gbp-Patch-Macros
# new.patch
+%if 1
%patch0 -p1
+%endif
%build
make
# Gbp-Ignore-Patches: -1
Patch: my.patch
# Patches auto-generated by git-buildpackage:
-Patch0: new.patch
+Patch0: 1.patch
+Patch1: 2.patch
Packager: Markus Lehtonen <markus.lehtonen@linux.intel.com>
VCS: myvcstag
echo "Do things"
# Gbp-Patch-Macros
-# new.patch
+# 1.patch
+%if true
%patch0 -p1
+%endif
+# 2.patch
+%ifarch %ix86
+%patch1 -p1
+%endif
%build
make