Example #1
0
    def execute(self, makefile, context):
        if context.weak:
            raise errors.DataError(
                "Static pattern rules not allowed in includedeps",
                self.targetexp.loc)

        targets = list(
            _expandwildcards(
                makefile,
                data.stripdotslashes(
                    self.targetexp.resolvesplit(makefile,
                                                makefile.variables))))

        if not len(targets):
            context.currule = DummyRule()
            return

        patterns = list(
            data.stripdotslashes(
                self.patternexp.resolvesplit(makefile, makefile.variables)))
        if len(patterns) != 1:
            raise errors.DataError(
                "Static pattern rules must have a single pattern",
                self.patternexp.loc)
        pattern = data.Pattern(patterns[0])

        deps = [
            data.Pattern(p) for p in _expandwildcards(
                makefile,
                data.stripdotslashes(
                    self.depexp.resolvesplit(makefile, makefile.variables)))
        ]

        rule = data.PatternRule([pattern],
                                deps,
                                self.doublecolon,
                                loc=self.targetexp.loc)

        for t in targets:
            if data.Pattern(t).ispattern():
                raise errors.DataError(
                    "Target '%s' of a static pattern rule must not be a pattern"
                    % (t, ), self.targetexp.loc)
            stem = pattern.match(t)
            if stem is None:
                raise errors.DataError(
                    "Target '%s' does not match the static pattern '%s'" %
                    (t, pattern), self.targetexp.loc)
            makefile.gettarget(t).addrule(
                data.PatternRuleInstance(rule, '', stem, pattern.ismatchany()))

        makefile.foundtarget(targets[0])
        context.currule = rule
Example #2
0
    def _execute(self, makefile, context):
        assert not context.weak

        atargets = data.stripdotslashes(
            self.targetexp.resolvesplit(makefile, makefile.variables))
        targets = [
            data.Pattern(p) for p in _expandwildcards(makefile, atargets)
        ]

        if not len(targets):
            context.currule = DummyRule()
            return

        ispatterns = set((t.ispattern() for t in targets))
        if len(ispatterns) == 2:
            raise errors.DataError("Mixed implicit and normal rule",
                                   self.targetexp.loc)
        ispattern, = ispatterns

        deps = list(
            _expandwildcards(
                makefile,
                data.stripdotslashes(
                    self.depexp.resolvesplit(makefile, makefile.variables))))
        if ispattern:
            prerequisites = [data.Pattern(d) for d in deps]
            rule = data.PatternRule(targets,
                                    prerequisites,
                                    self.doublecolon,
                                    loc=self.targetexp.loc)
            makefile.appendimplicitrule(rule)
        else:
            rule = data.Rule(deps,
                             self.doublecolon,
                             loc=self.targetexp.loc,
                             weakdeps=False)
            for t in targets:
                makefile.gettarget(t.gettarget()).addrule(rule)

            makefile.foundtarget(targets[0].gettarget())

        context.currule = rule
Example #3
0
 def _executeweak(self, makefile, context):
     """
     If the context is weak (we're just handling dependencies) we can make a number of assumptions here.
     This lets us go really fast and is generally good.
     """
     assert context.weak
     deps = self.depexp.resolvesplit(makefile, makefile.variables)
     # Skip targets with no rules and no dependencies
     if not deps:
         return
     targets = data.stripdotslashes(
         self.targetexp.resolvesplit(makefile, makefile.variables))
     rule = data.Rule(list(data.stripdotslashes(deps)),
                      self.doublecolon,
                      loc=self.targetexp.loc,
                      weakdeps=True)
     for target in targets:
         makefile.gettarget(target).addrule(rule)
         makefile.foundtarget(target)
     context.currule = rule
Example #4
0
    def execute(self, makefile, context):
        vname = self.vnameexp.resolvestr(makefile, makefile.variables)
        if len(vname) == 0:
            raise errors.DataError("Empty variable name", self.vnameexp.loc)

        if self.targetexp is None:
            setvariables = [makefile.variables]
        else:
            setvariables = []

            targets = [
                data.Pattern(t) for t in data.stripdotslashes(
                    self.targetexp.resolvesplit(makefile, makefile.variables))
            ]
            for t in targets:
                if t.ispattern():
                    setvariables.append(makefile.getpatternvariables(t))
                else:
                    setvariables.append(
                        makefile.gettarget(t.gettarget()).variables)

        for v in setvariables:
            if self.token == '+=':
                v.append(vname, self.source, self.value, makefile.variables,
                         makefile)
                continue

            if self.token == '?=':
                flavor = data.Variables.FLAVOR_RECURSIVE
                oldflavor, oldsource, oldval = v.get(vname, expand=False)
                if oldval is not None:
                    continue
                value = self.value
            elif self.token == '=':
                flavor = data.Variables.FLAVOR_RECURSIVE
                value = self.value
            else:
                assert self.token == ':='

                flavor = data.Variables.FLAVOR_SIMPLE
                d = parser.Data.fromstring(self.value, self.valueloc)
                e, t, o = parser.parsemakesyntax(d, 0, (), parser.iterdata)
                value = e.resolvestr(makefile, makefile.variables)

            v.set(vname, flavor, self.source, value)
Example #5
0
    def execute(self, makefile, context):
        words = list(
            data.stripdotslashes(
                self.exp.resolvesplit(makefile, makefile.variables)))
        if len(words) == 0:
            makefile.clearallvpaths()
        else:
            pattern = data.Pattern(words[0])
            mpaths = words[1:]

            if len(mpaths) == 0:
                makefile.clearvpath(pattern)
            else:
                dirs = []
                for mpath in mpaths:
                    dirs.extend(
                        (dir for dir in mpath.split(os.pathsep) if dir != ''))
                if len(dirs):
                    makefile.addvpath(pattern, dirs)