"Optional" variables ($?VAR)
Adriaan de Groot <adridg-FlD2LfDziEhmR6Xm/[email protected]>
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
By default, AAP is "strict" in its variable expansions. The expression "$VAR"
is an error unless VAR has been given a value (even an empty one) somewhere.
The construction $?VAR is used to indicate that the variable is "optional"
and that if the variable has never been assigned a value, the expression
$?VAR should expand to an empty string, and not give an error.
So far, so good. A departure from the old-fashioned make and shell semantics,
where it's never an error to use $VAR.
I'm currently working on an Automake-to-AAP wedge, which is basically one AAP
recipe that can handle most automake Makefile.am's. My testbed is KDE, where
most of the Makefile.am's are simple groups of variable assignments.
Something like this is typical:
kpilotTest_SOURCES = kpilotConfig.cc \
logWidget.cc pilotComponent.cc \
hotSync.cc internalEditorAction.cc interactiveSync.cc \
logWidgetDCOP.skel \
syncStack.cc \
main-test.cc
kpilotTest_LDADD = $(LIB_KFILE) $(PISOCK_LIB) ../lib/libkpilot.la
$(KHEX_LIB)
Heck, that could be (part of) an AAP recipe if it weren't for one thing: in
automake, those variables like $(KHEX_LIB) may not be defined; that yields
empty strings in the Makefile, yet errors in AAP.
So, what I'd like is a way to switch AAP's strictness for variables on or off
within a recipe. Then I could do something like
AAP_VAROPTIONAL=1
:include Makefile.am
AAP_VAROPTIONAL=
in order to read in a Makefile.am. What could be nicer to introduce AAP to
auto* and make users than as a single tool that can be introduced very
cheaply (just the automake wedge recipe is needed) while providing all kinds
of other possibilities as well.
The attached patch implements this. When a particular scope has
AAP_VAROPTIONAL set to a non-null value, variables taken from that scope are
always considered optional - ie. $VAR is read as $?VAR. A warning might be in
order for undefined variables in this case, though.
--
pub 1024D/FEA2A3FE 2002-06-18 Adriaan de Groot <[email protected]>
Key fingerprint = 934E 31AA 80A7 723F 54F9 50ED 76AC EE01 FEA2 A3FE
aap-lenient.diff
(text/x-diff, 419 B)
--- Commands.py.orig Tue Aug 12 17:29:33 2003
+++ Commands.py Tue Aug 12 17:33:56 2003
@@ -1426,6 +1426,14 @@
except:
scope_found = 0
+ if scope_found:
+ try:
+ lenient = rd["AAP_VAROPTIONAL"]
+ if lenient:
+ exp.optional=1
+ except:
+ lenient=0
+
if scope_found:
try:
var_found = rd[varname]