expansion.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/usr/bin/python
  2. # Copyright 2003 Vladimir Prus
  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. import BoostBuild
  6. t = BoostBuild.Tester(arguments=["--config="], pass_toolset=0)
  7. t.write("source.input", "")
  8. t.write("test-properties.jam", """
  9. import feature : feature ;
  10. import generators ;
  11. import toolset ;
  12. import type ;
  13. # We're not using the toolset at all, and we want to
  14. # suppress toolset initialization to avoid surprises.
  15. feature.extend toolset : null ;
  16. type.register CHECK : check ;
  17. type.register INPUT : input ;
  18. feature expected-define : : free ;
  19. feature unexpected-define : : free ;
  20. toolset.flags test-properties DEFINES : <define> ;
  21. toolset.flags test-properties EXPECTED : <expected-define> ;
  22. toolset.flags test-properties UNEXPECTED : <unexpected-define> ;
  23. generators.register-standard test-properties.check : INPUT : CHECK ;
  24. rule check ( target : source : properties * )
  25. {
  26. local defines = [ on $(target) return $(DEFINES) ] ;
  27. for local macro in [ on $(target) return $(EXPECTED) ]
  28. {
  29. if ! ( $(macro) in $(defines) )
  30. {
  31. EXIT expected $(macro) for $(target) in $(properties) : 1 ;
  32. }
  33. }
  34. for local macro in [ on $(target) return $(UNEXPECTED) ]
  35. {
  36. if $(macro) in $(defines)
  37. {
  38. EXIT unexpected $(macro) for $(target) in $(properties) : 1 ;
  39. }
  40. }
  41. }
  42. actions check
  43. {
  44. echo okay > $(<)
  45. }
  46. """)
  47. t.write("jamfile.jam", """
  48. import test-properties ;
  49. # See if default value of composite feature 'cf' will be expanded to
  50. # <define>CF_IS_OFF.
  51. check a : source.input : <expected-define>CF_IS_OFF ;
  52. # See if subfeature in requirements in expanded.
  53. check b : source.input : <cf>on-1
  54. <expected-define>CF_1 <unexpected-define>CF_IS_OFF ;
  55. # See if conditional requirements are recursively expanded.
  56. check c : source.input : <toolset>null:<variant>release
  57. <variant>release:<define>FOO <expected-define>FOO
  58. ;
  59. # Composites specified in the default build should not
  60. # be expanded if they are overridden in the the requirements.
  61. check d : source.input : <cf>on <unexpected-define>CF_IS_OFF : <cf>off ;
  62. # Overriding a feature should clear subfeatures and
  63. # apply default values of subfeatures.
  64. check e : source.input : <cf>always
  65. <unexpected-define>CF_IS_OFF <expected-define>CF_2 <unexpected-define>CF_1
  66. : <cf>on-1 ;
  67. # Subfeatures should not be changed if the parent feature doesn't change
  68. check f : source.input : <cf>on <expected-define>CF_1 : <cf>on-1 ;
  69. # If a subfeature is not specific to the value of the parent feature,
  70. # then changing the parent value should not clear the subfeature.
  71. check g : source.input : <fopt>off <expected-define>FOPT_2 : <fopt>on-2 ;
  72. # If the default value of a composite feature adds an optional
  73. # feature which has a subfeature with a default, then that
  74. # default should be added.
  75. check h : source.input : <expected-define>CX_2 ;
  76. # If the default value of a feature is used, then the
  77. # default value of its subfeatures should also be used.
  78. check i : source.input : <expected-define>SF_1 ;
  79. # Subfeatures should be expanded when listed in a
  80. # target reference.
  81. check j-impl : source.input : <expected-define>CF_1 ;
  82. explicit j-impl ;
  83. alias j : j-impl/<cf>on-1 ;
  84. """)
  85. t.write("jamroot.jam", """
  86. import feature ;
  87. feature.feature cf : off on always : composite incidental ;
  88. feature.compose <cf>off : <define>CF_IS_OFF ;
  89. feature.subfeature cf on : version : 1 2 : composite optional incidental ;
  90. feature.compose <cf-on:version>1 : <define>CF_1 ;
  91. feature.subfeature cf always : version : 1 2 : composite incidental ;
  92. feature.compose <cf-always:version>1 : <define>CF_2 ;
  93. feature.feature fopt : on off : optional incidental ;
  94. feature.subfeature fopt : version : 1 2 : composite incidental ;
  95. feature.compose <fopt-version>2 : <define>FOPT_2 ;
  96. feature.feature cx1 : on : composite incidental ;
  97. feature.feature cx2 : on : optional incidental ;
  98. feature.subfeature cx2 on : sub : 1 : composite incidental ;
  99. feature.compose <cx1>on : <cx2>on ;
  100. feature.compose <cx2-on:sub>1 : <define>CX_2 ;
  101. feature.feature sf : a : incidental ;
  102. feature.subfeature sf a : sub : 1 : composite incidental ;
  103. feature.compose <sf-a:sub>1 : <define>SF_1 ;
  104. """)
  105. t.expand_toolset("jamfile.jam")
  106. t.run_build_system()
  107. t.expect_addition(["bin/debug/a.check",
  108. "bin/debug/b.check",
  109. "bin/null/release/c.check",
  110. "bin/debug/d.check",
  111. "bin/debug/e.check",
  112. "bin/debug/f.check",
  113. "bin/debug/g.check",
  114. "bin/debug/h.check",
  115. "bin/debug/i.check"])
  116. t.cleanup()