Here is a patch removing one more item from gnulib-tool.py.TODO. Here
is a test and diff before applying this patch:

gnulib-tool.py --create-testdir --dir test-python dummy
gnulib-tool --create-testdir --dir test-shell dummy
git diff --no-index test-python test-shell

diff --git a/test-python/build-aux/test-driver 
b/test-shell/build-aux/test-driver
index be73b80adf..8b6ec6c4f8 100755
--- a/test-python/build-aux/test-driver
+++ b/test-shell/build-aux/test-driver
@@ -109,7 +109,10 @@ trap "st=143; $do_exit" 15
 # to ameliorate tests themselves also writing to the log file. Our tests
 # don't, but others can (automake bug#35762).
 : >"$log_file"
-"$@" >>"$log_file" 2>&1
+case "$1" in
+  *.sh) sh "$@" >>"$log_file" 2>&1 ;;
+  *)    "$@" >>"$log_file" 2>&1 ;;
+esac

These lines are fixed by this patch on my updated GNU/Linux machine. I
saw another TODO item referencing a separate patch needed for
test-driver distributed with a specific version of Automake. I'll get
around that one in a bit, but I figured I'd mention it in case this
test fails due to that issue.

Also, mostly a note for myself, I noticed a nice readability change
that is probably worth making in the future once gnulib-tool.py is
functionally working. It seems that Python added enums after
gnulib-tool.py was originally written [1]. It would be pretty simple
to add these to GLError.py.

I think that something like

    raise GLError(GLErrno.PATCH_FAILED, 'message')

would be more readable than

    raise GLError(20, 'message')

Sort of like errno.h but without the portability issues. :)

[1] https://docs.python.org/3/library/enum.html

Collin
From 97bcb4b8b358f35a38b4488d1981ad1ea931648a Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Fri, 8 Mar 2024 20:59:16 -0800
Subject: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 48.

Follow gnulib-tool change
2019-01-23  Bruno Haible  <br...@clisp.org>
gnulib-tool: Support running testdirs on Android.

* pygnulib/GLError.py (GLError.__init__, GLError.__repr__): Add errno 20
to print an error if patching build-aux/test-driver fails.
* pygnulib/main.py (main): Likewise.
* pygnulib/GLTestDir.py (_patch_test_driver): New private function which
runs patch on build-aux/test-driver with build-aux/test-driver.diff.
(GLTestDir.execute, GLMegaTestDir.execute): Check for
build-aux/test-driver in each testdir and patch it after running
automake.
---
 ChangeLog             | 15 +++++++++++++++
 gnulib-tool.py.TODO   | 12 ------------
 pygnulib/GLError.py   |  3 +++
 pygnulib/GLTestDir.py | 19 +++++++++++++++++++
 pygnulib/main.py      |  2 ++
 5 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 042fd868eb..e46c53a176 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-03-08  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Follow gnulib-tool changes, part 48.
+	Follow gnulib-tool change
+	2019-01-23  Bruno Haible  <br...@clisp.org>
+	gnulib-tool: Support running testdirs on Android.
+	* pygnulib/GLError.py (GLError.__init__, GLError.__repr__): Add errno 20
+	to print an error if patching build-aux/test-driver fails.
+	* pygnulib/main.py (main): Likewise.
+	* pygnulib/GLTestDir.py (_patch_test_driver): New private function which
+	runs patch on build-aux/test-driver with build-aux/test-driver.diff.
+	(GLTestDir.execute, GLMegaTestDir.execute): Check for
+	build-aux/test-driver in each testdir and patch it after running
+	automake.
+
 2024-03-08  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool: Don't remove comments referencing @NMD@.
diff --git a/gnulib-tool.py.TODO b/gnulib-tool.py.TODO
index 8918d58a88..7632991780 100644
--- a/gnulib-tool.py.TODO
+++ b/gnulib-tool.py.TODO
@@ -431,18 +431,6 @@ Date:   Mon Nov 18 13:32:46 2019 +0100
 
 --------------------------------------------------------------------------------
 
