Initial framework for exporting variables. This doesn't actually export them, because I haven't decided how much I want to deal with pulling variables from the environment.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Tue, 10 Feb 2009 15:34:38 -0500
changeset 88 facf7de96123fcd3ceb7b8ce08b903939b42512a
parent 87 0b004bb11184fea0ded1a47116b56ae25ede84e2
child 89 e4edf197af9eea08da53ce2e04bf0ae1fa3fa93f
push id46
push userbsmedberg@mozilla.com
push dateTue, 10 Feb 2009 20:34:48 +0000
Initial framework for exporting variables. This doesn't actually export them, because I haven't decided how much I want to deal with pulling variables from the environment.
pymake/data.py
pymake/parser.py
--- a/pymake/data.py
+++ b/pymake/data.py
@@ -781,16 +781,17 @@ class PatternRule(object):
             if cstring[0:1] == '@':
                 cstring = cstring[1:]
             subprocess.check_call(cstring, shell=True)
 
 class Makefile(object):
     def __init__(self, workdir=None, restarts=0):
         self.defaulttarget = None
         self.variables = Variables()
+        self.exportedvars = set()
         self._targets = {}
         self._patternvariables = [] # of (pattern, variables)
         self.implicitrules = []
         self.parsingfinished = False
 
         if workdir is None:
             workdir = os.getcwd()
         workdir = os.path.realpath(workdir)
--- a/pymake/parser.py
+++ b/pymake/parser.py
@@ -480,17 +480,17 @@ class Condition(object):
             self.active = False
             return
 
         self.active = active
         if active:
             self.everactive = True
 
 directives = [k for k in conditionkeywords.iterkeys()] + \
-    ['else', 'endif', 'define', 'endef', 'override', 'include', '-include', 'vpath']
+    ['else', 'endif', 'define', 'endef', 'override', 'include', '-include', 'vpath', 'export', 'unexport']
 
 varsettokens = (':=', '+=', '?=', '=')
 
 def parsestream(fd, filename, makefile):
     """
     Parse a stream of makefile into a makefile data structure.
 
     @param fd A file-like object containing the makefile data.
@@ -574,16 +574,39 @@ def parsestream(fd, filename, makefile):
                     makefile.include(f, kword == 'include')
                 continue
 
             if kword in conditionkeywords:
                 m = conditionkeywords[kword](d, offset, makefile)
                 condstack.append(Condition(m, d.getloc(offset)))
                 continue
 
+            if kword == 'export':
+                e, token, offset = parsemakesyntax(d, offset, varsettokens, itermakefilechars)
+                e.lstrip()
+                e.rstrip()
+                vars = e.resolve(makefile.variables, None)
+                if token is None:
+                    vlist = data.splitwords(vars)
+                    if len(vlist) == 0:
+                        raise SyntaxError("Exporting all variables is not supported", d.getloc(offset))
+                else:
+                    vlist = [vars]
+                    offset = d.skipwhitespace(offset)
+                    setvariable(makefile.variables, makefile.variables,
+                                vars, token, d, offset)
+
+                for v in vlist:
+                    makefile.exportedvars.add(v)
+
+                continue
+
+            if kword == 'unexport':
+                raise SyntaxError("unexporting variables is not supported", d.getloc(offset))
+
             assert kword is None
 
             if any((not c.active for c in condstack)):
                 log.info('%s: skipping line because of active conditions' % (d.getloc(0),))
                 continue
 
             e, token, offset = parsemakesyntax(d, offset, varsettokens + ('::', ':'), itermakefilechars)
             if token is None: