]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Fix unconditional Automake snippets for non-tests.
authorCollin Funk <collin.funk1@gmail.com>
Fri, 22 Mar 2024 09:15:24 +0000 (02:15 -0700)
committerBruno Haible <bruno@clisp.org>
Fri, 22 Mar 2024 16:06:17 +0000 (17:06 +0100)
* pygnulib/GLModuleSystem.py
(GLModule.getAutomakeSnippet_Unconditional): Fix the file lookups used
to determine the EXTRA_DIST and EXTRA_lib_SOURCES Automake variables.
Update comment to match gnulib-tool.sh.
* pygnulib/constants.py (filter_filelist): Fix misleading return type in
docstring. Return an empty string if no files were found.

ChangeLog
pygnulib/GLModuleSystem.py
pygnulib/constants.py

index ce94b65c6638a5b2596aee3eedb4cd1e4278655f..38633a82e95ebb1daffac56a238a2cbd3ac9d08b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-03-22  Collin Funk  <collin.funk1@gmail.com>
+
+       gnulib-tool.py: Fix unconditional Automake snippets for non-tests.
+       * pygnulib/GLModuleSystem.py
+       (GLModule.getAutomakeSnippet_Unconditional): Fix the file lookups used
+       to determine the EXTRA_DIST and EXTRA_lib_SOURCES Automake variables.
+       Update comment to match gnulib-tool.sh.
+       * pygnulib/constants.py (filter_filelist): Fix misleading return type in
+       docstring. Return an empty string if no files were found.
+
 2024-03-22  Bruno Haible  <bruno@clisp.org>
 
        gnulib-tool.sh: Produce same diagnostics regardless of Automake version.
index bfef6e692bbd24f8279c0a36bb2adf37e80e201d..c0d9b0365aa13a11517674b7931a6ad815c82702 100644 (file)
@@ -649,52 +649,61 @@ class GLModule(object):
         result = ''
         if 'makefile-unconditional' not in self.cache:
             if self.getName().endswith('-tests'):
+                # *-tests module live in tests/, not lib/.
+                # Synthesize an EXTRA_DIST augmentation.
                 files = self.getFiles()
                 extra_files = filter_filelist(constants.NL, files,
-                                              'tests/', '', 'tests/', '').split(constants.NL)
-                if extra_files:
-                    result += 'EXTRA_DIST += %s' % ' '.join(extra_files)
+                                              'tests/', '', 'tests/', '')
+                if extra_files != '':
+                    result += 'EXTRA_DIST += %s' % ' '.join(extra_files.split(constants.NL))
                     result += constants.NL * 2
             else:  # if not tests module
-                # TODO: unconditional automake snippet for nontests modules
+                # Synthesize an EXTRA_DIST augmentation.
                 snippet = self.getAutomakeSnippet_Conditional()
                 snippet = constants.combine_lines(snippet)
-                pattern = re.compile('^lib_SOURCES[\t ]*\\+=[\t ]*(.*)$', re.M)
-                mentioned_files = pattern.findall(snippet)
-                if mentioned_files != list():
-                    mentioned_files = mentioned_files[-1].split(' ')
-                    mentioned_files = [ f.strip()
-                                        for f in mentioned_files ]
-                    mentioned_files = [ f
-                                        for f in mentioned_files
-                                        if f != '' ]
-                    mentioned_files = sorted(set(mentioned_files))
+                pattern = re.compile(r'^lib_SOURCES[\t ]*\+=[\t ]*(.*)$', re.MULTILINE)
+                mentioned_files = set(pattern.findall(snippet))
+                if mentioned_files:
+                    # Get all the file names from 'lib_SOURCES += ...'.
+                    mentioned_files = { filename
+                                        for line in mentioned_files
+                                        for filename in line.split() }
                 all_files = self.getFiles()
                 lib_files = filter_filelist(constants.NL, all_files,
-                                            'lib/', '', 'lib/', '').split(constants.NL)
-                extra_files = [ f
-                                for f in lib_files
-                                if f not in mentioned_files ]
-                extra_files = sorted(set(extra_files))
-                if extra_files != [''] and extra_files:
+                                            'lib/', '', 'lib/', '')
+                if lib_files != '':
+                    lib_files = set(lib_files.split(constants.NL))
+                else:
+                    lib_files = set()
+                # Remove mentioned_files from lib_files.
+                extra_files = sorted(lib_files.difference(mentioned_files))
+                if extra_files:
                     result += 'EXTRA_DIST += %s' % ' '.join(extra_files)
                     result += '\n\n'
