wscript 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #! /usr/bin/env python
  2. top = '.'
  3. out = 'build'
  4. import os, shutil, sys
  5. from waflib import ConfigSet, Context, Logs
  6. def options(opt):
  7. pass
  8. def configure(conf):
  9. pass
  10. def run_command(ctx, *k, **kw):
  11. with open('/dev/null', 'w') as f:
  12. kw['stdout'] = f
  13. ret = ctx.exec_command(*k, **kw)
  14. if ret:
  15. ctx.fatal('Command failed ret:%r - %r %r' % (ret, k, kw))
  16. return ret
  17. def cleanup(ctx):
  18. for y in ('side_cwd', 'up_cwd'):
  19. lst = ctx.path.find_node(y).ant_glob(['**/.lock-waf*'])
  20. for k in lst:
  21. k.delete()
  22. for k in ctx.path.ant_glob('**/tmp_out', dir=True):
  23. shutil.rmtree(k.abspath())
  24. def build(bld):
  25. failures = []
  26. up_cwd = bld.path.find_node('up_cwd').abspath()
  27. side_cwd = bld.path.find_node('side_cwd').abspath()
  28. proj_cwd = bld.path.find_node('up_cwd/project').abspath()
  29. proj_sub_cwd = bld.path.find_node('up_cwd/project/sub').abspath()
  30. proj_out_cwd = bld.path.make_node('up_cwd/project/tmp_out').abspath()
  31. wscript = bld.path.find_node('up_cwd/project/wscript').abspath()
  32. d_node = bld.path.make_node('path_to_record')
  33. dumpf_default = d_node.abspath()
  34. def make_cmd(cmd, based=proj_cwd, dumpf=dumpf_default):
  35. return list(cmd) + ['--based=%s' % based, '--dumpf=%s' % dumpf]
  36. def test_cmd(cmd, cwd, test_name, cwd_dir='.', top_dir='.', out_dir='tmp_out', run_dir='.', launch_dir='.'):
  37. cmd = make_cmd(cmd)
  38. try:
  39. run_command(bld, cmd, cwd=cwd)
  40. v = ConfigSet.ConfigSet(dumpf_default)
  41. finally:
  42. for k in bld.path.ant_glob('**/path_to_record'):
  43. k.delete()
  44. err = []
  45. def check_err(got, expected, var_name):
  46. if got != expected:
  47. Logs.pprint('RED', '- %s: %s -> got:%r expected:%r' % (test_name, var_name, got, expected))
  48. err.append(var_name)
  49. check_err(v.cwd_dir, cwd_dir, 'cwd')
  50. check_err(v.top_dir, top_dir, 'top')
  51. check_err(v.run_dir, run_dir, 'run')
  52. check_err(v.out_dir, out_dir, 'out')
  53. check_err(v.launch_dir, launch_dir, 'launch')
  54. if err:
  55. failures.append(test_name)
  56. else:
  57. Logs.pprint('GREEN', '- %s: ok' % test_name)
  58. exe = os.path.abspath(os.path.join(Context.launch_dir, sys.argv[0]))
  59. cleanup(bld)
  60. test_cmd([exe, 'configure'], proj_cwd, 'regular configure')
  61. test_cmd([exe], proj_cwd, ' regular build from top')
  62. test_cmd([exe], proj_out_cwd, ' regular build from out', launch_dir='tmp_out')
  63. test_cmd([exe], proj_sub_cwd, ' regular build from subfolder', launch_dir='sub')
  64. cleanup(bld)
  65. test_cmd([exe, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], proj_cwd, 'configure with top/out from proj cwd')
  66. test_cmd([exe], proj_cwd, ' next build from top')
  67. test_cmd([exe], proj_out_cwd, ' next build from out', launch_dir='tmp_out')
  68. test_cmd([exe], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')
  69. test_cmd([exe, '--top=%s' % proj_cwd, '--out=foobar'], proj_cwd,
  70. ' next build from top, verify out_dir==lock_file.out_dir')
  71. test_cmd([exe, '--top=%s' % proj_cwd, '--out=foobar'], proj_sub_cwd,
  72. ' next build from subfolder, verify out_dir==lock_file.out_dir', launch_dir='sub')
  73. cleanup(bld)
  74. test_cmd([exe, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], up_cwd, 'configure with top/out from up cwd',
  75. launch_dir='..')
  76. test_cmd([exe], proj_cwd, ' next build from top')
  77. test_cmd([exe], proj_out_cwd, ' next build from out', launch_dir='tmp_out')
  78. test_cmd([exe], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')
  79. cleanup(bld)
  80. test_cmd([wscript, 'configure'], proj_cwd, 'wscript configure')
  81. test_cmd([wscript], proj_cwd, ' next build from top')
  82. test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out')
  83. test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')
  84. cleanup(bld)
  85. test_cmd([wscript, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], proj_cwd, 'wscript configure with top/out from proj cwd')
  86. test_cmd([wscript], proj_cwd, ' next build from top')
  87. test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out')
  88. test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')
  89. cleanup(bld)
  90. test_cmd([wscript, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], up_cwd, 'wscript configure with top/out from up cwd',
  91. launch_dir='..')
  92. test_cmd([wscript], proj_cwd, ' next build from top')
  93. test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out')
  94. test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')
  95. cleanup(bld)
  96. test_cmd([exe, '--top=%s' % proj_cwd], proj_cwd, 'autoconfig')
  97. cleanup(bld)
  98. test_cmd([wscript, 'configure', '--top=project', '--out=project/tmp_out'], up_cwd, 'wscript configure with relative top/out from up cwd',
  99. launch_dir='..')
  100. test_cmd([wscript], proj_cwd, ' next build from top')
  101. test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out')
  102. test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')
  103. cleanup(bld)
  104. test_cmd([exe, '--force-autoconfig', '--top=project'], up_cwd, 'autoconfig from up 1', launch_dir='..')
  105. os.remove(dumpf_default + '_autoconfig')
  106. test_cmd([exe, '--force-autoconfig', '--top=project'], up_cwd, 'autoconfig from up 2', launch_dir='..')
  107. os.remove(dumpf_default + '_autoconfig')
  108. test_cmd([exe, '--force-autoconfig', '--out=badout'], proj_cwd, 'autoconfig with clobber')
  109. cleanup(bld)
  110. if failures:
  111. bld.fatal('there were errors')