pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/url2pkg/files pkgtools/url2pkg: add BUILDLINK...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/715d6546bad4
branches:  trunk
changeset: 340488:715d6546bad4
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Oct 03 16:32:47 2019 +0000

description:
pkgtools/url2pkg: add BUILDLINK_API_DEPENDS and BUILDLINK_DEPENDS

diffstat:

 pkgtools/url2pkg/files/setuptools.py   |  11 ++++++++---
 pkgtools/url2pkg/files/url2pkg.py      |  34 ++++++++++++++++++++++++----------
 pkgtools/url2pkg/files/url2pkg_test.py |  32 ++++++++++++++++++++++++++++----
 3 files changed, 60 insertions(+), 17 deletions(-)

diffs (192 lines):

diff -r fd32b96042bc -r 715d6546bad4 pkgtools/url2pkg/files/setuptools.py
--- a/pkgtools/url2pkg/files/setuptools.py      Thu Oct 03 15:53:39 2019 +0000
+++ b/pkgtools/url2pkg/files/setuptools.py      Thu Oct 03 16:32:47 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: setuptools.py,v 1.3 2019/10/01 19:41:23 rillig Exp $
+# $NetBSD: setuptools.py,v 1.4 2019/10/03 16:32:47 rillig Exp $
 
 # This is a drop-in replacement for the setuptools Python module. Instead
 # of actually searching for the dependencies, it extracts the dependency
@@ -7,8 +7,8 @@
 url2pkg_license_mapping = {
     'Apache 2': 'apache-2.0',
     'Apache 2.0': 'apache-2.0',
-    'Apache Software License': '', # too unspecific; needs a version number
-    'BSD': '', # too unspecific
+    'Apache Software License': '',  # too unspecific; needs a version number
+    'BSD': '',  # too unspecific
     'GNU Lesser General Public License (LGPL), Version 3': 'gnu-lgpl-v3',
     'LGPL': 'gnu-lgpl-v2',
     'MIT': 'mit',
@@ -19,14 +19,17 @@
     'ZPL 2.1': 'zpl-2.1',
 }
 
+
 def url2pkg_print_depends(keyword, depends):
     for dep in depends:
         print('%s\t%s%s' % (keyword, dep.replace(' ', ''), '' if '>' in dep else '>=0'))
 
+
 def url2pkg_print_var(varname, value):
     if value != '':
         print('var\t%s\t%s' % (varname, value))
 
+
 def url2pkg_print_license(license):
     if license == '':
         return
@@ -36,6 +39,7 @@
     else:
         url2pkg_print_var('LICENSE', pkgsrc_license)
 
+
 def setup(**kwargs):
     url2pkg_print_depends('DEPENDS', kwargs.get('install_requires', []))
     url2pkg_print_depends('TEST_DEPENDS', kwargs.get('tests_require', []))
@@ -48,5 +52,6 @@
     # TODO: python_requires (see devel/py-futures)
     #       example: '>=2.6, <3, >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*')
 
+
 def find_packages(where='.', exclude=(), include=('*',)):
     return []
diff -r fd32b96042bc -r 715d6546bad4 pkgtools/url2pkg/files/url2pkg.py
--- a/pkgtools/url2pkg/files/url2pkg.py Thu Oct 03 15:53:39 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.py Thu Oct 03 16:32:47 2019 +0000
@@ -1,5 +1,5 @@
 #! @PYTHONBIN@
-# $NetBSD: url2pkg.py,v 1.3 2019/10/03 14:48:48 rillig Exp $
+# $NetBSD: url2pkg.py,v 1.4 2019/10/03 16:32:47 rillig Exp $
 
 # Copyright (c) 2019 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -72,7 +72,7 @@
         args.append(f'+{lineno}')
     args.append(fname)
 
-    code = subprocess.check_call(args)
+    subprocess.check_call(args)
 
 
 def generate_initial_package_Makefile_lines(url):
@@ -82,8 +82,8 @@
     master_sites = ''
     distfile = ''
     homepage = ''
-    extract_sufx = ''
-    categories = ''
+    extract_sufx: str
+    categories: str
     github_project = ''
     github_release = ''
     dist_subdir = ''
@@ -364,7 +364,6 @@
         if value == '':
             return
         varassign = self.unique_varassign(varname)
-        # TODO: add a test for multiple assignments
         if varassign is not None:
             before = ' ' if re.search(r'\S$', varassign.value) else ''
             after = '' if varassign.comment == '' else ' '
@@ -478,11 +477,26 @@
 
     def add_dependency(self, kind: str, pkgbase: str, constraint: str, dep_dir: str) -> None:
         """ add_dependency('DEPENDS', 'package', '>=1', '../../category/package') """
