Commit 5d9b8c8c authored by Jelmer Vernooij's avatar Jelmer Vernooij

* Add fixer for package-uses-deprecated-debhelper-compat-version

* Add support for fixing debhelper-but-no-misc-depends.
parents d20c67e2 42ef8aa9
......@@ -7,4 +7,4 @@ testsuite::
python3 setup.py test
README.md::
./buildtools/update-readme.py
PYTHONPATH=. ./buildtools/update-readme.py
......@@ -24,8 +24,10 @@ subset of the issues:
* ancient-python-version-field
* control-file-with-CRLF-EOLs
* copyright-has-crs
* debhelper-but-no-misc-depends
* debian-control-has-empty-field
* debian-control-has-obsolete-dbg-package
* debian-pyversions-is-obsolete
* debian-rules-should-not-use-pwd
* debian-upstream-obsolete-path
* debian-watch-uses-insecure-uri
......@@ -38,12 +40,15 @@ subset of the issues:
* missing-debian-source-format
* missing-vcs-browser-field
* out-of-date-copyright-format-uri
* package-needs-versioned-debhelper-build-depends
* package-uses-deprecated-debhelper-compat-version
* package-uses-deprecated-source-override-location
* priority-extra-is-replaced-by-priority-optional
* quilt-series-without-trailing-newline
* transitional-package-should-be-oldlibs-optional
* unnecessary-testsuite-autopkgtest-field
* unversioned-copyright-format-uri
* useless-autoreconf-build-depends
* vcs-field-uses-insecure-uri
* vcs-field-uses-not-recommended-uri-format
* wrong-debian-qa-group-name
......
lintian-brush (0.7) UNRELEASED; urgency=medium
* Add fixer for package-needs-versioned-debhelper-build-depends.
* Add fixer for package-uses-deprecated-debhelper-compat-version
* Add support for fixing debhelper-but-no-misc-depends.
-- Jelmer Vernooij <jelmer@debian.org> Fri, 09 Nov 2018 21:07:23 +0000
......
#!/usr/bin/python3
from lintian_brush.control import (
add_dependency,
parse_relations,
update_control,
)
uses_debhelper = False
misc_depends_added = []
def check_debhelper(control):
global uses_debhelper
if "Build-Depends" not in control:
return
for entry in parse_relations(control["Build-Depends"]):
(head_whitespace, relation, tail_whitespace) = entry
if any(r.name == 'debhelper' for r in relation):
uses_debhelper = True
def add_misc_depends(control):
global uses_debhelper
if not uses_debhelper:
return
for entry in parse_relations(control["Depends"]):
(head_whitespace, relation, tail_whitespace) = entry
if any(r.name == '${misc:Depends}' for r in relation):
return
control["Depends"] = add_dependency(control["Depends"], "${misc:Depends}")
misc_depends_added.append(control["Package"])
update_control(source_package_cb=check_debhelper,
binary_package_cb=add_misc_depends)
print("Add missing ${misc:Depends} to Depends for %s." %
", ".join(misc_depends_added))
print("Fixed-Lintian-Tags: debhelper-but-no-misc-depends")
#!/usr/bin/python3
from lintian_brush.control import (
update_control,
)
import urllib.parse
import urllib.request
known_https = [
'github.com', 'launchpad.net', 'pypi.python.org',
'pear.php.net', 'pecl.php.net', 'www.bioconductor.org',
'cran.r-project.org', 'wiki.debian.org']
def same_page(http_contents, https_contents):
# This is a pretty crude way to determine we end up on the same page, but
# it works.
http_contents = http_contents.replace(b'https', b'').replace(b'http', b'')
https_contents = https_contents.replace(b'https', b'').replace(
b'http', b'')
return http_contents == https_contents
def fix_homepage(http_url):
if not http_url.startswith('http:'):
return http_url
https_url = 'https:' + http_url[len('http:'):]
result = urllib.parse.urlparse(http_url)
if result.netloc in known_https:
return https_url
# Fall back to just comparing the two
http_contents = urllib.request.urlopen(http_url).read()
https_contents = urllib.request.urlopen(https_url).read()
if same_page(http_contents, https_contents):
return https_url
return http_url
def fix_homepage_header(control):
try:
homepage = control["Homepage"]
except KeyError:
return
control["Homepage"] = fix_homepage(homepage)
update_control(source_package_cb=fix_homepage_header)
print("Use secure URI in Homepage field.")
print("Fixed-Lintian-Tags: homepage-field-uses-insecure-uri")
#!/bin/sh
perl -p -i -e 's/^Homepage: http:\/\/github.com/Homepage: https:\/\/github.com/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/launchpad.net/Homepage: https:\/\/launchpad.net/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/pypi.python.org/Homepage: https:\/\/pypi.python.org/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/pear.php.net/Homepage: https:\/\/pear.php.net/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/pecl.php.net/Homepage: https:\/\/pecl.php.net/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/www.bioconductor.org/Homepage: https:\/\/www.bioconductor.org/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/bioconductor.org/Homepage: https:\/\/bioconductor.org/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/cran.r-project.org/Homepage: https:\/\/cran.r-project.org/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/wiki.debian.org/Homepage: https:\/\/wiki.debian.org/' debian/control
echo "Use secure URI in Homepage field."
echo "Fixed-Lintian-Tags: homepage-field-uses-insecure-uri"
......@@ -7,6 +7,9 @@ Lintian-Tags: control-file-with-CRLF-EOLs
Fix-Script: copyright-has-crs.sh
Lintian-Tags: copyright-has-crs
Fix-Script: debhelper-but-no-misc-depends.py
Lintian-Tags: debhelper-but-no-misc-depends
Fix-Script: debian-control-has-empty-field.py
Lintian-Tags: debian-control-has-empty-field
......@@ -34,7 +37,7 @@ Lintian-Tags: dm-upload-allowed-is-obsolete
Fix-Script: file-contains-trailing-whitespace.sh
Lintian-Tags: file-contains-trailing-whitespace
Fix-Script: homepage-field-uses-insecure-uri.sh
Fix-Script: homepage-field-uses-insecure-uri.py
Lintian-Tags: homepage-field-uses-insecure-uri
Fix-Script: insecure-copyright-format-uri.sh
......@@ -58,6 +61,9 @@ Lintian-Tags: package-needs-versioned-debhelper-build-depends
Fix-Script: package-uses-deprecated-source-override-location.sh
Lintian-Tags: package-uses-deprecated-source-override-location
Fix-Script: package-uses-deprecated-debhelper-compat-version.py
Lintian-Tags: package-uses-deprecated-debhelper-compat-version
Fix-Script: priority-extra-is-replaced-by-priority-optional.py
Lintian-Tags: priority-extra-is-replaced-by-priority-optional
......
......@@ -14,7 +14,7 @@ def bump_debhelper(control):
control["Build-Depends"] = ensure_minimum_version(
control["Build-Depends"],
"debhelper",
minimum_version)
"%s~" % minimum_version)
update_control(source_package_cb=bump_debhelper)
......
#!/usr/bin/python3
import os
import sys
from lintian_brush.control import (
ensure_minimum_version,
update_control,
)
# TODO(jelmer): Can we get these elsewhere rather than
# hardcoding them here?
minimum_debhelper_version = 9
default_debhelper_version = 11
if os.path.exists('debian/compat'):
with open('debian/compat', 'r') as f:
current = int(f.read().strip())
if current < minimum_debhelper_version:
new = default_debhelper_version
with open('debian/compat', 'w') as f:
f.write('%s\n' % new)
else:
# Nothing to do
sys.exit(2)
else:
sys.exit(2)
def bump_debhelper(control):
control["Build-Depends"] = ensure_minimum_version(
control["Build-Depends"],
"debhelper",
"%d~" % new)
update_control(source_package_cb=bump_debhelper)
print("Bump debhelper from deprecated %s to %s." % (current, new))
print("Fixed-Lintian-Tags: package-uses-deprecated-debhelper-compat-version")
......@@ -17,6 +17,7 @@
"""Utility functions for dealing with control files."""
import collections
from io import BytesIO
from debian.changelog import Version
......@@ -181,16 +182,61 @@ def ensure_minimum_version(relationstr, package, minimum_version):
changed = True
if not found:
changed = True
relations.append(
(' ' if len(relations) > 0 else '',
[PkgRelation(name=package, version=('>=', minimum_version))],
''))
_add_dependency(
relations,
[PkgRelation(name=package, version=('>=', minimum_version))])
if changed:
return format_relations(relations)
# Just return the original; we don't preserve all formatting yet.
return relationstr
def _add_dependency(relations, relation):
"""Add a dependency to a depends line.
Args:
relations: existing list of relations
relation: New relation
Returns:
Nothing
"""
if len(relations) == 0:
head_whitespace = ''
elif len(relations) == 1:
head_whitespace = (relations[0][0] or " ") # Best guess
else:
ws = collections.defaultdict(lambda: 0)
for r in relations[1:]:
ws[r[0]] += 1
if len(ws) == 1:
head_whitespace = list(ws.keys())[0]
else:
head_whitespace = relations[-1][0] # Best guest
if len(relations) == 0:
tail_whitespace = ''
else:
tail_whitespace = relations[-1][2]
relations[-1] = relations[-1][:2] + ('', )
relations.append((head_whitespace, relation, tail_whitespace))
def add_dependency(relationstr, relation):
"""Add a dependency to a depends line.
Args:
relationstr: existing relations line
relation: New relation
Returns:
Nothing
"""
relations = parse_relations(relationstr)
if isinstance(relation, str):
relation = PkgRelation.parse(relation)
_add_dependency(relations, relation)
return format_relations(relations)
def drop_dependency(relationstr, package):
"""Drop a dependency from a depends line.
......
......@@ -23,6 +23,7 @@ from breezy.tests import (
)
from lintian_brush.control import (
add_dependency,
can_preserve_deb822,
drop_dependency,
ensure_minimum_version,
......@@ -183,6 +184,17 @@ class EnsureMinimumVersionTests(TestCase):
'blah, debhelper (>= 9)',
ensure_minimum_version('blah', 'debhelper', '9'))
def test_unchanged(self):
self.assertEqual(
'debhelper (>= 9)', ensure_minimum_version(
'debhelper (>= 9)', 'debhelper', '9'))
self.assertEqual(
'debhelper (= 9)', ensure_minimum_version(
'debhelper (= 9)', 'debhelper', '9'))
self.assertEqual(
'debhelper (>= 9)', ensure_minimum_version(
'debhelper (>= 9)', 'debhelper', '9~'))
def test_updated(self):
self.assertEqual(
'debhelper (>= 9)',
......@@ -205,3 +217,30 @@ class DropDependencyTests(TestCase):
self.assertEqual(
' dh-autoreconf',
drop_dependency('debhelper (>= 9), dh-autoreconf', 'debhelper'))
class AddDependencyTests(TestCase):
def test_added(self):
self.assertEqual(
'debhelper (>= 9), dh-autoreconf',
add_dependency('debhelper (>= 9)', 'dh-autoreconf'))
self.assertEqual(
'debhelper (>= 9), ${misc:Depends}',
add_dependency('debhelper (>= 9)', '${misc:Depends}'))
def test_indentation(self):
self.assertEqual("""foo,
bar,
blah""", add_dependency("""foo,
bar""", 'blah'))
self.assertEqual("""foo,
bar,
blah""", add_dependency("""foo,
bar""", 'blah'))
self.assertEqual("""foo,
bar,
blah
""", add_dependency("""foo,
bar
""", 'blah'))
Source: f2fs-tools
Section: admin
Priority: optional
Maintainer: Jelmer Vernooij <jelmer@debian.org>
Build-Depends:
debhelper (>= 9)
Standards-Version: 4.2.0
Package: f2fs-tools
Architecture: linux-any
Depends: libf2fs5 (= ${binary:Version}), libf2fs-format4 (= ${binary:Version}), ${shlibs:Depends}
Description: Tools for Flash-Friendly File System
F2FS is a new filesystem for Linux aimed at NAND flash memory-based storage
devices, such as SSD, eMMC, and SD cards. It is based on Log-structured File
System (LFS).
Package: f2fs-tools-dbg
Section: debug
Architecture: linux-any
Depends: f2fs-tools (= ${binary:Version}), ${misc:Depends}
Description: Tools for Flash-Friendly File System (debug)
F2FS is a new filesystem for Linux aimed at NAND flash memory-based storage
devices, such as SSD, eMMC, and SD cards. It is based on Log-structured File
System (LFS).
.
This package contains the debugging symbols.
Add missing ${misc:Depends} to Depends for f2fs-tools.
Fixed-Lintian-Tags: debhelper-but-no-misc-depends
Source: f2fs-tools
Section: admin
Priority: optional
Maintainer: Jelmer Vernooij <jelmer@debian.org>
Build-Depends:
debhelper (>= 9)
Standards-Version: 4.2.0
Package: f2fs-tools
Architecture: linux-any
Depends: libf2fs5 (= ${binary:Version}), libf2fs-format4 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends}
Description: Tools for Flash-Friendly File System
F2FS is a new filesystem for Linux aimed at NAND flash memory-based storage
devices, such as SSD, eMMC, and SD cards. It is based on Log-structured File
System (LFS).
Package: f2fs-tools-dbg
Section: debug
Architecture: linux-any
Depends: f2fs-tools (= ${binary:Version}), ${misc:Depends}
Description: Tools for Flash-Friendly File System (debug)
F2FS is a new filesystem for Linux aimed at NAND flash memory-based storage
devices, such as SSD, eMMC, and SD cards. It is based on Log-structured File
System (LFS).
.
This package contains the debugging symbols.
......@@ -3,7 +3,7 @@ Section: admin
Priority: optional
Maintainer: Jelmer Vernooij <jelmer@debian.org>
Build-Depends:
debhelper (>= 10),
debhelper (>= 10~),
pkg-config,
uuid-dev
Standards-Version: 4.2.0
......
Source: f2fs-tools
Section: admin
Priority: optional
Maintainer: Jelmer Vernooij <jelmer@debian.org>
Build-Depends:
debhelper (>= 8),
pkg-config,
uuid-dev
Standards-Version: 4.2.0
Package: f2fs-tools
Architecture: linux-any
Depends: libf2fs5 (= ${binary:Version}), libf2fs-format4 (= ${binary:Version}), ${misc:Depends}, ${shlibs:Depends}
Description: Tools for Flash-Friendly File System
F2FS is a new filesystem for Linux aimed at NAND flash memory-based storage
devices, such as SSD, eMMC, and SD cards. It is based on Log-structured File
System (LFS).
Bump debhelper from deprecated 8 to 11.
Fixed-Lintian-Tags: package-uses-deprecated-debhelper-compat-version
Source: f2fs-tools
Section: admin
Priority: optional
Maintainer: Jelmer Vernooij <jelmer@debian.org>
Build-Depends:
debhelper (>= 11~),
pkg-config,
uuid-dev
Standards-Version: 4.2.0
Package: f2fs-tools
Architecture: linux-any
Depends: libf2fs5 (= ${binary:Version}), libf2fs-format4 (= ${binary:Version}), ${misc:Depends}, ${shlibs:Depends}
Description: Tools for Flash-Friendly File System
F2FS is a new filesystem for Linux aimed at NAND flash memory-based storage
devices, such as SSD, eMMC, and SD cards. It is based on Log-structured File
System (LFS).
#!/bin/sh
# TODO: re-export with;
# gpg --armor --export --export-options export-minimal,export-clean
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