bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Collin Funk <collin.funk1@gmail.com>
To: bug-gnulib@gnu.org
Subject: gnulib-tool.py: Locate configure.ac correctly when --dir is given.
Date: Sat, 6 Apr 2024 05:12:25 -0700	[thread overview]
Message-ID: <94d1a30c-fec8-4b1f-83c0-a4b45587a7e0@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2185 bytes --]

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

[-- Attachment #2: 0001-gnulib-tool.py-Locate-configure.ac-correctly-when-di.patch --]
[-- Type: text/x-patch, Size: 3229 bytes --]

From 2f36ea7789d35e4db82a1ad44c3e037e61e9052e Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@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.funk1@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  <bruno@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	other threads:[~2024-04-06 12:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-06 12:12 Collin Funk [this message]
2024-04-07 11:16 ` gnulib-tool.py: Locate configure.ac correctly when --dir is given Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94d1a30c-fec8-4b1f-83c0-a4b45587a7e0@gmail.com \
    --to=collin.funk1@gmail.com \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).