flags.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/python
  2. # Copyright (C) Steven Watanabe 2018
  3. # Distributed under the Boost Software License, Version 1.0. (See
  4. # accompanying file LICENSE.txt or copy at
  5. # https://www.bfgroup.xyz/b2/LICENSE.txt)
  6. # Tests the check-has-flag rule
  7. import BoostBuild
  8. t = BoostBuild.Tester(use_test_config=False)
  9. # We need an object file before we can run the actual test.
  10. t.write('input.cpp', 'void f() {}\n')
  11. t.write('Jamroot.jam', 'obj input : input.cpp ;')
  12. t.run_build_system()
  13. linker_input = t.glob_file('bin/$toolset/debug*/input.obj')
  14. # Check every possible result of pass or fail.
  15. t.write('Jamroot.jam', '''
  16. import flags ;
  17. import modules ;
  18. OBJECT_FILE = [ modules.peek : OBJECT_FILE ] ;
  19. obj fail_cpp : test.cpp : [ check-has-flag <cxxflags>--illegal-flag-cpp
  20. : <define>ERROR : <define>OK ] ;
  21. obj pass_cpp : test.cpp : [ check-has-flag <cxxflags>-DMACRO_CPP
  22. : <define>OK : <define>ERROR ] ;
  23. obj fail_c : test.cpp : [ check-has-flag <cflags>--illegal-flag-c
  24. : <define>ERROR : <define>OK ] ;
  25. obj pass_c : test.cpp : [ check-has-flag <cflags>-DMACRO_C
  26. : <define>OK : <define>ERROR ] ;
  27. obj fail_link : test.cpp : [ check-has-flag <linkflags>--illegal-flag-link
  28. : <define>ERROR : <define>OK ] ;
  29. # The only thing that we can be certain the linker
  30. # will accept is the name of an object file.
  31. obj pass_link : test.cpp : [ check-has-flag <linkflags>$(OBJECT_FILE)
  32. : <define>OK : <define>ERROR ] ;
  33. ''')
  34. t.write('test.cpp', '''
  35. #ifdef ERROR
  36. #error ERROR defined
  37. #endif
  38. #ifndef OK
  39. #error ERROR not defined
  40. #endif
  41. ''')
  42. # Don't check the status immediately, so that we have a chance
  43. # to print config.log. Also, we need a minimum of d2 to make
  44. # sure that we always see the commands and output.
  45. t.run_build_system(['-sOBJECT_FILE=' + linker_input, '-d2'], status=None)
  46. if t.status != 0:
  47. log_file = t.read('bin/config.log')
  48. BoostBuild.annotation("config.log", log_file)
  49. t.fail_test(True)
  50. t.expect_output_lines([' - has --illegal-flag-cpp : no*',
  51. ' - has -DMACRO_CPP : yes*',
  52. ' - has --illegal-flag-c : no*',
  53. ' - has -DMACRO_C : yes*',
  54. ' - has --illegal-flag-link : no*',
  55. ' - has *bin*/input.* : yes*'])
  56. t.expect_addition('bin/$toolset/debug*/fail_cpp.obj')
  57. t.expect_addition('bin/$toolset/debug*/pass_cpp.obj')
  58. t.expect_addition('bin/$toolset/debug*/fail_c.obj')
  59. t.expect_addition('bin/$toolset/debug*/pass_c.obj')
  60. t.expect_addition('bin/$toolset/debug*/fail_link.obj')
  61. t.expect_addition('bin/$toolset/debug*/pass_link.obj')
  62. t.cleanup()