#make test directory rule('tests/C',[]).func = makedir #make test prerequisites @rule('tests/C/*.txt',None,order_only='tests/C') def source(self): touch(self.targets) #test PatternSharedRule @rule(['%.c','%.o'],'%.txt',shared=True) def compile(self): touch([pjoin(self.extratargetpath,self.stems[0]+'.o'), pjoin(self.extratargetpath,self.stems[0]+'.c')]) #self.extratargetpath - pattern rules can be applied to subdirs too, this # attribute might sometimes be useful. #This PatternRule instance should be shadowed by the PatternSharedRule @rule(['%.c','%.o'],'%.txt',shared=False) def compile(self): print "shouldn't run" touch(self.targets) rule('All',PHONY=True,reqs=['tests/C/1.c','tests/C/1.o','tests/C/2.c']) if __name__=="__main__": rule.main()
from bob import Rule as rule #import bob from sh import touch rule('tests',None,func=['mkdir','{targets}']) r1 = rule('tests/test1.txt',None,order_only='tests') r2 = rule('tests/test2.txt',None) r3 = rule('tests/test3.txt',None) @rule(['tests/foo.txt','tests/foo2.txt'],'tests/test*.txt',shared=True) @rule('tests/ex%.txt','tests/test%.txt') def mytouch(self): touch(self.targets) for r in r1,r2,r3: r.func = mytouch rule('All',['tests','tests/foo2.txt','tests/ex2.txt'],PHONY=True) if __name__=="__main__": rule.main() #supplies a simple commandline interface # Can alternatively easily run buildbit from within script. if False: #__name__=="__main__": buildseq = rule.calc_build('All') print buildseq response=raw_input("run build? [(y)es/(n)o]") if response in ('y','yes'): rule.build(buildseq)
r9 = rule(['tests/B/example1.txt','tests/B/example2.txt','tests/B/example?.txt'], ['tests/B/bar2.dat','tests/B/bar4.dat'],order_only='tests/B',shared=True).func=mytouch ###make files for test dir### ##create a general pattern rule - can match to requested prerequisites in sub-directories too. r10 = rule('%.o','%.c',func='touch {targets}') # using command string directly #buildbit will create intemediate files (unlike make though it doesn't yet delete them) rule('tests/result',['tests/A/test{0}.o'.format(i) for i in [1]+range(4,20)]).func=myls #because r2 is a shared rule, buildbit will only run the it once despite multiple requests for its targets. ##pattern rule rule('tests/test%.o','tests/A/test%.c',order_only=['tests/B']).func=makefile #pattern rule #buildbit will use the pattern rule with the closest match rule('tests/result2',['tests/test{0}.o'.format(i) for i in range(4,20)],func=myls) ##pattern rule with wildcards r15 = rule('tests/%/*est%.final','tests/%/test%.*',func=makefile) if False: #__name__=="__main__": buildseq = rule.calc_build('All') print buildseq response=raw_input("run build? [(y)es/(n)o]") if response in ('y','yes'): rule.build(buildseq) if __name__=="__main__": rule.main()