]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Fix --extract-dependencies result.
authorBruno Haible <bruno@clisp.org>
Sun, 7 Aug 2022 22:02:59 +0000 (00:02 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 7 Aug 2022 22:02:59 +0000 (00:02 +0200)
* pygnulib/GLModuleSystem.py (GLModule.getDependencies): Return a
snippet, not a list. Implement dependency of ${module}-tests on
${module}.
(GLModule.getDependenciesWithoutConditions,
GLModule.getDependenciesWithConditions): New methods.
(GLModuleTable.transitive_closure): Call getDependenciesWithConditions.
* pygnulib/GLEmiter.py (GLEmiter.autoconfSnippets): Call
getDependenciesWithoutConditions.
* gnulib-tool.py (main) [--extract-dependencies]: Update.

ChangeLog
gnulib-tool.py
pygnulib/GLEmiter.py
pygnulib/GLModuleSystem.py

index 1278d8e4d90e96a1cb4e10959332ba8d3cdf2d1b..beb60578d0656f081f948ddea6b1a125a9427f20 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2022-08-07  Bruno Haible  <bruno@clisp.org>
 
+       gnulib-tool.py: Fix --extract-dependencies result.
+       * pygnulib/GLModuleSystem.py (GLModule.getDependencies): Return a
+       snippet, not a list. Implement dependency of ${module}-tests on
+       ${module}.
+       (GLModule.getDependenciesWithoutConditions,
+       GLModule.getDependenciesWithConditions): New methods.
+       (GLModuleTable.transitive_closure): Call getDependenciesWithConditions.
+       * pygnulib/GLEmiter.py (GLEmiter.autoconfSnippets): Call
+       getDependenciesWithoutConditions.
+       * gnulib-tool.py (main) [--extract-dependencies]: Update.
+
        gnulib-tool.py: Rename a method.
        * pygnulib/GLModuleSystem.py (GLModule.getAutoconfEarlySnippet): Renamed
        from GLModule.getAutoconfSnippet_Early.
index 0e888e6fd89ce866955a6db3e5498e3629aba395..0cd5accd2189a6e39b79d895502d8c2d0bbf14ac 100755 (executable)
@@ -1013,7 +1013,6 @@ def main():
             print('\n'.join(files))
 
     elif mode == 'extract-dependencies':
-        result = ''
         if avoids:
             message = '%s: *** ' % constants.APP['name']
             message += 'cannot combine --avoid and --extract-dependencies\n'
@@ -1024,14 +1023,7 @@ def main():
         modules = [ modulesystem.find(module)
                     for module in modules ]
         for module in modules:
-            dependencies = module.getDependencies()
-            if dependencies:
-                for depmodule, condition in dependencies:
-                    if condition == None:
-                        result += '%s\n' % str(depmodule)
-                    else:  # if condition != None
-                        result += '%s\t%s' % (str(depmodule), condition)
-        print(result)
+            sys.stdout.write(module.getDependencies())
 
     elif mode == 'extract-autoconf-snippet':
         modulesystem = classes.GLModuleSystem(config)
index 61cabc92fa7131b45fc033fe9b4ea798f8deb902..a02b44bdd51fa2773d83f30bbf343b3d59d7d91b 100644 (file)
@@ -309,9 +309,7 @@ class GLEmiter(object):
                         emit += self.autoconfSnippet(module, fileassistant, toplevel,
                                                      disable_libtool, disable_gettext, replace_auxdir, '      ')
                         emit += '      %s=true\n' % shellvar
-                        dependencies = module.getDependencies()
-                        depmodules = [ pair[0]
-                                       for pair in dependencies ]
+                        depmodules = module.getDependenciesWithoutConditions()
                         # Intersect dependencies with the modules list.
                         depmodules = [ dep
                                        for dep in depmodules
index 14bc089b27474245450816cd9a6ea83a70b29468..19d13d213b22f59df617d4dbe7817cb1791ce13a 100644 (file)
@@ -452,33 +452,74 @@ class GLModule(object):
         return self.cache['files']
 
     def getDependencies(self):
-        '''GLModule.getDependencies() -> list
+        '''GLModule.getDependencies() -> str
 
-        Return list of dependencies.
+        Return list of dependencies, as a snippet.
         GLConfig: localpath.'''
         if 'dependencies' not in self.cache:
+            result = ''
+            # ${module}-tests implicitly depends on ${module}, if that module exists.
+            if self.isTests():
+                main_module = subend('-tests', '', self.getName())
+                if self.modulesystem.exists(main_module):
+                    result += '%s\n' % main_module
+            # Then the explicit dependencies listed in the module description.
             snippet = self.sections.get('Depends-on', '')
-            modules = [ line.strip()
-                        for line in snippet.split('\n')
-                        if line.strip() ]
-            modules = [ module
-                        for module in modules
-                        if not module.startswith('#') ]
-            result = list()
-            for line in modules:
-                split = [ part
-                          for part in line.split(' ')
-                          if part.strip() ]
-                if len(split) == 1:
-                    module = line.strip()
-                    condition = None
-                else:  # if len(split) != 1
-                    module = split[0]
-                    condition = split[1]
-                result += [tuple([self.modulesystem.find(module), condition])]
+            # Remove comment lines.
+            snippet = re.compile('^#.*$[\n]', re.M).sub('', snippet)
+            result += snippet
             self.cache['dependencies'] = result
         return self.cache['dependencies']
 
+    def getDependenciesWithoutConditions(self):
+        '''GLModule.getDependenciesWithoutConditions() -> list
+
+        Return list of dependencies, as a list of GLModule objects.
+        GLConfig: localpath.'''
+        if 'dependenciesWithoutCond' not in self.cache:
+            snippet = self.getDependencies()
+            lines = [ line.strip()
+                      for line in snippet.split('\n')
+                      if line.strip() ]
+            pattern = re.compile(' *\\[.*$')
+            lines = [ pattern.sub('', line)
+                      for line in lines ]
+            result = [ self.modulesystem.find(module)
+                       for module in lines
+                       if module != '' ]
+            self.cache['dependenciesWithoutCond'] = result
+        return self.cache['dependenciesWithoutCond']
+
+    def getDependenciesWithConditions(self):
+        '''GLModule.getDependenciesWithConditions() -> list
+
+        Return list of dependencies, as a list of pairs (GLModule object, condition).
+        The "true" condition is denoted by None.
+        GLConfig: localpath.'''
+
+        if 'dependenciesWithCond' not in self.cache:
+            snippet = self.getDependencies()
+            lines = [ line.strip()
+                      for line in snippet.split('\n')
+                      if line.strip() ]
+            pattern = re.compile(' *\\[')
+            result = []
+            for line in lines:
+                match = pattern.search(line)
+                if match:
+                    module = line[0 : match.start()]
+                    condition = line[match.end() :]
+                    condition = subend(']', '', condition)
+                else:
+                    module = line
+                    condition = None
+                if module != '':
+                    if condition == 'true':
+                        condition = None
+                    result.append(tuple([self.modulesystem.find(module), condition]))
+            self.cache['dependenciesWithCond'] = result
+        return self.cache['dependenciesWithCond']
+
     def getAutoconfEarlySnippet(self):
         '''GLModule.getAutoconfEarlySnippet() -> str
 
@@ -798,7 +839,7 @@ class GLModuleTable(object):
                         if not pattern.findall(automake_snippet):
                             self.addUnconditional(module)
                         conditional = self.isConditional(module)
-                    dependencies = module.getDependencies()
+                    dependencies = module.getDependenciesWithConditions()
                     depmodules = [ pair[0]
                                    for pair in dependencies ]
                     conditions = [ pair[1]