]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Fixes for conditional dependencies.
authorBruno Haible <bruno@clisp.org>
Mon, 8 Aug 2022 19:22:15 +0000 (21:22 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 9 Aug 2022 21:19:21 +0000 (23:19 +0200)
* pygnulib/GLModuleSystem.py (GLModule.shell_id_chars): New constant.
(GLModule.getShellFunc): Don't use md5 just because of an '_' character.
(GLModule.getShellVar): Likewise.
(GLModule.getConditionalName): Include a newline in the md5 input.
* pygnulib/constants.py (ALPHANUMERIC): Remove constant.

ChangeLog
pygnulib/GLModuleSystem.py
pygnulib/constants.py

index 596f629316b5b451dd0a4a929fe862c172e39d18..091af1f974171391b382f1689d1d7825bb670999 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2022-08-09  Bruno Haible  <bruno@clisp.org>
 
+       gnulib-tool.py: Fixes for conditional dependencies.
+       * pygnulib/GLModuleSystem.py (GLModule.shell_id_chars): New constant.
+       (GLModule.getShellFunc): Don't use md5 just because of an '_' character.
+       (GLModule.getShellVar): Likewise.
+       (GLModule.getConditionalName): Include a newline in the md5 input.
+       * pygnulib/constants.py (ALPHANUMERIC): Remove constant.
+
        gnulib-tool.py: Refactor.
        * pygnulib/GLModuleSystem.py (GLModule.getLicense): Separate the warning
        logic from the result logic.
index 13d6a722318f82a496fbdf30619742e6119fcd3f..9bfd5bd266ee3c5f61fe8ba832a2a7d81a692bef 100644 (file)
@@ -183,6 +183,9 @@ class GLModule(object):
                    + 'Makefile\\.am|Include|Link|License|Maintainer):$',
                    re.M)
 
+    # List of characters allowed in shell identifiers.
+    shell_id_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
+
     def __init__(self, config, path, patched=False):
         '''GLModule.__init__(config, path[, patched]) -> GLModule
 
@@ -329,20 +332,19 @@ class GLModule(object):
 
         Computes the shell function name that will contain the m4 macros for the
         module.'''
-        isalnum = True
         macro_prefix = self.config['macro_prefix']
-        for char in str(module):
-            if char not in constants.ALPHANUMERIC:
-                isalnum = False
+        valid_shell_id = True
+        for char in self.getName():
+            if char not in GLModule.shell_id_chars:
+                valid_shell_id = False
                 break
-        if isalnum:
-            module = str(self)
-        else:  # if not isalnum
-            module = '%s\n' % str(self)
-            if type(module) is str:
-                module = module.encode(ENCS['default'])
-            module = hashlib.md5(module).hexdigest()
-        result = 'func_%s_gnulib_m4code_%s' % (macro_prefix, module)
+        identifier = None
+        if valid_shell_id:
+            identifier = self.getName()
+        else:
+            hash_input = '%s\n' % self.getName()
+            identifier = hashlib.md5(hash_input.encode(ENCS['default'])).hexdigest()
+        result = 'func_%s_gnulib_m4code_%s' % (macro_prefix, identifier)
         return result
 
     def getShellVar(self):
@@ -350,20 +352,19 @@ class GLModule(object):
 
         Compute the shell variable name the will be set to true once the m4 macros
         for the module have been executed.'''
-        isalnum = True
         macro_prefix = self.config['macro_prefix']
-        for char in str(module):
-            if char not in constants.ALPHANUMERIC:
-                isalnum = False
+        valid_shell_id = True
+        for char in self.getName():
+            if char not in GLModule.shell_id_chars:
+                valid_shell_id = False
                 break
-        if isalnum:
-            module = str(self)
-        else:  # if not isalnum
-            module = '%s\n' % str(self)
-            if type(module) is str:
-                module = module.encode(ENCS['default'])
-            module = hashlib.md5(module).hexdigest()
-        result = '%s_gnulib_enabled_%s' % (macro_prefix, module)
+        identifier = None
+        if valid_shell_id:
+            identifier = self.getName()
+        else:
+            hash_input = '%s\n' % self.getName()
+            identifier = hashlib.md5(hash_input.encode(ENCS['default'])).hexdigest()
+        result = '%s_gnulib_enabled_%s' % (macro_prefix, identifier)
         return result
 
     def getConditionalName(self):
@@ -372,15 +373,18 @@ class GLModule(object):
         Return the automake conditional name.
         GLConfig: macro_prefix.'''
         macro_prefix = self.config['macro_prefix']
-        nonascii = [ char
-                     for char in self.getName()
-                     if char not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' ]
-        if nonascii:
-            name = self.getName().encode(ENCS['default'])
-            name = hashlib.md5(name).hexdigest()
-            conditional = '%s_GNULIB_ENABLED_%s' % (macro_prefix, name)
-        else:  # if not nonascii
-            result = '%s_GNULIB_ENABLED_%s' % (macro_prefix, name)
+        valid_shell_id = True
+        for char in self.getName():
+            if char not in GLModule.shell_id_chars:
+                valid_shell_id = False
+                break
+        identifier = None
+        if valid_shell_id:
+            identifier = self.getName()
+        else:
+            hash_input = '%s\n' % self.getName()
+            identifier = hashlib.md5(hash_input.encode(ENCS['default'])).hexdigest()
+        result = '%s_GNULIB_ENABLED_%s' % (macro_prefix, identifier)
         return result
 
     def getDescription(self):
index ba0ebc9942fe74dcaf3136f669ed21e5e2206a1d..ae27d8d41a087ad1d6f4d63da0927ae5c5aac76f 100644 (file)
@@ -57,9 +57,6 @@ MODES = dict()  # Modes
 TESTS = dict()  # Tests
 NL = '''
 '''  # Newline character
-ALPHANUMERIC = 'abcdefghijklmnopqrstuvwxyz\
-ABCDEFGHIJKLMNOPQRSTUVWXYZ\
-0123456789'  # Alphanumeric characters
 
 # Set ENCS dictionary
 if not hasattr(interpreter, '__file__'):