summaryrefslogtreecommitdiff
path: root/pygnulib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2022-08-08 21:22:15 +0200
committerBruno Haible <bruno@clisp.org>2022-08-09 23:19:21 +0200
commit501feeb5d595d8b4cea9a1a8e404277c27d2f5bf (patch)
tree781fceac77c52d8ea65730ea6adb3f945943aad9 /pygnulib
parentd0e094317bbf34413e458f9551543335b6eb8cef (diff)
downloadgnulib-501feeb5d595d8b4cea9a1a8e404277c27d2f5bf.tar.gz
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.
Diffstat (limited to 'pygnulib')
-rw-r--r--pygnulib/GLModuleSystem.py70
-rw-r--r--pygnulib/constants.py3
2 files changed, 37 insertions, 36 deletions
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 13d6a72231..9bfd5bd266 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -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):
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index ba0ebc9942..ae27d8d41a 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -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__'):