Hi Collin,
> When working on the one of the TODO entries I noticed that
> the gnulib-comp.m4 output was incorrect. The indentation was slightly
> off and the output also had "if True;" conditionals. Here is a diff
> from Emacs merge-gnulib to show the difference:
>
> @@ -784,8 +785,12 @@ AC_DEFUN
> if $gl_gnulib_enabled_8444034ea779b88768865bb60b4fb8c9; then :; else
> AC_PROG_MKDIR_P
> gl_gnulib_enabled_8444034ea779b88768865bb60b4fb8c9=true
> - func_gl_gnulib_m4code_ef455225c00f5049c808c2eda3e76866
> - func_gl_gnulib_m4code_61bcaca76b3e6f9ae55d57a1c3193bc4
> + if True; then
> + func_gl_gnulib_m4code_ef455225c00f5049c808c2eda3e76866
> + fi
> + if True; then
> + func_gl_gnulib_m4code_61bcaca76b3e6f9ae55d57a1c3193bc4
> + fi
> fi
> }
>
> This seems to be caused by GLModuleTable.addConditional [1] allowing
> string values or boolean True values. When outputting the
> conditionals in GLEmiter.autoconfSnippets, the condition is printed as
> long as the return value is not None [2]. Therefore, when True is
> returned it is printed. The shell script does not print the
> conditional in these cases.
I see; good point.
> I've opted to use "type(condition) is str" and not "condition != True"
> to avoid any problems comparing a string to a bool. I doubt it would
> cause problems, but the type check in addConditional would ensure it
> isn't anything else weird.
There are no problems with writing "condition != True". Remember the rule?
'condition' as a variable can hold the values None, True, or a string.
Thus it has to be compared with == or !=.
"condition != True" is more future-proof than "type(condition) is str",
because
- It expresses the intent more precisely. We are making an optimization
that consists in simplifying
if true; then
STATEMENT
fi
to
STATEMENT
- We may want to allow more complicated conditions in the future, that
may be represented as, say, list of strings instead of a simple string.
I've therefore applied a modified patch:
2024-03-03 Collin Funk <[email protected]>
Bruno Haible <[email protected]>
gnulib-tool.py: Fix output of gnulib-comp.m4.
* pygnulib/GLEmiter.py (GLEmiter.autoconfSnippets): Fix indentation.
Don't print nonstring values into gnulib-comp.m4.
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index 2a8ede9335..8939917a0a 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -297,12 +297,12 @@ class GLEmiter(object):
if moduletable.isConditional(depmodule):
shellfunc = depmodule.getShellFunc()
condition = moduletable.getCondition(module,
depmodule)
- if condition != None:
- emit += ' if %s; then\n' % condition
- emit += ' %s\n' % shellfunc
- emit += ' fi\n'
- else: # if condition == None
- emit += ' %s\n' % shellfunc
+ if condition != None and condition != True:
+ emit += ' if %s; then\n' % condition
+ emit += ' %s\n' % shellfunc
+ emit += ' fi\n'
+ else: # if condition == None or condition ==
True
+ emit += ' %s\n' % shellfunc
# if not moduletable.isConditional(depmodule)
else:
# The autoconf code for $dep has already been
emitted above and
@@ -329,11 +329,11 @@ class GLEmiter(object):
if moduletable.isConditional(depmodule):
shellfunc = depmodule.getShellFunc()
condition = moduletable.getCondition(module,
depmodule)
- if condition != None:
+ if condition != None and condition != True:
emit += ' if %s; then\n' % condition
emit += ' %s\n' % shellfunc
emit += ' fi\n'
- else: # if condition == None
+ else: # if condition == None or condition ==
True
emit += ' %s\n' % shellfunc
# if not moduletable.isConditional(depmodule)
else: