pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/revbump



Module Name:    pkgsrc
Committed By:   wiz
Date:           Fri May 26 06:47:54 UTC 2023

Modified Files:
        pkgsrc/pkgtools/revbump: Makefile PLIST
Added Files:
        pkgsrc/pkgtools/revbump/files: revbump.py revbump.py.1

Log Message:
revbump: update to 3.0.

Rewrite as a single script in Python.

Leave Perl scripts in place for now.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 pkgsrc/pkgtools/revbump/Makefile
cvs rdiff -u -r1.4 -r1.5 pkgsrc/pkgtools/revbump/PLIST
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/revbump/files/revbump.py \
    pkgsrc/pkgtools/revbump/files/revbump.py.1

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

Modified files:

Index: pkgsrc/pkgtools/revbump/Makefile
diff -u pkgsrc/pkgtools/revbump/Makefile:1.49 pkgsrc/pkgtools/revbump/Makefile:1.50
--- pkgsrc/pkgtools/revbump/Makefile:1.49       Fri Nov 18 04:18:22 2022
+++ pkgsrc/pkgtools/revbump/Makefile    Fri May 26 06:47:54 2023
@@ -1,20 +1,26 @@
-# $NetBSD: Makefile,v 1.49 2022/11/18 04:18:22 gutteridge Exp $
+# $NetBSD: Makefile,v 1.50 2023/05/26 06:47:54 wiz Exp $
 
-PKGNAME=               revbump-2.17
+PKGNAME=               revbump-3.0
 CATEGORIES=            pkgtools
 
 MAINTAINER=            wiz%NetBSD.org@localhost
 HOMEPAGE=              https://www.pkgsrc.org/
-COMMENT=               Tools for bumping PKGREVISIONs (for pkgsrc developers)
-LICENSE=               modified-bsd
+COMMENT=               Tool for bumping PKGREVISIONs (for pkgsrc developers)
+LICENSE=               modified-bsd AND 2-clause-bsd
 
 WRKSRC=                ${WRKDIR}
-NO_CONFIGURE=  yes
 USE_TOOLS+=    perl:run
 USE_LANGUAGES= # empty
 
 INSTALLATION_DIRS=     bin ${PKGMANDIR}/man1
 
+REPLACE_PYTHON+=       revbump.py
+
+post-extract:
+       ${CP} ${FILESDIR}/revbump.py ${WRKSRC}
+
+do-configure:
+
 do-build:
 .for  i in  blbump finddepends revbump replace-commonbump check-cvs-diff
        ${SED} -e "s!@PERL@!${PERL5}!g" -e "s! make ! ${MAKE} !g" \
@@ -26,5 +32,8 @@ do-install:
        ${INSTALL_SCRIPT} ${WRKDIR}/${i} ${DESTDIR}${PREFIX}/bin
        ${INSTALL_MAN} ${FILESDIR}/${i}.1 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man1
 .endfor
+       ${INSTALL_SCRIPT} ${WRKDIR}/revbump.py ${DESTDIR}${PREFIX}/bin
+       ${INSTALL_MAN} ${FILESDIR}/revbump.py.1 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man1
 
+.include "../../lang/python/application.mk"
 .include "../../mk/bsd.pkg.mk"

Index: pkgsrc/pkgtools/revbump/PLIST
diff -u pkgsrc/pkgtools/revbump/PLIST:1.4 pkgsrc/pkgtools/revbump/PLIST:1.5
--- pkgsrc/pkgtools/revbump/PLIST:1.4   Mon Dec 15 23:25:54 2014
+++ pkgsrc/pkgtools/revbump/PLIST       Fri May 26 06:47:54 2023
@@ -1,11 +1,13 @@
-@comment $NetBSD: PLIST,v 1.4 2014/12/15 23:25:54 mef Exp $
+@comment $NetBSD: PLIST,v 1.5 2023/05/26 06:47:54 wiz Exp $
 bin/blbump
 bin/check-cvs-diff
 bin/finddepends
 bin/replace-commonbump
 bin/revbump
+bin/revbump.py
 man/man1/blbump.1
 man/man1/check-cvs-diff.1
 man/man1/finddepends.1
 man/man1/replace-commonbump.1
 man/man1/revbump.1
+man/man1/revbump.py.1

Added files:

