1
1
import logging, re, os
2
import data, functions, util, parser
2
import data, parser, functions, util
3
3
from cStringIO import StringIO
4
4
from pymake.globrelative import hasglob, glob
22
22
self.column = column
24
def __add__(self, data):
24
def offset(self, s, start, end):
26
26
Returns a new location offset by
27
27
the specified string.
33
skiplines = data.count('\n')
33
skiplines = s.count('\n', start, end)
34
34
line = self.line + skiplines
36
lastnl = data.rfind('\n')
36
lastnl = s.rfind('\n', start, end)
37
37
assert lastnl != -1
38
data = data[lastnl + 1:]
41
41
column = self.column
45
j = data.find('\t', i)
44
j = s.find('\t', start, end)
47
column += len(data) - i
51
50
column += _tabwidth
52
51
column -= column % _tabwidth
55
54
return Location(self.path, line, column)
135
134
raise data.DataError("Mixed implicit and normal rule", self.targetexp.loc)
136
135
ispattern, = ispatterns
137
if ispattern and context.weak:
138
raise data.DataError("Pattern rules not allowed in includedeps", self.targetexp.loc)
138
140
deps = [p for p in _expandwildcards(makefile, data.stripdotslashes(self.depexp.resolvesplit(makefile, makefile.variables)))]
140
142
rule = data.PatternRule(targets, map(data.Pattern, deps), self.doublecolon, loc=self.targetexp.loc)
141
143
makefile.appendimplicitrule(rule)
143
rule = data.Rule(deps, self.doublecolon, loc=self.targetexp.loc)
145
rule = data.Rule(deps, self.doublecolon, loc=self.targetexp.loc, weakdeps=context.weak)
144
146
for t in targets:
145
147
makefile.gettarget(t.gettarget()).addrule(rule)
146
149
makefile.foundtarget(targets[0].gettarget())
148
151
context.currule = rule
164
167
self.doublecolon = doublecolon
166
169
def execute(self, makefile, context):
171
raise data.DataError("Static pattern rules not allowed in includedeps", self.targetexp.loc)
167
173
targets = list(_expandwildcards(makefile, data.stripdotslashes(self.targetexp.resolvesplit(makefile, makefile.variables))))
169
175
if not len(targets):
203
209
def execute(self, makefile, context):
204
210
assert context.currule is not None
212
raise data.DataError("rules not allowed in includedeps", self.exp.loc)
205
214
context.currule.addcommand(self.exp)
207
216
def dump(self, fd, indent):
336
345
self.addcondition(loc, condition)
338
347
def getloc(self):
339
return self._groups[0][0].loc
341
350
def addcondition(self, loc, condition):
342
351
assert isinstance(condition, Condition)
344
354
if len(self._groups) and isinstance(self._groups[-1][0], ElseCondition):
345
355
raise parser.SyntaxError("Multiple else conditions for block starting at %s" % self.loc, loc)
369
379
print >>fd, "%s ~Condition" % (indent,)
370
380
print >>fd, "%s~ConditionBlock" % (indent,)
383
return iter(self._groups)
386
return len(self._groups)
388
def __getitem__(self, i):
389
return self._groups[i]
372
391
class Include(Statement):
373
__slots__ = ('exp', 'required')
392
__slots__ = ('exp', 'required', 'deps')
375
def __init__(self, exp, required):
394
def __init__(self, exp, required, weak):
376
395
assert isinstance(exp, (data.Expansion, data.StringExpansion))
378
397
self.required = required
380
400
def execute(self, makefile, context):
381
401
files = self.exp.resolvesplit(makefile, makefile.variables)
383
makefile.include(f, self.required, loc=self.exp.loc)
403
makefile.include(f, self.required, loc=self.exp.loc, weak=self.weak)
385
405
def dump(self, fd, indent):
386
406
print >>fd, "%sInclude %s" % (indent, self.exp)
462
482
print >>fd, "%sEmptyDirective: %s" % (indent, self.exp)
464
484
class _EvalContext(object):
465
__slots__ = ('currule',)
485
__slots__ = ('currule', 'weak')
487
def __init__(self, weak):
467
490
class StatementList(list):
468
491
__slots__ = ('mtime',)
471
494
assert isinstance(statement, Statement)
472
495
list.append(self, statement)
474
def execute(self, makefile, context=None):
497
def execute(self, makefile, context=None, weak=False):
475
498
if context is None:
476
context = _EvalContext()
499
context = _EvalContext(weak=weak)
479
502
s.execute(makefile, context)