package.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #!/usr/bin/python
  2. # Copyright 2018 Steven Watanabe
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
  5. # Test the package module.
  6. import BoostBuild
  7. import os
  8. def setup():
  9. t = BoostBuild.Tester(["p//install", "p//data"],
  10. use_test_config=False)
  11. t.write("p/jamroot.jam", "")
  12. t.write("p/jamfile.jam", """\
  13. import package ;
  14. exe a : a.cpp ;
  15. lib b : b.cpp ;
  16. package.install install Test :
  17. : a
  18. : b/<link>static b/<link>shared
  19. : a.h ;
  20. package.install-data data : Test : a.txt ;
  21. """)
  22. t.write("p/a.cpp", "int main() {}")
  23. t.write("p/b.cpp", """
  24. int
  25. #ifdef _WIN32
  26. __declspec(dllexport)
  27. #endif
  28. must_export_something;
  29. """)
  30. t.write("p/a.h", "")
  31. t.write("p/a.txt", "")
  32. return t
  33. def test_defaults():
  34. t = setup()
  35. # Since the default install location is outside out test area,
  36. # we don't want to actually execute the build.
  37. t.run_build_system(["-n", "-d1"])
  38. installdir = "C:/Test" if os.name == 'nt' else "/usr/local"
  39. t.expect_output_lines([
  40. x.replace('/', os.sep) for x in
  41. ["common.copy %s/bin/%s" % (installdir, t.adjust_name("a.exe")),
  42. "common.copy %s/lib/%s" % (installdir, t.adjust_name("b.dll")),
  43. "common.copy %s/lib/%s" % (installdir, t.adjust_name("b.lib")),
  44. "common.copy %s/include/a.h" % installdir,
  45. "common.copy %s/share/Test/a.txt" % installdir]])
  46. t.cleanup()
  47. def test_prefix():
  48. t = setup()
  49. # An explicit --prefix on the command should override all of these:
  50. t.write("project-config.jam", """
  51. option.set prefix : bad ;
  52. option.set bindir : bad/bin ;
  53. option.set libdir : bad/lib ;
  54. option.set includedir : bad/include ;
  55. option.set datarootdir : bad/share ;
  56. """)
  57. t.run_build_system(["--prefix=installdir"])
  58. t.expect_addition("installdir/bin/a.exe")
  59. t.expect_addition("installdir/lib/b.dll")
  60. t.expect_addition("installdir/lib/b.lib")
  61. t.expect_addition("installdir/include/a.h")
  62. t.expect_addition("installdir/share/Test/a.txt")
  63. t.cleanup()
  64. def test_subdirs():
  65. t = setup()
  66. # Command line options override config files
  67. t.write("project-config.jam", """
  68. option.set prefix : bad ;
  69. option.set bindir : bad/bin ;
  70. option.set libdir : bad/lib ;
  71. option.set includedir : bad/include ;
  72. option.set datarootdir : bad/share ;
  73. """)
  74. t.run_build_system(["--libdir=installdir/lib64",
  75. "--bindir=installdir/binx",
  76. "--includedir=installdir/includex",
  77. "--datarootdir=installdir/sharex"])
  78. t.expect_addition("installdir/binx/a.exe")
  79. t.expect_addition("installdir/lib64/b.dll")
  80. t.expect_addition("installdir/lib64/b.lib")
  81. t.expect_addition("installdir/includex/a.h")
  82. t.expect_addition("installdir/sharex/Test/a.txt")
  83. t.cleanup()
  84. def test_subdirs_with_prefix():
  85. t = setup()
  86. # Command line options override config files
  87. t.write("project-config.jam", """
  88. option.set prefix : bad ;
  89. option.set bindir : bad/bin ;
  90. option.set libdir : bad/lib ;
  91. option.set includedir : bad/include ;
  92. option.set datarootdir : bad/share ;
  93. """)
  94. t.run_build_system(["--prefix=bad",
  95. "--libdir=installdir/lib64",
  96. "--bindir=installdir/binx",
  97. "--includedir=installdir/includex",
  98. "--datarootdir=installdir/sharex"])
  99. t.expect_addition("installdir/binx/a.exe")
  100. t.expect_addition("installdir/lib64/b.dll")
  101. t.expect_addition("installdir/lib64/b.lib")
  102. t.expect_addition("installdir/includex/a.h")
  103. t.expect_addition("installdir/sharex/Test/a.txt")
  104. t.cleanup()
  105. def test_prefix_config_file():
  106. t = setup()
  107. # An explicit --prefix on the command should override all of these:
  108. t.write("project-config.jam", """
  109. option.set prefix : installdir ;
  110. """)
  111. t.run_build_system()
  112. t.expect_addition("installdir/bin/a.exe")
  113. t.expect_addition("installdir/lib/b.dll")
  114. t.expect_addition("installdir/lib/b.lib")
  115. t.expect_addition("installdir/include/a.h")
  116. t.expect_addition("installdir/share/Test/a.txt")
  117. t.cleanup()
  118. def test_subdirs_config_file():
  119. t = setup()
  120. # An explicit --prefix on the command should override all of these:
  121. t.write("project-config.jam", """
  122. option.set prefix : installdir ;
  123. option.set libdir : installdir/lib64 ;
  124. option.set bindir : installdir/binx ;
  125. option.set includedir : installdir/includex ;
  126. option.set datarootdir : installdir/sharex ;
  127. """)
  128. t.run_build_system()
  129. t.expect_addition("installdir/binx/a.exe")
  130. t.expect_addition("installdir/lib64/b.dll")
  131. t.expect_addition("installdir/lib64/b.lib")
  132. t.expect_addition("installdir/includex/a.h")
  133. t.expect_addition("installdir/sharex/Test/a.txt")
  134. t.cleanup()
  135. def test_multiple():
  136. '''If no prefix is specified, we might use several default
  137. install prefixes.'''
  138. t = BoostBuild.Tester(use_test_config=False)
  139. t.write("p/jamroot.jam", "")
  140. t.write("p/jamfile.jam", """\
  141. import package ;
  142. exe a : a.cpp ;
  143. lib b : b.cpp ;
  144. package.install installx TestX : <install-default-prefix>xxx
  145. : a
  146. : b/<link>static b/<link>shared
  147. : a.h ;
  148. package.install instally TestY : <install-default-prefix>yyy
  149. : a
  150. : b/<link>static b/<link>shared
  151. : a.h ;
  152. """)
  153. t.write("p/a.cpp", "int main() {}")
  154. t.write("p/b.cpp", """
  155. int
  156. #ifdef _WIN32
  157. __declspec(dllexport)
  158. #endif
  159. must_export_something;
  160. """)
  161. t.write("p/a.h", "")
  162. t.run_build_system(["p//installx", "p//instally"])
  163. t.expect_addition("p/xxx/bin/a.exe")
  164. t.expect_addition("p/xxx/lib/b.dll")
  165. t.expect_addition("p/xxx/lib/b.lib")
  166. t.expect_addition("p/xxx/include/a.h")
  167. t.expect_addition("p/yyy/bin/a.exe")
  168. t.expect_addition("p/yyy/lib/b.dll")
  169. t.expect_addition("p/yyy/lib/b.lib")
  170. t.expect_addition("p/yyy/include/a.h")
  171. def test_paths():
  172. t = BoostBuild.Tester(pass_toolset=False)
  173. t.write("Jamroot.jam", """\
  174. import package ;
  175. import assert ;
  176. import os ;
  177. if [ os.name ] = NT
  178. {
  179. default-prefix = "/C:/Test" ;
  180. }
  181. else
  182. {
  183. default-prefix = /usr/local ;
  184. }
  185. paths = [ package.paths Test ] ;
  186. assert.result $(default-prefix) : $(paths).prefix ;
  187. assert.result $(default-prefix)/lib : $(paths).libdir ;
  188. assert.result $(default-prefix)/bin : $(paths).bindir ;
  189. assert.result $(default-prefix)/include : $(paths).includedir ;
  190. assert.result $(default-prefix)/share : $(paths).datarootdir ;
  191. package.add-path-option bardir : bar : libdir ;
  192. assert.result $(default-prefix)/lib/bar : $(paths).get bardir ;
  193. """)
  194. t.run_build_system()
  195. t.cleanup()
  196. test_defaults()
  197. test_prefix()
  198. test_subdirs()
  199. test_subdirs_with_prefix()
  200. test_prefix_config_file()
  201. test_subdirs_config_file()
  202. test_multiple()
  203. test_paths()