Index: pkgsrc/pkgtools/revbump/files/revbump.py
diff -u /dev/null pkgsrc/pkgtools/revbump/files/revbump.py:1.1
--- /dev/null   Fri May 26 06:47:54 2023
+++ pkgsrc/pkgtools/revbump/files/revbump.py    Fri May 26 06:47:54 2023
@@ -0,0 +1,279 @@
+#!/usr/bin/env python3
+#
+# $NetBSD: revbump.py,v 1.1 2023/05/26 06:47:54 wiz Exp $
+#
+# Copyright (c) 2023 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Thomas Klausner.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+import argparse
+import glob
+import os
+import pathlib
+import re
+import subprocess
+import sys
+
+# only accept includes with ../../ or in the current directory
+bl3_include_re = re.compile(r'\s*\.\s*include\s+"(\.\./\.\./[^/]*/[^/]*/|)([^/]*)"')
+abi_depends_re = re.compile(r'^(BUILDLINK_ABI_DEPENDS.+=[ \t]+)')
+bldir_re = re.compile(r'^BUILDLINK_PKGSRCDIR(.*=[ \t]+)')
+pkgrevision_re = re.compile(r'PKGREVISION=([ \t]+)([0-9]+)$')
+pr_before_re = re.compile(r'(?:CATEGORIES=|\.\s*include)([ \t]+)')
+pr_after_re = re.compile(r'(?:PKGNAME=|COMMENT=)([ \t]+)')
+python_fix_re = re.compile(r'py[0-9]*-')
+ruby_fix_re = re.compile(r'ruby[0-9]*-')
+
+
+def bl3bump(path):
+    '''Update the ABI depends line in path/buildlink3.mk.'''
+    old_path = args.pkgsrcdir + '/' + path + '/buildlink3.mk'
+    if not pathlib.Path(old_path).exists():
+        print(f'{old_path} does not exist, skipped')
+        return
+    new_path = old_path + '.modified'
+
+    version_process = subprocess.run(['make', 'show-var', 'VARNAME=PKGNAME'],
+                                     capture_output=True,
+                                     check=True,
+                                     cwd=args.pkgsrcdir + '/' + path,
+                                     text=True)
+    version = version_process.stdout
+    last_dash = version.rfind('-')
+    version = version[:last_dash] + '>=' + version[last_dash+1:]
+    if python_fix_re.match(version):
+        version = re.sub(python_fix_re, '${PYPKGPREFIX}-', version)
+    if ruby_fix_re.match(version):
+        version = re.sub(ruby_fix_re, '${RUBY_PKGPREFIX}-', version)
+
+    output = []
+    with open(old_path, 'r', encoding='utf-8') as input_file:
+        done = False
+        for line in input_file.readlines():
+            if done:
+                output.append(line)
+            elif m := abi_depends_re.match(line):
+                new_line = m.group(1) + version
+                if line == new_line:
+                    # no effective change to file, avoid changing it
+                    return
+                output.append(new_line)
+                done = True
+            elif m := bldir_re.match(line):
+                output.append('BUILDLINK_ABI_DEPENDS' + m.group(1) + version)
+                output.append(line)
+                done = True
+            else:
+                output.append(line)
+
+    if not done:
+        print(f'{old_path}: failed to update BUILDLINK_ABI_DEPENDS to {version}, please handle manually')
+        return
+
+    with open(new_path, 'w', encoding='utf-8') as output_file:
+        for line in output:
+            output_file.write(line)
+    os.rename(new_path, old_path)
+
+
+def revbump(path):
+    '''Update PKGREVISION in path/Makefile.'''
+    old_path = args.pkgsrcdir + '/' + path + '/Makefile'
+    if not pathlib.Path(old_path).exists():
+        print(f'{old_path} does not exist, skipped')
+        return
+
+    new_path = old_path + '.modified'
+    output = []
+    with open(old_path, 'r', encoding='utf-8') as input_file:
+        done = False
+        for line in input_file.readlines():
+            if done:
+                output.append(line)
+            elif m := pkgrevision_re.match(line):
+                done = True
+                output.append('PKGREVISION=' + m.group(1)
+                              + str(int(m.group(2))+1) + '\n')
+            else:
+                output.append(line)
+    if not done:
+        output2 = []
+        # some heuristics where to add a PKGREVISION line
+        # mostly needed for packages that have a Makefile.common
+        for line in output:
+            if done:
+                output2.append(line)
+            elif m := pr_before_re.match(line):
+                output2.append('PKGREVISION=' + m.group(1) + '1\n')
+                output2.append(line)
+                done = True
+            elif m := pr_after_re.match(line):
+                output2.append(line)
+                output2.append('PKGREVISION=' + m.group(1) + '1\n')
+                done = True
+            else:
+                output2.append(line)
+        output = output2
+
+    if not done:
+        print(f'{old_path}: failed to update PKGREVISION, please handle manually')
+        return
+
+    with open(new_path, 'w', encoding='utf-8') as output_file:
+        for line in output:
+            output_file.write(line)
+    os.rename(new_path, old_path)
+
+
+def extract_includes(path):
+    '''Read the interesting parts of a Makefile (fragment).'''
+    file_content = []
+    relative = relative_path(path)
+    with open(path, 'r', encoding='utf-8') as f:
+        for entry in f.readlines():
+            if m := bl3_include_re.match(entry):
+                file_path = m.group(1)
+                file_name = m.group(2)
+                if file_path.find('/mk/') != -1:
+                    continue
+                if len(file_path) == 0:
+                    file_path = '../../' + relative[:relative.rfind('/')+1]
+                file_content.append(file_path[6:] + file_name)
+    return file_content
+
+
+def relative_path(full_path):
+    '''Strip pkgsrcdir from path.'''
+    return full_path[len(args.pkgsrcdir)+1:]
+
+
+parser = argparse.ArgumentParser(description='find all packages that' +
+                                 ' link against a given package')
+parser.add_argument('package', help='package for which we want to find' +
+                    ' its dependencies')
+parser.add_argument('-o', dest='output', default='commitlist',
+                    help='output file containing the directories with changes',
+                    action='store')
+parser.add_argument('-p', dest='pkgsrcdir', default='/usr/pkgsrc',
+                    help='path to the pkgsrc root directory', action='store')
+parser.add_argument('-w', dest='wip', default=False,
+                    help='include wip in search', action='store_true')
+args = parser.parse_args()
+
+if not pathlib.Path(args.pkgsrcdir).exists() or \
+   not pathlib.Path(args.pkgsrcdir + '/doc').exists() or \
+   not pathlib.Path(args.pkgsrcdir + '/mk').exists():
+    print(f'invalid pkgsrc directory "{args.pkgsrcdir}"')
+    sys.exit(1)
+
+initial_bl3 = args.package.rstrip('/') + '/buildlink3.mk'
+if not pathlib.Path(args.pkgsrcdir + '/' + initial_bl3).exists():
+    print(f'package {args.package} provides no buildlink3.mk file')
+    sys.exit(1)
+searchlist = [initial_bl3]
+
+bl3files = glob.glob(args.pkgsrcdir + '/*/*/buildlink3.mk')
+bl3files.append(args.pkgsrcdir + '/lang/ocaml/ocaml.mk')
+if not args.wip:
+    bl3files = filter(lambda name: name.find('/wip/') == -1, bl3files)
+# recursively find all buildlink3.mk files that directly or indirectly
+# include the target package's buildlink3.mk file
+bl3content = {}
+for file in bl3files:
+    includes = extract_includes(file)
+    if len(includes) > 0:
+        bl3content[file] = includes
+
+bl3result = []
+while len(searchlist) > 0:
+    newlist = []
+    for pattern in searchlist:
+        bl3result.append(pattern)
+        for key, value in dict(bl3content).items():
+            if pattern in value:
+                # remove entry so it is not found again
+                # via a different include path
+                del bl3content[key]
+                # skip 'pkgsrcdir/'
+                newlist.append(relative_path(key))
+    searchlist = newlist
+# not needed any longer
+bl3content.clear()
+
+makefiles = glob.glob(args.pkgsrcdir + '/*/*/Makefile*')
+makefiles.extend(glob.glob(args.pkgsrcdir + '/*/*/*.mk'))
+makefiles = list(filter(lambda name: name.find('/mk/') == -1
+                        and not name.endswith('buildlink3.mk')
+                        and not name.endswith('cargo-depends.mk')
+                        and not name.endswith('go-modules.mk'),
+                        makefiles))
+if not args.wip:
+    makefiles = list(filter(lambda name: name.find('/wip/') == -1, makefiles))
+
+makefile_content = {}
+for makefile in makefiles:
+    includes = extract_includes(makefile)
+    if len(includes) > 0:
+        makefile_content[makefile] = includes
+makefile_result = []
+for makefile in makefiles:
+    for pattern in bl3result:
+        if makefile in makefile_content \
+           and pattern in makefile_content[makefile]:
+            makefile_result.append(relative_path(makefile))
+            break
+
+# for non-plain Makefile, look if they are included from somewhere else
+possibly_included_files = list(filter(lambda name:
+                                      not name.endswith('/Makefile'),
+                                      makefile_result))
+while len(possibly_included_files) > 0:
+    newlist = []
+    for pattern in possibly_included_files:
+        for name, content in makefile_content.items():
+            if pattern in content:
+                makefile_result.append(relative_path(name))
+                if not name.endswith('/Makefile'):
+                    newlist.append(relative_path)
+    possibly_included_files = newlist
+# not needed any longer
+makefile_content.clear()
+
+# to be on the safe side, bump all p5-* Packages when perl is bumped
+if args.package == 'lang/perl5':
+    for file in glob.glob(args.pkgsrcdir + '/*/p5-*/Makefile'):
+        makefile_result.append(relative_path(file))
+
+
+directories = [path[:path.rfind('/')] for path in makefile_result + bl3result]
+directories = filter(lambda name: name != args.package, directories)
+with open(args.output, 'w', encoding='utf-8') as f:
+    for directory in sorted(set(directories)):
+        revbump(directory)
+        f.write(directory + '\n')
+for bl3file in sorted(set(bl3result)):
+    bl3bump(bl3file[:-len('/buildlink3.mk')])
Index: pkgsrc/pkgtools/revbump/files/revbump.py.1
diff -u /dev/null pkgsrc/pkgtools/revbump/files/revbump.py.1:1.1
--- /dev/null   Fri May 26 06:47:54 2023
+++ pkgsrc/pkgtools/revbump/files/revbump.py.1  Fri May 26 06:47:54 2023
@@ -0,0 +1,100 @@
+.\"    $NetBSD: revbump.py.1,v 1.1 2023/05/26 06:47:54 wiz Exp $
+.\"
+.\" Copyright (c) 2023 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Thomas Klausner.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd May 26, 2023
+.Dt REVBUMP.PY 1
+.Os
+.Sh NAME
+.Nm revbump.py
+.Nd tool to bump PKGREVISIONs automatically
+.Sh SYNOPSIS
+.Nm
+.Op Fl hw
+.Op Fl o Ar output
+.Op Fl p Ar pkgsrcdir
+.Ar category/package
+.Sh DESCRIPTION
+.Nm
+is a script for pkgsrc developers that bumps PKGREVISIONs
+automatically.
+.Pp
+.Nm
+will bump the PKGREVISION of all packages that include
+.Ar category/package Ap s
+.Pa buildlink3.mk
+recursively.
+.Nm
+will also increase the BUILDLINK_ABI_DEPENDS in
+.Ar category/package/buildlink3.mk
+and all the
+.Pa buildlink3.mk
+files that include this file.
+The list of changed directories is provided (see
+.Fl o )
+for the commit.
+.Pp
+.Nm
+supports the following options:
+.Bl -tag -width 12n -offset indent
+.It Fl h
+Show the usage.
+.It Fl o Ar output
+Write the list of changed package directories (relative to the
+.Pa pkgsrc
+directory) to
+.Ar output .
+Defaults to
+.Dq Pa commitlist .
+.It Fl p Ar pkgsrcdir
+Use
+.Ar pkgsrcdir
+as root of the pkgsrc tree.
+Defaults to
+.Pa /usr/pkgsrc .
+.It Fl w
+Also bump packages in the
+.Pa wip/
+subtree.
+.El
+.Sh EXAMPLES
+.Dl revbump.py devel/glib2
+.Pp
+will bump the PKGREVISIONs of glib2.
+.Ed
+.Pp
+The complete procedure for a recursive dependency bump for
+category/package looks like this:
+.Bd -literal -offset indent
+revbump.py category/package
+# check for problems
+cvs diff $(cat commitlist) | less
+# if the diff is ok
+cvs commit $(cat commitlist)
+rm commitlist
+.Ed



Home | Main Index | Thread Index | Old Index