Commit 0fd16706 authored by Jelmer Vernooij's avatar Jelmer Vernooij

Provide environment variable with current version.

parent 5a7cacc8
#!/usr/bin/python3
from io import BytesIO
import os
from lintian_brush.control import update_control
from debian.deb822 import PkgRelation
from debian.changelog import Changelog, Version
from debian.changelog import Version
minimum_version = Version("9.20160114")
......@@ -34,13 +35,10 @@ def del_dbg(control):
update_control(source_package_cb=bump_debhelper, binary_package_cb=del_dbg)
with open('debian/changelog', 'rb') as f:
cl = Changelog(f)
if cl.distributions == "UNRELEASED":
version = "<< %s" % cl.version
else:
version = "<= %s" % cl.version
current_version = os.environ["CURRENT_VERSION"]
migrate_version = "<< %s%s" % (
current_version,
'' if current_version.endswith('~') else '~')
outf = BytesIO()
with open('debian/rules', 'rb') as f:
......@@ -54,7 +52,7 @@ with open('debian/rules', 'rb') as f:
line = line.replace(
('--dbg-package=%s' % dbg_pkg).encode('utf-8'),
("--dbgsym-migration='%s (%s)'" % (
dbg_pkg, version)).encode('utf-8'))
dbg_pkg, migrate_version)).encode('utf-8'))
dbg_migration_done.add(dbg_pkg)
outf.write(line)
......
......@@ -17,7 +17,9 @@
"""Automatically fix lintian issues."""
from debian.changelog import Changelog
import os
import re
import subprocess
import sys
......@@ -87,10 +89,13 @@ class ScriptFixer(Fixer):
def __repr__(self):
return "<ScriptFixer(%r)>" % (os.path.basename(self.script_path))
def run(self, basedir):
def run(self, basedir, current_version):
note('Running fixer %r on %s', self, basedir)
env = dict(os.environ.items())
env['CURRENT_VERSION'] = str(current_version)
p = subprocess.Popen(self.script_path, cwd=basedir,
stdout=subprocess.PIPE, stderr=sys.stderr)
stdout=subprocess.PIPE, stderr=sys.stderr,
env=env)
(description, err) = p.communicate("")
if p.returncode != 0:
raise ScriptFailed("Script %s failed with error code %d" % (
......@@ -157,6 +162,15 @@ def available_lintian_fixers(fixers_dir=None):
yield fixer
def increment_version(v):
if v.debian_revision is not None:
v.debian_revision = re.sub(
'\\d+$', lambda x: str(int(x.group())+1), v.debian_revision)
else:
v.upstream_version = re.sub(
'\\d+$', lambda x: str(int(x.group())+1), v.upstream_version)
def run_lintian_fixer(local_tree, fixer, update_changelog=True):
"""Run a lintian fixer on a tree.
......@@ -170,8 +184,15 @@ def run_lintian_fixer(local_tree, fixer, update_changelog=True):
# Just check there are no changes to begin with
if list(local_tree.iter_changes(local_tree.basis_tree())):
raise AssertionError("Local tree %s has changes" % local_tree.basedir)
with local_tree.get_file('debian/changelog') as f:
cl = Changelog(f, max_blocks=1)
if cl.distributions == 'UNRELEASED':
current_version = cl.version
else:
current_version = cl.version
increment_version(current_version)
try:
result = fixer.run(local_tree.basedir)
result = fixer.run(local_tree.basedir, current_version=current_version)
except BaseException:
revert(local_tree, local_tree.branch.basis_tree(), None)
deletables = list(iter_deletables(
......
......@@ -29,6 +29,14 @@ from lintian_brush import (
run_lintian_fixer,
)
CHANGELOG_FILE = ('debian/changelog', """\
blah (0.1) UNRELEASED; urgency=medium
* Initial release. (Closes: #911016)
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
""")
class AvailableLintianFixersTest(TestCaseWithTransport):
......@@ -57,7 +65,7 @@ Lintian-Tags: i-fix-another-tag, no-extension
class DummyFixer(Fixer):
def run(self, basedir):
def run(self, basedir, current_version):
with open(os.path.join(basedir, 'debian/control'), 'a') as f:
f.write('a new line\n')
return FixerResult("Fixed some tag.\nExtended description.",
......@@ -72,15 +80,16 @@ class RunLintianFixerTests(TestCaseWithTransport):
self.build_tree_contents([
('debian/', ),
('debian/control', """\
Source: blah\
Source: blah
Vcs-Git: https://example.com/blah
Testsuite: autopkgtest
Binary: blah
Arch: all
""")])
self.tree.add(['debian', 'debian/control'])
"""),
CHANGELOG_FILE])
self.tree.add(['debian', 'debian/changelog', 'debian/control'])
self.tree.commit('Initial thingy.')
def test_simple_modify(self):
......@@ -96,7 +105,7 @@ Arch: all
def test_new_file(self):
class NewFileFixer(Fixer):
def run(self, basedir):
def run(self, basedir, current_version):
with open(os.path.join(basedir, 'debian/somefile'), 'w') as f:
f.write("test")
return FixerResult("Created new file.", ['some-tag'])
......@@ -121,7 +130,7 @@ Arch: all
def test_rename_file(self):
class RenameFileFixer(Fixer):
def run(self, basedir):
def run(self, basedir, current_version):
os.rename(os.path.join(basedir, 'debian/control'),
os.path.join(basedir, 'debian/control.blah'))
return FixerResult("Renamed a file.")
......@@ -145,7 +154,7 @@ Arch: all
def test_empty_change(self):
class EmptyFixer(Fixer):
def run(self, basedir):
def run(self, basedir, current_version):
return FixerResult("I didn't actually change anything.")
with self.tree.lock_write():
self.assertRaises(
......@@ -158,7 +167,7 @@ Arch: all
def test_fails(self):
class FailingFixer(Fixer):
def run(self, basedir):
def run(self, basedir, current_version):
with open(os.path.join(basedir, 'debian/foo'), 'w') as f:
f.write("blah")
with open(os.path.join(basedir, 'debian/control'), 'a') as f:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment