pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/url2pkg/files



Module Name:    pkgsrc
Committed By:   rillig
Date:           Thu Oct  3 16:32:47 UTC 2019

Modified Files:
        pkgsrc/pkgtools/url2pkg/files: setuptools.py url2pkg.py url2pkg_test.py

Log Message:
pkgtools/url2pkg: add BUILDLINK_API_DEPENDS and BUILDLINK_DEPENDS


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 pkgsrc/pkgtools/url2pkg/files/setuptools.py \
    pkgsrc/pkgtools/url2pkg/files/url2pkg.py
cvs rdiff -u -r1.2 -r1.3 pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/url2pkg/files/setuptools.py
diff -u pkgsrc/pkgtools/url2pkg/files/setuptools.py:1.3 pkgsrc/pkgtools/url2pkg/files/setuptools.py:1.4
--- pkgsrc/pkgtools/url2pkg/files/setuptools.py:1.3     Tue Oct  1 19:41:23 2019
+++ pkgsrc/pkgtools/url2pkg/files/setuptools.py Thu Oct  3 16:32:47 2019
@@ -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 @@ url2pkg_license_mapping = {
     '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 @@ def url2pkg_print_license(license):
     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 @@ def setup(**kwargs):
     # 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 []
Index: pkgsrc/pkgtools/url2pkg/files/url2pkg.py
diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.3 pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.4
--- pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.3        Thu Oct  3 14:48:48 2019
+++ pkgsrc/pkgtools/url2pkg/files/url2pkg.py    Thu Oct  3 16:32:47 2019
@@ -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 @@ def run_editor(fname: str, lineno: int):
         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 @@ def generate_initial_package_Makefile_li
     master_sites = ''
     distfile = ''
     homepage = ''
-    extract_sufx = ''
-    categories = ''
+    extract_sufx: str
+    categories: str
     github_project = ''
     github_release = ''
     dist_subdir = ''
@@ -364,7 +364,6 @@ class Lines:
         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 @@ class Adjuster:
 
     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') \

Index: pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py
diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.2 pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.3
--- pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.2   Thu Oct  3 12:52:54 2019
+++ pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py       Thu Oct  3 16:32:47 2019
@@ -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 @@ def test_Lines_append__value_without_com
     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_generate_initial_package_Makefi
 
 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 @@ def test_Adjuster_read_dependencies():
     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_generate_adjusted_Make
     ]
 
 
+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