unused.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/python
  2. # Copyright 2003 Vladimir Prus
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE.txt or copy at
  5. # https://www.bfgroup.xyz/b2/LICENSE.txt)
  6. # Test that unused sources are at least reported.
  7. import BoostBuild
  8. t = BoostBuild.Tester(["-d+2"], use_test_config=False)
  9. t.write("a.cpp", "int main() {}\n")
  10. t.write("b.cpp", "\n")
  11. t.write("b.xyz", "")
  12. t.write("jamroot.jam", """\
  13. import "class" : new ;
  14. import modules ;
  15. import project ;
  16. import targets ;
  17. import type ;
  18. import virtual-target ;
  19. type.register X : xyz ;
  20. class test-target-class : basic-target
  21. {
  22. rule construct ( name : source-targets * : property-set )
  23. {
  24. local result = [ property-set.empty ] ;
  25. if ! [ modules.peek : GENERATE_NOTHING ]
  26. {
  27. result += [ virtual-target.from-file b.xyz : . : $(self.project) ] ;
  28. if ! [ modules.peek : GENERATE_ONLY_UNUSABLE ]
  29. {
  30. result += [ virtual-target.from-file b.cpp : . : $(self.project)
  31. ] ;
  32. }
  33. }
  34. return $(result) ;
  35. }
  36. rule compute-usage-requirements ( rproperties : targets * )
  37. {
  38. return [ property-set.create <define>FOO ] ;
  39. }
  40. }
  41. rule make-b-main-target
  42. {
  43. local project = [ project.current ] ;
  44. targets.main-target-alternative [ new test-target-class b : $(project) ] ;
  45. }
  46. exe a : a.cpp b c ;
  47. make-b-main-target ;
  48. alias c ; # Expands to nothing, intentionally.
  49. """)
  50. t.run_build_system()
  51. # The second invocation should do nothing, and produce no warning. The previous
  52. # invocation might have printed executed actions and other things, so it is not
  53. # easy to check if a warning was issued or not.
  54. t.run_build_system(stdout="")
  55. t.run_build_system(["-sGENERATE_ONLY_UNUSABLE=1"], stdout="")
  56. # Check that even if main target generates nothing, its usage requirements are
  57. # still propagated to dependants.
  58. t.write("a.cpp", """\
  59. #ifndef FOO
  60. #error We refuse to compile without FOO being defined!
  61. We_refuse_to_compile_without_FOO_being_defined
  62. #endif
  63. int main() {}
  64. """)
  65. t.run_build_system(["-sGENERATE_NOTHING=1"])
  66. t.cleanup()