clean.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/python
  2. # Copyright (C) Vladimir Prus 2006.
  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. import BoostBuild
  7. t = BoostBuild.Tester(use_test_config=False)
  8. t.write("a.cpp", "int main() {}\n")
  9. t.write("jamroot.jam", "exe a : a.cpp sub1//sub1 sub2//sub2 sub3//sub3 ;")
  10. t.write("sub1/jamfile.jam", """\
  11. lib sub1 : sub1.cpp sub1_2 ../sub2//sub2 ;
  12. lib sub1_2 : sub1_2.cpp ;
  13. """)
  14. t.write("sub1/sub1.cpp", """\
  15. #ifdef _WIN32
  16. __declspec(dllexport)
  17. #endif
  18. void sub1() {}
  19. """)
  20. t.write("sub1/sub1_2.cpp", """\
  21. #ifdef _WIN32
  22. __declspec(dllexport)
  23. #endif
  24. void sub1() {}
  25. """)
  26. t.write("sub2/jamfile.jam", "lib sub2 : sub2.cpp ;")
  27. t.write("sub2/sub2.cpp", """\
  28. #ifdef _WIN32
  29. __declspec(dllexport)
  30. #endif
  31. void sub2() {}
  32. """)
  33. t.write("sub3/jamroot.jam", "lib sub3 : sub3.cpp ;")
  34. t.write("sub3/sub3.cpp", """\
  35. #ifdef _WIN32
  36. __declspec(dllexport)
  37. #endif
  38. void sub3() {}
  39. """)
  40. # 'clean' should not remove files under separate jamroot.jam.
  41. t.run_build_system()
  42. t.run_build_system(["--clean"])
  43. t.expect_removal("bin/$toolset/debug*/a.obj")
  44. t.expect_removal("sub1/bin/$toolset/debug*/sub1.obj")
  45. t.expect_removal("sub1/bin/$toolset/debug*/sub1_2.obj")
  46. t.expect_removal("sub2/bin/$toolset/debug*/sub2.obj")
  47. t.expect_nothing("sub3/bin/$toolset/debug*/sub3.obj")
  48. # 'clean-all' removes everything it can reach.
  49. t.run_build_system()
  50. t.run_build_system(["--clean-all"])
  51. t.expect_removal("bin/$toolset/debug*/a.obj")
  52. t.expect_removal("sub1/bin/$toolset/debug*/sub1.obj")
  53. t.expect_removal("sub1/bin/$toolset/debug*/sub1_2.obj")
  54. t.expect_removal("sub2/bin/$toolset/debug*/sub2.obj")
  55. t.expect_nothing("sub3/bin/$toolset/debug*/sub3.obj")
  56. # 'clean' together with project target removes only under that project.
  57. t.run_build_system()
  58. t.run_build_system(["sub1", "--clean"])
  59. t.expect_nothing("bin/$toolset/debug*/a.obj")
  60. t.expect_removal("sub1/bin/$toolset/debug*/sub1.obj")
  61. t.expect_removal("sub1/bin/$toolset/debug*/sub1_2.obj")
  62. t.expect_nothing("sub2/bin/$toolset/debug*/sub2.obj")
  63. t.expect_nothing("sub3/bin/$toolset/debug*/sub3.obj")
  64. # 'clean-all' removes everything.
  65. t.run_build_system()
  66. t.run_build_system(["sub1", "--clean-all"])
  67. t.expect_nothing("bin/$toolset/debug*/a.obj")
  68. t.expect_removal("sub1/bin/$toolset/debug*/sub1.obj")
  69. t.expect_removal("sub1/bin/$toolset/debug*/sub1_2.obj")
  70. t.expect_removal("sub2/bin/$toolset/debug*/sub2.obj")
  71. t.expect_nothing("sub3/bin/$toolset/debug*/sub3.obj")
  72. # If main target is explicitly named, we should not remove files from other
  73. # targets.
  74. t.run_build_system()
  75. t.run_build_system(["sub1//sub1", "--clean"])
  76. t.expect_removal("sub1/bin/$toolset/debug*/sub1.obj")
  77. t.expect_nothing("sub1/bin/$toolset/debug*/sub1_2.obj")
  78. t.expect_nothing("sub2/bin/$toolset/debug*/sub2.obj")
  79. t.expect_nothing("sub3/bin/$toolset/debug*/sub3.obj")
  80. # Regression test: sources of the 'cast' rule were mistakenly deleted.
  81. t.rm(".")
  82. t.write("jamroot.jam", """\
  83. import cast ;
  84. cast a cpp : a.h ;
  85. """)
  86. t.write("a.h", "")
  87. t.run_build_system(["--clean"])
  88. t.expect_nothing("a.h")
  89. t.cleanup()