When running ./autogen.sh in gettext gnulib-tool.py fails on the first
invocation. :(

The command is something like this:

    $GNULIB_TOOL --dir=gettext-runtime ...

We get the following error message:

Traceback (most recent call last):
  File "/home/collin/.local/src/gnulib/.gnulib-tool.py", line 30, in <module>
    main.main_with_exception_handling()
  File "/home/collin/.local/src/gnulib/pygnulib/main.py", line 1382, in 
main_with_exception_handling
    main()
  File "/home/collin/.local/src/gnulib/pygnulib/main.py", line 953, in main
    importer = GLImport(config, mode)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/collin/.local/src/gnulib/pygnulib/GLImport.py", line 94, in 
__init__
    with codecs.open(self.config.getAutoconfFile(), 'rb', 'UTF-8') as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen codecs>", line 918, in open
FileNotFoundError: [Errno 2] No such file or directory: 
'gettext-runtime/gettext-runtime/configure.ac'

When moving the configure.{ac,in} checks to main I only had tests
with an implicit --dir='.'. This behavior is not visible in that case.

In main we have joinpath(destdir, 'configure.ac') which is then passed
to GLConfig.setAutoconfFile which has
os.path.join(self.table['destdir'], configure_ac).

The the implicit --dir='.' case:

    configure_ac = joinpath('.', 'configure.ac')
    # configure_ac == 'configure.ac'
    configure_ac = os.path.join('.', configure_ac)
    # configure_ac == './configure.ac'
    # Wrong process, correct answer.

in the --dir='gettext-runtime' case:

    configure_ac = joinpath('gettext-runtime', 'configure.ac')
    # configure_ac == 'gettext-runtime/configure.ac'
    os.path.join('gettext-runtime', configure_ac)
    # configure_ac == 'gettext-runtime/gettext-runtime/configure.ac'
    # Wrong process, wrong answer.

Since GLConfig.setAutoconfFile() is only used in main we can just have
it accept the argument as it is given. This patch fixes that.

The joinpath() and os.path.join() distinction is important for the
test suite. 'configure.ac' vs './configure.ac' will cause some test
failures. I've left a comment so it doesn't get changed.

Collin
From 2f36ea7789d35e4db82a1ad44c3e037e61e9052e Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sat, 6 Apr 2024 04:41:03 -0700
Subject: [PATCH] gnulib-tool.py: Locate configure.ac correctly when --dir is
 given.

* pygnulib/GLConfig.py (GLConfig.setAutoconfFile): Don't combine the
given file name argument with destdir.
* pygnulib/main.py (main): Use os.path.join() instead of joinpath() when
constructing the path to the configure.ac file. The latter normalizes
paths which causes the test suite to fail when printed in files.
---
 ChangeLog            |  9 +++++++++
 pygnulib/GLConfig.py |  3 +--
 pygnulib/main.py     | 12 +++++++-----
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9d069b83e2..feed5699f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-04-06  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Locate configure.ac correctly when --dir is given.
+	* pygnulib/GLConfig.py (GLConfig.setAutoconfFile): Don't combine the
+	given file name argument with destdir.
+	* pygnulib/main.py (main): Use os.path.join() instead of joinpath() when
+	constructing the path to the configure.ac file. The latter normalizes
+	paths which causes the test suite to fail when printed in files.
+
 2024-04-06  Bruno Haible  <br...@clisp.org>
 
 	expm1l: Work around a NetBSD 10.0/i386 bug.
diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py
index 1c9caa218b..f5282dbf53 100644
--- a/pygnulib/GLConfig.py
+++ b/pygnulib/GLConfig.py
@@ -1025,8 +1025,7 @@ class GLConfig:
         '''Specify path of autoconf file relative to destdir.'''
         if type(configure_ac) is str:
             if configure_ac:
-                self.table['configure_ac'] = \
-                    os.path.join(self.table['destdir'], configure_ac)
+                self.table['configure_ac'] = configure_ac
         else:  # if type of configure_ac is not str
             raise TypeError('configure_ac must be a string, not %s'
                             % type(configure_ac).__name__)
diff --git a/pygnulib/main.py b/pygnulib/main.py
index 4bf4da4279..a67252f7f6 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -910,12 +910,14 @@ def main() -> None:
         config.setDestDir(destdir)
 
         # Prefer configure.ac but also look for configure.in.
-        if isfile(joinpath(destdir, 'configure.ac')):
-            configure_ac = joinpath(destdir, 'configure.ac')
-        elif isfile(joinpath(destdir, 'configure.in')):
-            configure_ac = joinpath(destdir, 'configure.in')
+        # NOTE: Use os.path.join so the leading './' is not removed. This
+        # is to make the gnulib-tool test suite happy.
+        if isfile(os.path.join(destdir, 'configure.ac')):
+            configure_ac = os.path.join(destdir, 'configure.ac')
+        elif isfile(os.path.join(destdir, 'configure.in')):
+            configure_ac = os.path.join(destdir, 'configure.in')
         else:
-            raise GLError(3, joinpath(destdir, 'configure.ac'))
+            raise GLError(3, os.path.join(destdir, 'configure.ac'))
 
         # Save the Autoconf file path for the rest of the import.
         config.setAutoconfFile(configure_ac)
-- 
2.44.0

Reply via email to