-                # Synthesize also an EXTRA_lib_SOURCES augmentation
+                # Synthesize also an EXTRA_lib_SOURCES augmentation.
+                # This is necessary so that automake can generate the right list of
+                # dependency rules.
+                # A possible approach would be to use autom4te --trace of the redefined
+                # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
+                # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
+                # inside autoconf's built-in macros are not missed).
+                # But it's simpler and more robust to do it here, based on the file list.
+                # If some .c file exists and is not used with AC_LIBOBJ - for example,
+                # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
+                # automake will generate a useless dependency; this is harmless.
                 if str(self) != 'relocatable-prog-wrapper' and str(self) != 'pt_chown':
                     extra_files = filter_filelist(constants.NL, extra_files,
-                                                  '', '.c', '', '').split(constants.NL)
-                    extra_files = sorted(set(extra_files))
-                    if extra_files != ['']:
-                        result += 'EXTRA_lib_SOURCES += %s' % ' '.join(extra_files)
+                                                  '', '.c', '', '')
+                    if extra_files != '':
+                        result += 'EXTRA_lib_SOURCES += %s' % ' '.join(sorted(set(extra_files.split(constants.NL))))
                         result += '\n\n'
                 # Synthesize an EXTRA_DIST augmentation also for the files in build-aux
                 buildaux_files = filter_filelist(constants.NL, all_files,
-                                                 'build-aux/', '', 'build-aux/', '').split(constants.NL)
-                buildaux_files = sorted(set(buildaux_files))
-                if buildaux_files != ['']:
-                    buildaux_files = ''.join(buildaux_files)
-                    buildaux_files = joinpath('$(top_srcdir)', auxdir, buildaux_files)
-                    result += 'EXTRA_DIST += %s' % buildaux_files
+                                                 'build-aux/', '', 'build-aux/', '')
+                if buildaux_files != '':
+                    buildaux_files = [ joinpath('$(top_srcdir)', auxdir, filename)
+                                       for filename in sorted(set(buildaux_files.split(constants.NL))) ]
+                    result += 'EXTRA_DIST += %s' % ' '.join(buildaux_files)
                     result += '\n\n'
             result = constants.nlconvert(result)
             self.cache['makefile-unconditional'] = result
index b7434155d8b009b7245a568ef1654aa463d8ffd4..c3a5aeae094237949f619a3853df98f20af40fbd 100644 (file)
@@ -447,7 +447,7 @@ def hardlink(src: str, dest: str) -> None:
 def filter_filelist(separator, filelist,
                     prefix, suffix, removed_prefix, removed_suffix,
                     added_prefix='', added_suffix=''):
-    '''filter_filelist(*args) -> list
+    '''filter_filelist(*args) -> str
 
     Filter the given list of files. Filtering: Only the elements starting with
     prefix and ending with suffix are considered. Processing: removed_prefix
@@ -461,7 +461,12 @@ def filter_filelist(separator, filelist,
             result = pattern.sub('%s\\1%s'
                                  % (added_prefix, added_suffix), filename)
             listing += [result]
-    result = separator.join(listing)
+    # Return an empty string if no files were matched, else combine them
+    # with the given separator.
+    if listing:
+        result = separator.join(listing)
+    else:
+        result = ''
     return result