TestToolset.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/python
  2. #
  3. # Copyright 2017 Steven Watanabe
  4. #
  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. # validates a toolset using a mock of the compiler
  9. import BoostBuild
  10. import os
  11. import re
  12. import sys
  13. renames = {"debug": "variant=debug", "release": "variant=release"}
  14. def set_default_target_os(os):
  15. global removed
  16. global default_target_os
  17. default_target_os = os
  18. removed = set()
  19. removed.add("target-os=" + default_target_os)
  20. def adjust_property(property):
  21. global renames
  22. if property in renames:
  23. return renames[property]
  24. else:
  25. return property
  26. def adjust_properties(properties):
  27. global removed
  28. return [adjust_property(p) for p in properties if p not in removed]
  29. def has_property(name, properties):
  30. return name in [re.sub("=.*", "", p) for p in properties]
  31. def get_property(name, properties):
  32. for m in [re.match("(.*)=(.*)", p) for p in properties]:
  33. if m and m.group(1) == name:
  34. return m.group(2)
  35. def get_target_os(properties):
  36. return get_property("target-os", properties) or default_target_os
  37. def expand_properties(properties):
  38. result = properties[:]
  39. if not has_property("variant", properties):
  40. result += ["variant=debug"]
  41. if not has_property("threading", properties):
  42. result += ["threading=single"]
  43. if not has_property("exception-handling", properties):
  44. result += ["exception-handling=on"]
  45. if not has_property("link", properties):
  46. result += ["link=shared"]
  47. if not has_property("rtti", properties):
  48. result += ["rtti=on"]
  49. if not has_property("runtime-link", properties):
  50. result += ["runtime-link=shared"]
  51. if not has_property("strip", properties):
  52. result += ["strip=off"]
  53. if not has_property("target-os", properties):
  54. result += ["target-os=" + default_target_os]
  55. return result
  56. def compute_path(properties, target_type):
  57. path = ""
  58. if "variant=release" in properties:
  59. path += "/release"
  60. else:
  61. path += "/debug"
  62. if has_property("address-model", properties):
  63. path += "/address-model-" + get_property("address-model", properties)
  64. if has_property("architecture", properties):
  65. path += "/architecture-" + get_property("architecture", properties)
  66. if "cxxstd=latest" in properties:
  67. path += "/cxxstd-latest-iso"
  68. if "exception-handling=off" in properties:
  69. path += "/exception-handling-off"
  70. if "link=static" in properties:
  71. path += "/link-static"
  72. if "rtti=off" in properties:
  73. path += "/rtti-off"
  74. if "runtime-link=static" in properties and target_type in ["exe"]:
  75. path += "/runtime-link-static"
  76. if "strip=on" in properties and target_type in ["dll", "exe", "obj2"]:
  77. path += "/strip-on"
  78. if get_target_os(properties) != default_target_os:
  79. path += "/target-os-" + get_target_os(properties)
  80. if "threading=multi" in properties:
  81. path += "/threading-multi"
  82. return path
  83. def test_toolset(toolset, version, property_sets):
  84. t = BoostBuild.Tester()
  85. t.set_tree("toolset-mock")
  86. # Build necessary tools
  87. t.run_build_system(["-sPYTHON_CMD=%s" % sys.executable], subdir="src")
  88. set_default_target_os(t.read("src/bin/target-os.txt").strip())
  89. for properties in property_sets:
  90. t.set_toolset(toolset + "-" + version, get_target_os(properties))
  91. properties = adjust_properties(properties)
  92. def path(t):
  93. return toolset.split("-")[0] + "-*" + version + compute_path(properties, t)
  94. os.environ["B2_PROPERTIES"] = " ".join(expand_properties(properties))
  95. t.run_build_system(["--user-config=", "-sPYTHON_CMD=%s" % sys.executable] + properties)
  96. t.expect_addition("bin/%s/lib.obj" % (path("obj")))
  97. if "link=static" not in properties:
  98. t.expect_addition("bin/%s/l1.dll" % (path("dll")))
  99. t.ignore_addition("bin/%s/*l1.*.rsp" % (path("dll")))
  100. else:
  101. t.expect_addition("bin/%s/l1.lib" % (path("lib")))
  102. t.expect_addition("bin/%s/main.obj" % (path("obj2")))
  103. t.expect_addition("bin/%s/test.exe" % (path("exe")))
  104. t.ignore_addition("bin/%s/test.rsp" % (path("exe")))
  105. t.expect_nothing_more()
  106. t.rm("bin")
  107. t.cleanup()