-commit 425ee42259b04956aae20afc5204775ae6e79744
-Author: Bruno Haible <br...@clisp.org>
-Date:   Wed Jan 23 05:11:54 2019 +0100
-
-    gnulib-tool: Support running testdirs on Android.
-
-    * build-aux/test-driver.diff: New file.
-    * gnulib-tool (func_create_testdir, func_create_megatestdir): Patch
-    build-aux/test-driver after running automake.
-
---------------------------------------------------------------------------------
-
 commit ce8a5edbc49dea0cb859207c2d063dbd3be0f96c
 Author: Bruno Haible <br...@clisp.org>
 Date:   Fri Jan 4 19:34:19 2019 +0100
diff --git a/pygnulib/GLError.py b/pygnulib/GLError.py
index 5c7420e8b1..0fd1fcf3a1 100644
--- a/pygnulib/GLError.py
+++ b/pygnulib/GLError.py
@@ -61,6 +61,7 @@ class GLError(Exception):
          17: cannot update the given file: <file>
          18: module lacks a license: <module>
          19: could not create destination directory: <directory>
+         20: could not patch test-driver script
         errinfo: additional information'''
         self.errno = errno
         self.errinfo = errinfo
@@ -109,5 +110,7 @@ class GLError(Exception):
                 message = "module lacks a license: %s" % repr(errinfo)
             elif errno == 19:
                 message = "error when running subprocess: %s" % repr(errinfo)
+            elif errno == 20:
+                message = 'could not patch test-driver script'
             self.message = '[Errno %d] %s' % (errno, message)
         return self.message
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index 8a3072ea09..5a4c38f049 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -57,6 +57,19 @@ isfile = os.path.isfile
 normpath = os.path.normpath
 
 
+def _patch_test_driver() -> None:
+    '''Patch the test-driver script in testdirs.'''
+    test_driver = joinpath('build-aux', 'test-driver')
+    diff = joinpath(DIRS['root'], joinpath('build-aux', 'test-driver.diff'))
+    command = f'patch {test_driver} < {diff}'
+    try:
+        result = sp.call(command, shell=True)
+        if result != 0:
+            raise GLError(20, None)
+    except OSError:
+        raise GLError(20, None)
+
+
 #===============================================================================
 # Define GLTestDir class
 #===============================================================================
@@ -841,6 +854,10 @@ class GLTestDir(object):
                     'LIBTOOLIZE=%s' % UTILS['libtoolize'],
                     'distclean']
             sp.call(args)
+        os.chdir(self.testdir)
+        if isfile(joinpath('build-aux', 'test-driver')):
+            _patch_test_driver()
+        os.chdir(DIRS['cwd'])
         sp.call(['rm', '-rf', self.config['tempdir']], shell=False)
 
 
@@ -999,5 +1016,7 @@ class GLMegaTestDir(object):
         args = [UTILS['automake'], '--add-missing', '--copy']
         constants.execute(args, verbose)
         shutil.rmtree('autom4te.cache')
+        if isfile(joinpath('build-aux', 'test-driver')):
+            _patch_test_driver()
         os.chdir(DIRS['cwd'])
         sp.call(['rm', '-rf', self.config['tempdir']], shell=False)
diff --git a/pygnulib/main.py b/pygnulib/main.py
index a76de2ffe0..58d4cd268e 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -1272,6 +1272,8 @@ if __name__ == '__main__':
                 message += 'module %s lacks a license' % errinfo
             elif errno == 19:
                 message += 'could not create destination directory: %s' % errinfo
+            elif errno == 20:
+                message += 'could not patch test-driver script'
             message += '\n%s: *** Stop.\n' % constants.APP['name']
             sys.stderr.write(message)
             sys.exit(1)
-- 
2.44.0

Reply via email to