diff options
author | Andrej Shadura <andrew.shadura@collabora.co.uk> | 2018-12-20 19:51:14 +0100 |
---|---|---|
committer | Andrej Shadura <andrew.shadura@collabora.co.uk> | 2018-12-20 19:51:14 +0100 |
commit | 91df6076a64c25b1ad8fea69a395ea7529f9588a (patch) | |
tree | 599347ff66d8fbf2637eff18d8cc9c8879723c70 | |
parent | 1fca37264e7b02416dc36490bad4ee0f09ef13f3 (diff) |
Generate Built-Using at the build time
Closes: #831271
-rw-r--r-- | debian/control | 39 | ||||
-rwxr-xr-x | debian/genbuildusing.py | 84 | ||||
-rwxr-xr-x | debian/rules | 1 |
3 files changed, 106 insertions, 18 deletions
diff --git a/debian/control b/debian/control index f1ba060..8ce9f4c 100644 --- a/debian/control +++ b/debian/control @@ -19,6 +19,7 @@ Build-Depends: debhelper (>= 11), python3-certifi, python3-chardet, python3-colorama, + python3-debian, python3-distlib, python3-distro, python3-html5lib, @@ -80,24 +81,26 @@ Package: python-pip-whl Architecture: all Depends: ca-certificates, ${misc:Depends}, -Built-Using: chardet (= 2.3.0-2), - distlib (= 0.2.4-1), - html5lib (= 0.999999999-1), - pyparsing (= 2.1.10+dfsg1-1), - appdirs (= 1.4.0-2), - python-cachecontrol (= 0.11.7-1), - python-colorama (= 0.3.7-1), - python-distro (= 1.0.1-1), - python-ipaddress (= 1.0.17-1), - python-lockfile (= 1:0.12.2-2), - python-packaging (= 16.7-2), - python-progress (= 1.2-1), - python-retrying (= 1.3.3-1), - python-setuptools (= 32.3.1-1), - python-urllib3 (= 1.16-1), - python-webencodings (= 0.5-1), - requests (= 2.11.1-1), - six (= 1.10.0-3), +Built-Using: ${pip:Built-Using} +X-Built-Using: + chardet, + distlib, + html5lib, + pyparsing, + appdirs, + python-cachecontrol, + python-colorama, + python-distro, + python-ipaddress, + python-lockfile, + python-packaging, + python-progress, + python-retrying, + python-setuptools, + python-urllib3, + python-webencodings, + requests, + six, Breaks: python-chardet-whl (<< 2.3.0-2), python-colorama-whl (<< 0.3.6-1), python-distlib-whl (<< 0.2.2-1), diff --git a/debian/genbuildusing.py b/debian/genbuildusing.py new file mode 100755 index 0000000..a082b58 --- /dev/null +++ b/debian/genbuildusing.py @@ -0,0 +1,84 @@ +#!/usr/bin/python3 +import os +import sys +import gzip +from debian.deb822 import Deb822, PkgRelation, _PkgRelationMixin +from debian.changelog import Changelog + +class Control(Deb822, _PkgRelationMixin): + """ + This class automatically parses relationship fields. + """ + _relationship_fields = [ + 'build-depends', + 'x-built-using', + 'built-using', + 'depends', + 'pre-depends', + 'recommends', + 'suggests', + 'breaks', + 'conflicts', + 'provides', + 'replaces', + 'enhances', + ] + + def __init__(self, *args, **kwargs): + # type: (*Any, **Any) -> None + Deb822.__init__(self, *args, **kwargs) + _PkgRelationMixin.__init__(self, *args, **kwargs) + +source_pkg = None +wheel_pkg = None + +# We cannot put unversioned source package names in Built-Using +# since dpkg-gencontrol doesn’t allow overriding them with +# versioned package names (unlike in, say, Depends), making +# that non-trivial to substitute. +# +# Instead, we put them into X-Built-Using, which also prevents +# them from leaking into the binary package’s control file. + +for pkg in Control.iter_paragraphs(open('debian/control')): + if 'Source' in pkg: + source_pkg = pkg + if 'X-Built-Using' in pkg: + wheel_pkg = pkg + +if not source_pkg and not wheel_pkg: + print('no source packages or packages with Built-Using found', file=sys.stderr) + exit(1) + +if len(sys.argv) < 2: + print('substvars file required', file=sys.stderr) + exit(1) + +substvars_file = sys.argv[1] + +def nowarn(*args): + pass + +# To prevent the parser from complaining about substitutions +import warnings +warnings.warn = nowarn + +# if len(...) is needed to allow the trailing comma +# this doesn’t allow alternative built-dependencies +build_depends = [x[0]['name'] for x in source_pkg.relations['build-depends'] if len(x[0]['name'])] +# this also filters out substitutions — no longer needed since we need X-Built-Using anyway :( +built_using = [x[0]['name'] for x in wheel_pkg.relations['x-built-using'] if not x[0]['name'].startswith('${')] + +def get_source_and_version(pkg): + # try non-native location first + changelog_path = os.path.join('/usr/share/doc', pkg, 'changelog.Debian.gz') + if not os.path.exists(changelog_path): + changelog_path = os.path.join('/usr/share/doc', pkg, 'changelog.gz') + changelog = Changelog(file=gzip.open(changelog_path, 'rb')) + return changelog.get_package(), changelog.get_version() + +build_depends_sources = [get_source_and_version(x) for x in build_depends] + +built_using_versions = [[{'name': pkg, 'version': ('=', str(ver))}] for (pkg, ver) in build_depends_sources if pkg in built_using] + +print('pip:Built-Using=%s' % PkgRelation.str(built_using_versions), file=open(substvars_file, 'a')) diff --git a/debian/rules b/debian/rules index 512996d..ae5e15d 100755 --- a/debian/rules +++ b/debian/rules @@ -71,6 +71,7 @@ override_dh_auto_install: python3 setup.py bdist_wheel \ --universal \ -d $(CURDIR)/debian/python-pip-whl/usr/share/python-wheels + debian/genbuildusing.py debian/python-pip-whl.substvars override_dh_installchangelogs: dh_installchangelogs NEWS.rst |