alias.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/python
  2. # Copyright 2003 Dave Abrahams
  3. # Copyright 2003 Vladimir Prus
  4. # Distributed under the Boost Software License, Version 1.0.
  5. # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
  6. import BoostBuild
  7. ###############################################################################
  8. #
  9. # test_alias_rule()
  10. # -----------------
  11. #
  12. ###############################################################################
  13. def test_alias_rule(t):
  14. """Basic alias rule test."""
  15. t.write("jamroot.jam", """\
  16. exe a : a.cpp ;
  17. exe b : b.cpp ;
  18. exe c : c.cpp ;
  19. alias bin1 : a ;
  20. alias bin2 : a b ;
  21. alias src : s.cpp ;
  22. exe hello : hello.cpp src ;
  23. """)
  24. t.write("a.cpp", "int main() {}\n")
  25. t.copy("a.cpp", "b.cpp")
  26. t.copy("a.cpp", "c.cpp")
  27. t.copy("a.cpp", "hello.cpp")
  28. t.write("s.cpp", "")
  29. # Check that targets to which "bin1" refers are updated, and only those.
  30. t.run_build_system(["bin1"])
  31. t.expect_addition(BoostBuild.List("bin/$toolset/debug*/") * "a.exe a.obj")
  32. t.ignore_addition('bin/*/a.rsp')
  33. t.ignore_addition('bin/*/a.*.rsp')
  34. t.expect_nothing_more()
  35. # Try again with "bin2"
  36. t.run_build_system(["bin2"])
  37. t.expect_addition(BoostBuild.List("bin/$toolset/debug*/") * "b.exe b.obj")
  38. t.ignore_addition('bin/*/b.rsp')
  39. t.ignore_addition('bin/*/b.*.rsp')
  40. t.expect_nothing_more()
  41. # Try building everything, making sure 'hello' target is created.
  42. t.run_build_system()
  43. t.expect_addition(BoostBuild.List("bin/$toolset/debug*/") * \
  44. "hello.exe hello.obj")
  45. t.ignore_addition('bin/*/hello.rsp')
  46. t.ignore_addition('bin/*/hello.*.rsp')
  47. t.expect_addition("bin/$toolset/debug*/s.obj")
  48. t.ignore_addition('bin/*/s.*.rsp')
  49. t.expect_addition(BoostBuild.List("bin/$toolset/debug*/") * "c.exe c.obj")
  50. t.ignore_addition('bin/*/c.rsp')
  51. t.ignore_addition('bin/*/c.*.rsp')
  52. t.expect_nothing_more()
  53. ###############################################################################
  54. #
  55. # test_alias_source_usage_requirements()
  56. # --------------------------------------
  57. #
  58. ###############################################################################
  59. def test_alias_source_usage_requirements(t):
  60. """
  61. Check whether usage requirements are propagated via "alias". In case they
  62. are not, linking will fail as there will be no main() function defined
  63. anywhere in the source.
  64. """
  65. t.write("jamroot.jam", """\
  66. lib l : l.cpp : : : <define>WANT_MAIN ;
  67. alias la : l ;
  68. exe main : main.cpp la ;
  69. """)
  70. t.write("l.cpp", """\
  71. void
  72. #if defined(_WIN32)
  73. __declspec(dllexport)
  74. #endif
  75. foo() {}
  76. """)
  77. t.write("main.cpp", """\
  78. #ifdef WANT_MAIN
  79. int main() {}
  80. #endif
  81. """)
  82. t.run_build_system()
  83. ###############################################################################
  84. #
  85. # main()
  86. # ------
  87. #
  88. ###############################################################################
  89. t = BoostBuild.Tester(use_test_config=False)
  90. test_alias_rule(t)
  91. test_alias_source_usage_requirements(t)
  92. t.cleanup()