]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
UBUNTU: [Packaging] Rewrite debian/scripts/misc/insert-changes.pl in Python
authorJuerg Haefliger <juerg.haefliger@canonical.com>
Wed, 3 Nov 2021 16:59:22 +0000 (17:59 +0100)
committerAndrea Righi <andrea.righi@canonical.com>
Tue, 7 Dec 2021 06:32:20 +0000 (07:32 +0100)
Rewrite the insert-changes.pl script in Python to get us one step closer
to dropping Perl as an Ubuntu kernel build dependency.

Signed-off-by: Juerg Haefliger <juergh@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
debian/rules.d/1-maintainer.mk
debian/scripts/misc/insert-changes [new file with mode: 0755]
debian/scripts/misc/insert-changes.pl [deleted file]

index 7c13fcdaa98a1d36559c8d8952744113f662dc13..5917b89bbd4992c031be88388335909251e1dfea 100644 (file)
@@ -113,7 +113,7 @@ printchanges:
        $(DROOT)/scripts/misc/git-ubuntu-log $(ubuntu_log_opts)
 
 insertchanges: autoreconstruct finalchecks
-       @perl -w -f $(DROOT)/scripts/misc/insert-changes.pl $(DROOT) $(DEBIAN) 
+       $(DROOT)/scripts/misc/insert-changes $(DROOT) $(DEBIAN)
 
 autoreconstruct:
        # No need for reconstruct for -rc kernels since we don't upload an
diff --git a/debian/scripts/misc/insert-changes b/debian/scripts/misc/insert-changes
new file mode 100755 (executable)
index 0000000..e21aaa4
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/python3
+
+import os
+import sys
+
+from subprocess import check_output
+
+droot = 'debian'
+if len(sys.argv) > 1:
+    droot = sys.argv[1]
+
+debian = 'debian.master'
+if len(sys.argv) > 2:
+    debian = sys.argv[2]
+
+rules = os.path.join(droot, 'rules')
+changelog = os.path.join(debian, 'changelog')
+changelog_new = os.path.join(debian, 'changelog.new')
+
+# Generate the list of new changes
+changes = check_output(['make', '-s', '-f', rules, 'printchanges']).decode('UTF-8')
+
+# Insert the new changes into the changelog
+with open(changelog) as orig, open(changelog_new, 'w') as new:
+    printed = False
+    skip_newline = False
+    for line in orig:
+        if line.startswith('  CHANGELOG: '):
+            if not printed:
+                printed = True
+                if changes == '':
+                    skip_newline = True
+                    continue
+                new.write(changes)
+        else:
+            if skip_newline and line.strip() == '':
+                skip_newline = False
+                continue
+            new.write(line)
+
+# Replace the original changelog with the new one
+os.rename(changelog_new, changelog)
diff --git a/debian/scripts/misc/insert-changes.pl b/debian/scripts/misc/insert-changes.pl
deleted file mode 100755 (executable)
index 4eed4e2..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/perl -w
-
-my $debian;
-$droot = $ARGV[0] if (defined $ARGV[0]);
-$droot = 'debian' if (!defined $droot);
-$debian = $ARGV[1] if (defined $ARGV[1]);
-$debian = 'debian.master' if (!defined $debian);
-
-system("make -s -f $droot/rules printchanges > $debian/changes");
-
-open(CHANGELOG, "< $debian/changelog") or die "Cannot open changelog";
-open(CHANGES, "< $debian/changes") or die "Cannot open new changes";
-open(NEW, "> $debian/changelog.new") or die "Cannot open new changelog";
-
-$printed = 0;
-my $skip_newline = 0;
-
-while (<CHANGELOG>) {
-       if (/^  CHANGELOG: /) {
-               next if $printed;
-
-               $skip_newline = 1;
-               while (<CHANGES>) {
-                       $skip_newline = 0;
-                       print NEW;
-               }
-
-               $printed = 1;
-       } else {
-               if (/^$/ && $skip_newline == 1) {
-                       $skip_newline = 0;
-                       next;
-               }
-               print NEW;
-       }
-}
-
-close(NEW);
-close(CHANGES);
-close(CHANGELOG);
-
-rename("$debian/changelog.new", "$debian/changelog");
-unlink("$debian/changes");