-        if dep_dir != '' and isfile(dep_dir + '/buildlink3.mk'):
-            # TODO: add kind to bl3_lines (BUILDLINK_DEPENDS)
-            # TODO: add constraint to bl3_lines (BUILDLINK_API_DEPENDS)
-            self.bl3_lines.append('.include "%s/buildlink3.mk"' % dep_dir)
-            return
+
+        def bl3_identifier():
+            try:
+                with open(dep_dir + '/buildlink3.mk') as f:
+                    for line in f:
+                        m = re.search(r'^BUILDLINK_TREE\+=\s*(\S+)$', line)
+                        if m:
+                            return m[1]
+            except OSError:
+                pass
+            return ''
+
+        if dep_dir != '':
+            pkgid = bl3_identifier()
+            if pkgid != '':
+                if kind == 'BUILD_DEPENDS':
+                    self.bl3_lines.append(f'BUILDLINK_DEPENDS.{pkgid}+=\tbuild')
+                self.bl3_lines.append(f'BUILDLINK_API_DEPENDS.{pkgid}+=\t{pkgid}{constraint}')
+                self.bl3_lines.append(f'.include "{dep_dir}/buildlink3.mk"')
+                return
 
         value = pkgbase + constraint + ':' + dep_dir \
             if dep_dir != '' and isfile(dep_dir + '/Makefile') \
diff -r fd32b96042bc -r 715d6546bad4 pkgtools/url2pkg/files/url2pkg_test.py
--- a/pkgtools/url2pkg/files/url2pkg_test.py    Thu Oct 03 15:53:39 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg_test.py    Thu Oct 03 16:32:47 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: url2pkg_test.py,v 1.2 2019/10/03 12:52:54 rillig Exp $
+# $NetBSD: url2pkg_test.py,v 1.3 2019/10/03 16:32:47 rillig Exp $
 
 from url2pkg import *
 
@@ -126,6 +126,14 @@
     assert lines.lines == ["VARNAME+=\tvalue appended"]
 
 
+def test_Lines_append__multiple_assignments():
+    lines = Lines("VARNAME+=\tvalue1", "VARNAME+=\tvalue2")
+
+    assert not lines.append("VARNAME", "appended")
+
+    assert lines.lines == ["VARNAME+=\tvalue1", "VARNAME+=\tvalue2"]
+
+
 def test_Lines_set__previously_with_comment():
     lines = Lines("LICENSE=\t# TODO: see mk/license.mk")
 
@@ -351,8 +359,8 @@
 
 def test_Adjuster_read_dependencies():
     dep_lines = [
-        "DEPENDS\tpackage>=version:../../pkgtools/pkglint",
-        "DEPENDS\tpackage>=version:../../pkgtools/x11-links",
+        "DEPENDS\tpackage>=80.0:../../pkgtools/pkglint",
+        "DEPENDS\tpackage>=120.0:../../pkgtools/x11-links",
         "BUILD_DEPENDS\turl2pkg>=1.0",
         "TEST_DEPENDS\tpkglint",
         "A line that is not a dependency at all",
@@ -369,9 +377,10 @@
     assert os.getenv('URL2PKG_DEPENDENCIES') is None
 
     assert adjuster.depends == [
-        "package>=version:../../pkgtools/pkglint"
+        "package>=80.0:../../pkgtools/pkglint"
     ]
     assert adjuster.bl3_lines == [
+        'BUILDLINK_API_DEPENDS.x11-links+=\tx11-links>=120.0',
         ".include \"../../pkgtools/x11-links/buildlink3.mk\""
     ]
     assert adjuster.build_depends == [
@@ -442,6 +451,21 @@
     ]
 
 
+def test_Adjuster_add_dependency__buildlink():
+    adjuster = Adjuster()
+    adjuster.makefile_lines.add('# url2pkg-marker')
+
+    adjuster.add_dependency('BUILD_DEPENDS', 'libusb', '>=2019', '../../devel/libusb')
+
+    lines = adjuster.generate_adjusted_Makefile_lines('https://example.org/distfile-1.0.zip')
+
+    assert lines.lines == [
+        'BUILDLINK_DEPENDS.libusb+=\tbuild',
+        'BUILDLINK_API_DEPENDS.libusb+=\tlibusb>=2019',
+        '.include "../../devel/libusb/buildlink3.mk"',
+    ]
+
+
 def test_Adjuster_adjust_configure__not_found(tmp_path):
     adjuster = Adjuster()
     adjuster.abs_wrksrc = str(tmp_path)



Home | Main Index | Thread Index | Old Index