wscript 2.7 KB

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