This patch fixes this test failure:

./test-hello-c-gnulib-nonrecursive-1.out tmp1016386-out differ: byte 2612, line 
147
--- ./test-hello-c-gnulib-nonrecursive-1.out    2024-03-24 03:30:48.391074752 
-0700
+++ tmp1016386-out      2024-03-24 18:33:30.855703830 -0700
@@ -144,9 +144,9 @@
   m4/wchar_t.m4
   m4/wint_t.m4
   m4/zzgnulib.m4
-Creating directory ./lib
-Creating directory ./gnulib-m4
-Creating directory ./build-aux
+Creating directory build-aux
+Creating directory gnulib-m4
+Creating directory lib

This is because joinpath performs path normalization. Using
os.path.join seems like the best solution for this:

import os.path
from pathlib import Path
print(os.path.join('.', 'abc'))
./abc
print(str(Path('.', 'abc')))
abc

The second change is reordering the directories. In gnulib-tool.py we
sort all of them. However gnulib-tool.sh only sorts the new file
directories:

  # Create directories.
  { echo "$sourcebase"
    echo "$m4base"
    if test -n "$pobase"; then
      echo "$pobase"
    fi
    docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
    if test -n "$docfiles"; then
      echo "$docbase"
    fi
    if $gentests; then
      echo "$testsbase"
    fi
    echo "$auxdir"
    for f in $files; do echo $f; done \
      | sed -e "$sed_rewrite_new_files" \
      | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
      | LC_ALL=C sort -u
  } > "$tmp"/dirs

To match this we can reorder gnulib-tool.py and use the dictionary
trick I mentioned here to remove duplicates from a list while
preserving order:

https://lists.gnu.org/archive/html/bug-gnulib/2024-03/msg00011.html

diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index e8c8231886..c516491067 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -1060,7 +1060,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         gentests = len(testsfiles) > 0
 
         # Create all necessary directories.
-        dirs = list()
+        dirs = [sourcebase, m4base]
         if pobase:
             dirs += [pobase]
         if [ file
@@ -1069,11 +1069,11 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
             dirs += [docbase]
         if gentests:
             dirs += [testsbase]
-        dirs += [sourcebase, m4base, auxdir]
-        dirs += [ os.path.dirname(pair[0])
-                  for pair in filetable['new'] ]
-        dirs = sorted(set([ joinpath(destdir, d)
-                            for d in dirs ]))
+        dirs += [auxdir]
+        dirs += sorted(list(dict.fromkeys([ os.path.dirname(pair[0])
+                                            for pair in filetable['new'] ])))
+        dirs = [ os.path.join(destdir, d)
+                 for d in dirs ]
         for directory in dirs:
             if not isdir(directory):
                 print('Creating directory %s' % directory)

Collin
From 06570d8a7fe66272fabfe8579d4a9273d9ab4add Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 24 Mar 2024 18:51:29 -0700
Subject: [PATCH] gnulib-tool.py: Fix "Creating directory" output.

* pygnulib/GLImport.py (GLImport.execute): Reorder directories. Use
os.path.join instead of joinpath to avoid path normalization.
---
 ChangeLog            |  6 ++++++
 pygnulib/GLImport.py | 12 ++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0693acfc13..2d8a54f1a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-03-24  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Fix "Creating directory" output.
+	* pygnulib/GLImport.py (GLImport.execute): Reorder directories. Use
+	os.path.join instead of joinpath to avoid path normalization.
+
 2024-03-24  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Fix filetable construction for ignorelist.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index e8c8231886..c516491067 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -1060,7 +1060,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         gentests = len(testsfiles) > 0
 
         # Create all necessary directories.
-        dirs = list()
+        dirs = [sourcebase, m4base]
         if pobase:
             dirs += [pobase]
         if [ file
@@ -1069,11 +1069,11 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
             dirs += [docbase]
         if gentests:
             dirs += [testsbase]
-        dirs += [sourcebase, m4base, auxdir]
-        dirs += [ os.path.dirname(pair[0])
-                  for pair in filetable['new'] ]
-        dirs = sorted(set([ joinpath(destdir, d)
-                            for d in dirs ]))
+        dirs += [auxdir]
+        dirs += sorted(list(dict.fromkeys([ os.path.dirname(pair[0])
+                                            for pair in filetable['new'] ])))
+        dirs = [ os.path.join(destdir, d)
+                 for d in dirs ]
         for directory in dirs:
             if not isdir(directory):
                 print('Creating directory %s' % directory)
-- 
2.44.0

Reply via email to