#!/usr/bin/env python """example script for package buildbit.""" 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'):
#!/usr/bin/env python """example script for package buildbit.""" from bob import Rule as rule import bob from sh import touch,mkdir,ls #make test directories def makedir(self): for target in self.targets: mkdir('-p',target) rule('tests',None,func=makedir) rule('tests/A',None,order_only='tests').func = makedir r1 = rule('tests/B',None,order_only='tests') r1.func = makedir ###make files for dir A### @rule('tests/A/test1.c',None,order_only='tests/A') @rule('tests/A/test2',None,order_only='tests/A') @rule('tests/A/test3.txt',None,order_only='tests/A') def mytouch(self): touch(self.targets) ##one shared rule for many targets r2 = rule(['tests/A/test%d.c' %i for i in range(4,20)],None,shared=True,order_only='tests/A') r2.func = mytouch
"""example script for package buildbit.""" from bob import Rule as rule import bob from sh import touch,mkdir,ls import os pjoin = os.path.join def makedir(self): for target in self.targets: mkdir('-p',target) #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.
#!/usr/bin/env python """example script for package buildbit.""" from bob import Rule as rule import bob from sh import touch,mkdir,ls #make test directories def makedir(self): for target in self.targets: mkdir('-p',target) outpath = 'tests-unittests/' r0 = rule(outpath[:-1],None,func=makedir) assert isinstance(r0,bob.ExplicitRule) tmp = rule(outpath+'A',None,order_only=outpath[:-1]).func = makedir assert (tmp is makedir) r1 = bob.ExplicitRule.rules[outpath+'A'] r2 = rule(outpath+'B',None,order_only=outpath[:-1]) r2.func = makedir assert isinstance(r2,bob.ExplicitRule) ###make files for dir A### @rule(outpath+'A/test1.c',None,order_only=outpath+'A') @rule(outpath+'A/test2',None,order_only=outpath+'A') @rule(outpath+'A/test3.txt',None,order_only=outpath+'A')