build_dir.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/python
  2. # Copyright 2003 Dave Abrahams
  3. # Copyright 2002, 2003, 2005 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. # Test that we can change build directory using the 'build-dir' project
  7. # attribute.
  8. import BoostBuild
  9. import string
  10. import os
  11. t = BoostBuild.Tester(use_test_config=False)
  12. # Test that top-level project can affect build dir.
  13. t.write("jamroot.jam", "import gcc ;")
  14. t.write("jamfile.jam", """\
  15. project : build-dir build ;
  16. exe a : a.cpp ;
  17. build-project src ;
  18. """)
  19. t.write("a.cpp", "int main() {}\n")
  20. t.write("src/jamfile.jam", "exe b : b.cpp ; ")
  21. t.write("src/b.cpp", "int main() {}\n")
  22. t.run_build_system()
  23. t.expect_addition(["build/$toolset/debug*/a.exe",
  24. "build/src/$toolset/debug*/b.exe"])
  25. # Test that building from child projects work.
  26. t.run_build_system(subdir='src')
  27. t.ignore("build/config.log")
  28. t.ignore("build/project-cache.jam")
  29. t.expect_nothing_more()
  30. # Test that project can override build dir.
  31. t.write("jamfile.jam", """\
  32. exe a : a.cpp ;
  33. build-project src ;
  34. """)
  35. t.write("src/jamfile.jam", """\
  36. project : build-dir build ;
  37. exe b : b.cpp ;
  38. """)
  39. t.run_build_system()
  40. t.expect_addition(["bin/$toolset/debug*/a.exe",
  41. "src/build/$toolset/debug*/b.exe"])
  42. # Now test the '--build-dir' option.
  43. t.rm(".")
  44. t.write("jamroot.jam", "")
  45. # Test that we get an error when no project id is specified.
  46. t.run_build_system(["--build-dir=foo"])
  47. t.fail_test(t.stdout().find(
  48. "warning: the --build-dir option will be ignored") == -1)
  49. t.write("jamroot.jam", """\
  50. project foo ;
  51. exe a : a.cpp ;
  52. build-project sub ;
  53. """)
  54. t.write("a.cpp", "int main() {}\n")
  55. t.write("sub/jamfile.jam", "exe b : b.cpp ;\n")
  56. t.write("sub/b.cpp", "int main() {}\n")
  57. t.run_build_system(["--build-dir=build"])
  58. t.expect_addition(["build/foo/$toolset/debug*/a.exe",
  59. "build/foo/sub/$toolset/debug*/b.exe"])
  60. t.write("jamroot.jam", """\
  61. project foo : build-dir bin.v2 ;
  62. exe a : a.cpp ;
  63. build-project sub ;
  64. """)
  65. t.run_build_system(["--build-dir=build"])
  66. t.expect_addition(["build/foo/bin.v2/$toolset/debug*/a.exe",
  67. "build/foo/bin.v2/sub/$toolset/debug*/b.exe"])
  68. # Try building in subdir. We expect that the entire build tree with be in
  69. # 'sub/build'. Today, I am not sure if this is what the user expects, but let
  70. # it be.
  71. t.rm('build')
  72. t.run_build_system(["--build-dir=build"], subdir="sub")
  73. t.expect_addition(["sub/build/foo/bin.v2/sub/$toolset/debug*/b.exe"])
  74. t.write("jamroot.jam", """\
  75. project foo : build-dir %s ;
  76. exe a : a.cpp ;
  77. build-project sub ;
  78. """ % os.getcwd().replace('\\', '\\\\'))
  79. t.run_build_system(["--build-dir=build"], status=1)
  80. t.fail_test(t.stdout().find(
  81. "Absolute directory specified via 'build-dir' project attribute") == -1)
  82. t.cleanup()