wscript (3243B)
1 #! /usr/bin/env python 2 # encoding: utf-8 3 # Thomas Nagy, 2016 4 # 5 6 import os 7 from waflib import Build, Options, TaskGen, Utils 8 9 def build(bld): 10 pass 11 12 @TaskGen.feature('ruler') 13 @TaskGen.before('process_rule') 14 def test_helper(self): 15 if not self.bld.is_install or self.bld.is_install == Build.UNINSTALL: 16 while self.meths: # do not generate tasks: the target file may not be there 17 self.meths.pop() 18 return 19 20 tg = self.bld.get_tgen_by_name(self.bring_in) 21 tg.post() # let it create its installation task 22 assert tg.install_task.outputs 23 self.source = tg.install_task.outputs 24 25 def configure(conf): 26 27 tmpdir_top = conf.bldnode.make_node('tmpdir') 28 tmpdir_top.delete(evict=False) 29 tmpdir = tmpdir_top.make_node('foo') 30 31 def build(bld): 32 bld.is_install = env.INSTALL 33 bld.path.make_node('tmpfile').write('test') 34 35 bld.install_as('${PREFIX}/bin/foo', 'tmpfile', chmod=Utils.O755) 36 bld.symlink_as('${PREFIX}/bin/bar', '../tmpfile') 37 tsk = bld.install_files('${PREFIX}/bin', 'tmpfile', chmod=Utils.O755, name='cheese') 38 bld(rule='ls -l ${SRC}', always=True, bring_in='cheese', features='ruler') 39 40 # preserve the folder structure or not (relative_trick) 41 bld.path.make_node('blah/blah').mkdir() 42 bld(features='subst', source='tmpfile', target='blah/blah/rel1', is_copy=True, install_path='${PREFIX}') 43 44 bld(features='subst', source='tmpfile', target='blah/blah/rel2', is_copy=True) 45 bld.install_files('${PREFIX}', 'blah/blah/rel2', relative_base=bld.path.get_bld(), relative_trick=True) 46 47 bld(features='subst', source='tmpfile', target='blah/blah/rel3', is_copy=True) 48 bld.install_files('${PREFIX}', 'blah/blah/rel3', relative_base=bld.path.search_node('blah').get_bld(), relative_trick=True) 49 50 bld(features='subst', source='tmpfile', target='blah/blah/rel4', is_copy=True) 51 bld.install_files('lib', 'blah/blah/rel4') 52 53 def check(env): 54 tmpdir_top.delete(evict=False) 55 56 env.INSTALL = Build.INSTALL 57 conf.run_build(build_fun=build, msg='building', okmsg='ok', errmsg='eh', env=env) 58 59 assert tmpdir.exists() 60 assert tmpdir.make_node('bin/foo').exists() 61 assert tmpdir.make_node('bin/tmpfile').exists() 62 assert tmpdir.make_node('bin/foo').read() == tmpdir.make_node('bin/tmpfile').read() 63 assert os.path.lexists(tmpdir.make_node('bin/bar').abspath()) 64 assert os.readlink(tmpdir.make_node('bin/bar').abspath()) == '../tmpfile' 65 assert tmpdir.make_node('rel1').exists() 66 assert tmpdir.make_node('blah/blah/rel2').exists() 67 assert tmpdir.make_node('blah/rel3').exists() 68 assert tmpdir.make_node('lib/rel4').exists() 69 70 env.INSTALL = Build.UNINSTALL 71 conf.run_build(build_fun=build, msg='building', okmsg='ok', errmsg='eh', env=env) 72 assert not tmpdir.exists() 73 assert not tmpdir.make_node('bin/foo').exists() 74 assert not tmpdir.make_node('bin/tmpfile').exists() 75 assert not os.path.lexists(tmpdir.make_node('bin/bar').abspath()) 76 assert not tmpdir.exists() 77 assert not tmpdir.make_node('rel1').exists() 78 assert not tmpdir.make_node('blah/blah/rel2').exists() 79 assert not tmpdir.make_node('blah/rel3').exists() 80 81 env = conf.env.derive() 82 env.PREFIX = tmpdir.abspath() 83 Options.options.destdir = None 84 check(env) 85 86 env = conf.env.derive() 87 env.PREFIX = '/foo' 88 Options.options.destdir = tmpdir_top.abspath() 89 check(env) 90 91