module_actions.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/python
  2. # Copyright 2003 Dave Abrahams
  3. # Copyright 2006 Rene Rivera
  4. # Copyright 2003 Vladimir Prus
  5. # Distributed under the Boost Software License, Version 1.0.
  6. # (See accompanying file LICENSE.txt or copy at
  7. # https://www.bfgroup.xyz/b2/LICENSE.txt)
  8. # Demonstration that module variables have the correct effect in actions.
  9. import BoostBuild
  10. import os
  11. import re
  12. t = BoostBuild.Tester(["-d+1"], pass_toolset=0)
  13. t.write("boost-build.jam", "boost-build . ;")
  14. t.write("bootstrap.jam", """\
  15. # Top-level rule causing a target to be built by invoking the specified action.
  16. rule make ( target : sources * : act )
  17. {
  18. DEPENDS all : $(target) ;
  19. DEPENDS $(target) : $(sources) ;
  20. $(act) $(target) : $(sources) ;
  21. }
  22. X1 = X1-global ;
  23. X2 = X2-global ;
  24. X3 = X3-global ;
  25. module A
  26. {
  27. X1 = X1-A ;
  28. rule act ( target )
  29. {
  30. NOTFILE $(target) ;
  31. ALWAYS $(target) ;
  32. }
  33. actions act { echo A.act $(<): $(X1) $(X2) $(X3) }
  34. make t1 : : A.act ;
  35. make t2 : : A.act ;
  36. make t3 : : A.act ;
  37. }
  38. module B
  39. {
  40. X2 = X2-B ;
  41. actions act { echo B.act $(<): $(X1) $(X2) $(X3) }
  42. make t1 : : B.act ;
  43. make t2 : : B.act ;
  44. make t3 : : B.act ;
  45. }
  46. actions act { echo act $(<): $(X1) $(X2) $(X3) }
  47. make t1 : : act ;
  48. make t2 : : act ;
  49. make t3 : : act ;
  50. X1 on t1 = X1-t1 ;
  51. X2 on t2 = X2-t2 ;
  52. X3 on t3 = X3-t3 ;
  53. DEPENDS all : t1 t2 t3 ;
  54. """)
  55. expected_lines = [
  56. "...found 4 targets...",
  57. "...updating 3 targets...",
  58. "A.act t1",
  59. "A.act t1: X1-t1 ",
  60. "B.act t1",
  61. "B.act t1: X1-t1 X2-B ",
  62. "act t1",
  63. "act t1: X1-t1 X2-global X3-global ",
  64. "A.act t2",
  65. "A.act t2: X1-A X2-t2 ",
  66. "B.act t2",
  67. "B.act t2: X2-t2 ",
  68. "act t2",
  69. "act t2: X1-global X2-t2 X3-global ",
  70. "A.act t3",
  71. "A.act t3: X1-A X3-t3 ",
  72. "B.act t3",
  73. "B.act t3: X2-B X3-t3 ",
  74. "act t3",
  75. "act t3: X1-global X2-global X3-t3 ",
  76. "...updated 3 targets...",
  77. ""]
  78. # Accommodate for the fact that on Unixes, a call to 'echo 1 2 3 '
  79. # produces '1 2 3' (note the spacing).
  80. if os.name != 'nt':
  81. expected_lines = [re.sub(" +", " ", x.rstrip()) for x in expected_lines]
  82. t.run_build_system()
  83. t.expect_output_lines(expected_lines)
  84. t.expect_nothing_more()
  85. t.cleanup()