Exemple #1
0
    def resolveRun(self, cfg=None):
        config = cfg or self._config
        subJobs = []
        
        job     = self
        if not job.hasFeature("run"):
            return [job]
        else:
            # prepare a Let object for potential macro expansion
            letObj = Let(self.get(Lang.LET_KEY, {}))
            letObj.expandMacrosInLet()              # do self-expansion of macros

            for subjob in job.getFeature("run"):
                
                # make best effort on macro expansion
                if isinstance(subjob, types.StringTypes):
                    if subjob.find('${') > -1:
                        subjob = letObj.expandMacros(subjob)
                # get job object
                subjobObj = self._getJob(subjob, config)
                if not subjobObj:
                    raise RuntimeError, "No such job: \"%s\"" % subjob
                # make new job map job::subjob as copy of job, but extend[subjob]
                newjobname = self.name + self._config.COMPOSED_NAME_SEP + \
                             subjobObj.name.replace(self._config.NS_SEP, self._config.COMPOSED_NAME_SEP)
                newjob     = job.clone()
                newjob.name= newjobname
                newjob.removeFeature('run')       # remove 'run' key
                
                # we assume the initial 'run' job has already been resolved, so
                # we reset it here and set the 'extend' to the subjob
                if newjob.hasFeature(Lang.RESOLVED_KEY): 
                    newjob.removeFeature(Lang.RESOLVED_KEY)
                else:
                    raise RuntimeError, "Cannot resolve 'run' key before 'extend' key"
                newjob.setFeature('extend', [subjobObj]) # extend subjob
                
                # add to config
                self._config.addJob(newjobname, newjob)  # TODO: why not config.addJob(...) ?!
                
                # add to job list
                subJobs.append(newjob)
                
            job.setFeature('run', subJobs)   # overwrite with list of Jobs (instead of Strings)

        return subJobs
Exemple #2
0
    def resolveExtend(self, entryTrace=[], cfg=None):
        # resolve the 'extend' entry of a job
        config = cfg or self._config

        if self.hasFeature(Lang.RESOLVED_KEY):
            return

        self.includeGlobalLet() # make sure potential global let is included first

        if self.hasFeature("extend"):
            # prepare a Let object for potential macro expansion
            letObj = Let(self.get(Lang.LET_KEY, {}))
            letObj.expandMacrosInLet()              # do self-expansion of macros
            # loop through 'extend' entries
            extends = self.getFeature("extend")
            self._console.indent()
            for entry in extends:
                # make best effort on macro expansion
                if isinstance(entry, types.StringTypes):
                    if entry.find('${') > -1:
                        entry = letObj.expandMacros(entry)
                # cyclic check: have we seen this already?
                if entry in entryTrace:
                    raise RuntimeError, "Extend entry already seen: %s" % str(entryTrace+[self.name,entry])
                
                entryJob = self._getJob(entry, config)
                if not entryJob:
                    raise RuntimeError, "No such job: \"%s\" (trace: %s)" % (entry, entryTrace+[self.name])

                self._console.debug('Including "%s" into "%s"' % (entryJob.name, self.name))
                # make sure this entry job is fully resolved in its context
                entryJob.resolveExtend(entryTrace + [self.name], config)

                # now merge the fully expanded job into the current job
                self.mergeJob(entryJob)
            self._console.outdent()

        self.setFeature(Lang.RESOLVED_KEY, True)