@btc-vision/bitcoin 6.4.9 → 6.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/.babelrc +4 -4
  2. package/.mocharc.json +13 -13
  3. package/.prettierrc.json +12 -12
  4. package/CHANGELOG.md +403 -403
  5. package/CONTRIBUTING.md +83 -83
  6. package/LICENSE +21 -21
  7. package/README.md +201 -201
  8. package/browser/index.d.ts +1 -1
  9. package/browser/index.js +1 -1
  10. package/browser/{ops.d.ts → opcodes.d.ts} +2 -3
  11. package/browser/script.d.ts +2 -2
  12. package/build/address.js +2 -1
  13. package/build/index.d.ts +1 -1
  14. package/build/index.js +1 -1
  15. package/build/{ops.d.ts → opcodes.d.ts} +2 -3
  16. package/build/{ops.js → opcodes.js} +4 -5
  17. package/build/payments/embed.js +1 -1
  18. package/build/payments/p2ms.js +1 -1
  19. package/build/payments/p2op.js +1 -1
  20. package/build/payments/p2pk.js +1 -1
  21. package/build/payments/p2pkh.js +1 -1
  22. package/build/payments/p2sh.js +3 -3
  23. package/build/payments/p2tr.js +1 -1
  24. package/build/payments/p2wpkh.js +2 -2
  25. package/build/payments/p2wsh.js +2 -2
  26. package/build/push_data.js +9 -9
  27. package/build/script.d.ts +2 -2
  28. package/build/script.js +12 -12
  29. package/build/transaction.js +1 -1
  30. package/cjs/package.json +3 -3
  31. package/gulpfile.js +42 -42
  32. package/package.json +150 -150
  33. package/src/address.ts +304 -303
  34. package/src/bip66.ts +107 -107
  35. package/src/block.ts +233 -233
  36. package/src/bufferutils.ts +188 -188
  37. package/src/crypto.ts +108 -108
  38. package/src/ecc_lib.ts +94 -94
  39. package/src/hooks/AdvancedSignatureManager.ts +104 -104
  40. package/src/hooks/SignatureManager.ts +84 -84
  41. package/src/index.ts +105 -105
  42. package/src/merkle.ts +31 -31
  43. package/src/{ops.ts → opcodes.ts} +280 -282
  44. package/src/payments/bip341.ts +140 -140
  45. package/src/payments/embed.ts +61 -61
  46. package/src/payments/index.ts +172 -172
  47. package/src/payments/lazy.ts +28 -28
  48. package/src/payments/p2ms.ts +156 -156
  49. package/src/payments/p2op.ts +195 -195
  50. package/src/payments/p2pk.ts +93 -93
  51. package/src/payments/p2pkh.ts +214 -214
  52. package/src/payments/p2sh.ts +210 -210
  53. package/src/payments/p2tr.ts +309 -309
  54. package/src/payments/p2wpkh.ts +144 -144
  55. package/src/payments/p2wsh.ts +217 -217
  56. package/src/psbt/bip371.ts +441 -441
  57. package/src/push_data.ts +97 -97
  58. package/src/script.ts +247 -247
  59. package/src/script_number.ts +72 -72
  60. package/src/script_signature.ts +91 -91
  61. package/src/transaction.ts +656 -656
  62. package/test/address.spec.ts +155 -155
  63. package/test/bitcoin.core.spec.ts +212 -212
  64. package/test/block.spec.ts +171 -171
  65. package/test/bufferutils.spec.ts +450 -450
  66. package/test/crypto.spec.ts +49 -49
  67. package/test/fixtures/address.json +329 -329
  68. package/test/fixtures/block.json +148 -148
  69. package/test/fixtures/bufferutils.json +102 -102
  70. package/test/fixtures/core/README.md +26 -26
  71. package/test/fixtures/core/base58_encode_decode.json +50 -50
  72. package/test/fixtures/core/base58_keys_invalid.json +152 -152
  73. package/test/fixtures/core/base58_keys_valid.json +452 -452
  74. package/test/fixtures/core/blocks.json +27 -27
  75. package/test/fixtures/core/sig_canonical.json +7 -7
  76. package/test/fixtures/core/sig_noncanonical.json +33 -33
  77. package/test/fixtures/core/sighash.json +3505 -3505
  78. package/test/fixtures/core/tx_valid.json +2023 -2023
  79. package/test/fixtures/crypto.json +43 -43
  80. package/test/fixtures/ecdsa.json +217 -217
  81. package/test/fixtures/ecpair.json +141 -141
  82. package/test/fixtures/embed.json +108 -108
  83. package/test/fixtures/p2ms.json +434 -434
  84. package/test/fixtures/p2pk.json +179 -179
  85. package/test/fixtures/p2pkh.json +276 -276
  86. package/test/fixtures/p2sh.json +508 -508
  87. package/test/fixtures/p2tr.json +1198 -1198
  88. package/test/fixtures/p2wpkh.json +290 -290
  89. package/test/fixtures/p2wsh.json +489 -489
  90. package/test/fixtures/psbt.json +924 -924
  91. package/test/fixtures/script.json +465 -465
  92. package/test/fixtures/script_number.json +225 -225
  93. package/test/fixtures/signature.json +140 -140
  94. package/test/fixtures/transaction.json +916 -916
  95. package/test/integration/_regtest.ts +6 -6
  96. package/test/integration/addresses.spec.ts +142 -142
  97. package/test/integration/bip32.spec.ts +130 -130
  98. package/test/integration/blocks.spec.ts +28 -28
  99. package/test/integration/cltv.spec.ts +241 -241
  100. package/test/integration/csv.spec.ts +452 -452
  101. package/test/integration/payments.spec.ts +110 -110
  102. package/test/integration/taproot.spec.ts +663 -663
  103. package/test/integration/transactions.spec.ts +668 -668
  104. package/test/payments.spec.ts +114 -114
  105. package/test/payments.utils.ts +165 -165
  106. package/test/psbt.spec.ts +1285 -1285
  107. package/test/script.spec.ts +186 -186
  108. package/test/script_number.spec.ts +26 -26
  109. package/test/script_signature.spec.ts +66 -66
  110. package/test/transaction.spec.ts +337 -337
  111. package/test/ts-node-register.js +7 -7
  112. package/test/tsconfig.json +48 -48
  113. package/test/types.spec.ts +53 -53
  114. package/tsconfig.base.json +27 -27
  115. package/tsconfig.json +19 -19
  116. package/tsconfig.webpack.json +18 -18
  117. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.ready +0 -0
  118. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.release-please-manifest.json +0 -3
  119. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CHANGELOG.md +0 -962
  120. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CONTRIBUTING.md +0 -34
  121. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/LICENSE +0 -24
  122. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/README.md +0 -273
  123. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/SECURITY.md +0 -2
  124. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/addon.gypi +0 -204
  125. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/bin/node-gyp.js +0 -138
  126. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/.release-please-manifest.json +0 -3
  127. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/LICENSE +0 -28
  128. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/ninja/build.ninja +0 -4
  129. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +0 -12
  130. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/GypVsCMake.md +0 -116
  131. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Hacking.md +0 -46
  132. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/InputFormatReference.md +0 -1080
  133. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/LanguageSpecification.md +0 -430
  134. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/README.md +0 -27
  135. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Testing.md +0 -450
  136. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/UserDocumentation.md +0 -965
  137. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp +0 -8
  138. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp.bat +0 -5
  139. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp_main.py +0 -45
  140. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +0 -365
  141. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +0 -206
  142. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +0 -1272
  143. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +0 -1547
  144. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +0 -59
  145. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +0 -153
  146. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +0 -271
  147. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +0 -574
  148. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +0 -692
  149. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common.py +0 -711
  150. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +0 -171
  151. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +0 -169
  152. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +0 -113
  153. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +0 -55
  154. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  155. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +0 -804
  156. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +0 -1173
  157. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +0 -1318
  158. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +0 -127
  159. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +0 -103
  160. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +0 -461
  161. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +0 -89
  162. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +0 -57
  163. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +0 -2745
  164. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +0 -3976
  165. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +0 -44
  166. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +0 -2964
  167. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +0 -67
  168. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +0 -1391
  169. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +0 -25
  170. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input.py +0 -3115
  171. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +0 -98
  172. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +0 -771
  173. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +0 -1260
  174. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +0 -174
  175. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +0 -61
  176. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +0 -373
  177. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +0 -1938
  178. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +0 -53
  179. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +0 -302
  180. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +0 -3198
  181. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +0 -65
  182. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +0 -3
  183. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +0 -177
  184. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +0 -23
  185. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +0 -15
  186. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +0 -108
  187. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +0 -252
  188. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +0 -83
  189. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +0 -359
  190. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +0 -61
  191. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +0 -192
  192. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/markers.py +0 -252
  193. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +0 -825
  194. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  195. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +0 -90
  196. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +0 -1030
  197. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/tags.py +0 -553
  198. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/utils.py +0 -172
  199. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/version.py +0 -563
  200. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pyproject.toml +0 -120
  201. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/release-please-config.json +0 -11
  202. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/test_gyp.py +0 -261
  203. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/Find-VisualStudio.cs +0 -250
  204. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/build.js +0 -227
  205. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/clean.js +0 -15
  206. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/configure.js +0 -328
  207. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/create-config-gypi.js +0 -150
  208. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/download.js +0 -39
  209. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-node-directory.js +0 -63
  210. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-python.js +0 -310
  211. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-visualstudio.js +0 -590
  212. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/install.js +0 -415
  213. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/list.js +0 -26
  214. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/log.js +0 -168
  215. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/node-gyp.js +0 -188
  216. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/process-release.js +0 -146
  217. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/rebuild.js +0 -12
  218. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/remove.js +0 -43
  219. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/util.js +0 -81
  220. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/macOS_Catalina_acid_test.sh +0 -21
  221. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/package.json +0 -51
  222. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/release-please-config.json +0 -40
  223. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/src/win_delay_load_hook.cc +0 -39
  224. package/coverage/tmp/coverage-31752-1735543485354-0.json +0 -1
  225. package/coverage/tmp/coverage-59920-1735543484555-0.json +0 -1
  226. package/coverage/tmp/coverage-66252-1735543483919-0.json +0 -1
  227. package/coverage/tmp/coverage-68440-1735543485236-0.json +0 -1
  228. package/coverage/tmp/coverage-70588-1735543484426-0.json +0 -1
  229. package/coverage/tmp/coverage-79292-1735543485296-0.json +0 -1
  230. package/coverage/tmp/coverage-80212-1735543483980-0.json +0 -1
@@ -1,2964 +0,0 @@
1
- # Copyright (c) 2013 Google Inc. All rights reserved.
2
- # Use of this source code is governed by a BSD-style license that can be
3
- # found in the LICENSE file.
4
-
5
-
6
- import collections
7
- import copy
8
- import hashlib
9
- import json
10
- import multiprocessing
11
- import os.path
12
- import re
13
- import signal
14
- import shutil
15
- import subprocess
16
- import sys
17
- import gyp
18
- import gyp.common
19
- import gyp.msvs_emulation
20
- import gyp.MSVSUtil as MSVSUtil
21
- import gyp.xcode_emulation
22
-
23
- from io import StringIO
24
-
25
- from gyp.common import GetEnvironFallback
26
- import gyp.ninja_syntax as ninja_syntax
27
-
28
- generator_default_variables = {
29
- "EXECUTABLE_PREFIX": "",
30
- "EXECUTABLE_SUFFIX": "",
31
- "STATIC_LIB_PREFIX": "lib",
32
- "STATIC_LIB_SUFFIX": ".a",
33
- "SHARED_LIB_PREFIX": "lib",
34
- # Gyp expects the following variables to be expandable by the build
35
- # system to the appropriate locations. Ninja prefers paths to be
36
- # known at gyp time. To resolve this, introduce special
37
- # variables starting with $! and $| (which begin with a $ so gyp knows it
38
- # should be treated specially, but is otherwise an invalid
39
- # ninja/shell variable) that are passed to gyp here but expanded
40
- # before writing out into the target .ninja files; see
41
- # ExpandSpecial.
42
- # $! is used for variables that represent a path and that can only appear at
43
- # the start of a string, while $| is used for variables that can appear
44
- # anywhere in a string.
45
- "INTERMEDIATE_DIR": "$!INTERMEDIATE_DIR",
46
- "SHARED_INTERMEDIATE_DIR": "$!PRODUCT_DIR/gen",
47
- "PRODUCT_DIR": "$!PRODUCT_DIR",
48
- "CONFIGURATION_NAME": "$|CONFIGURATION_NAME",
49
- # Special variables that may be used by gyp 'rule' targets.
50
- # We generate definitions for these variables on the fly when processing a
51
- # rule.
52
- "RULE_INPUT_ROOT": "${root}",
53
- "RULE_INPUT_DIRNAME": "${dirname}",
54
- "RULE_INPUT_PATH": "${source}",
55
- "RULE_INPUT_EXT": "${ext}",
56
- "RULE_INPUT_NAME": "${name}",
57
- }
58
-
59
- # Placates pylint.
60
- generator_additional_non_configuration_keys = []
61
- generator_additional_path_sections = []
62
- generator_extra_sources_for_rules = []
63
- generator_filelist_paths = None
64
-
65
- generator_supports_multiple_toolsets = gyp.common.CrossCompileRequested()
66
-
67
-
68
- def StripPrefix(arg, prefix):
69
- if arg.startswith(prefix):
70
- return arg[len(prefix) :]
71
- return arg
72
-
73
-
74
- def QuoteShellArgument(arg, flavor):
75
- """Quote a string such that it will be interpreted as a single argument
76
- by the shell."""
77
- # Rather than attempting to enumerate the bad shell characters, just
78
- # allow common OK ones and quote anything else.
79
- if re.match(r"^[a-zA-Z0-9_=.\\/-]+$", arg):
80
- return arg # No quoting necessary.
81
- if flavor == "win":
82
- return gyp.msvs_emulation.QuoteForRspFile(arg)
83
- return "'" + arg.replace("'", "'" + '"\'"' + "'") + "'"
84
-
85
-
86
- def Define(d, flavor):
87
- """Takes a preprocessor define and returns a -D parameter that's ninja- and
88
- shell-escaped."""
89
- if flavor == "win":
90
- # cl.exe replaces literal # characters with = in preprocessor definitions for
91
- # some reason. Octal-encode to work around that.
92
- d = d.replace("#", "\\%03o" % ord("#"))
93
- return QuoteShellArgument(ninja_syntax.escape("-D" + d), flavor)
94
-
95
-
96
- def AddArch(output, arch):
97
- """Adds an arch string to an output path."""
98
- output, extension = os.path.splitext(output)
99
- return f"{output}.{arch}{extension}"
100
-
101
-
102
- class Target:
103
- """Target represents the paths used within a single gyp target.
104
-
105
- Conceptually, building a single target A is a series of steps:
106
-
107
- 1) actions/rules/copies generates source/resources/etc.
108
- 2) compiles generates .o files
109
- 3) link generates a binary (library/executable)
110
- 4) bundle merges the above in a mac bundle
111
-
112
- (Any of these steps can be optional.)
113
-
114
- From a build ordering perspective, a dependent target B could just
115
- depend on the last output of this series of steps.
116
-
117
- But some dependent commands sometimes need to reach inside the box.
118
- For example, when linking B it needs to get the path to the static
119
- library generated by A.
120
-
121
- This object stores those paths. To keep things simple, member
122
- variables only store concrete paths to single files, while methods
123
- compute derived values like "the last output of the target".
124
- """
125
-
126
- def __init__(self, type):
127
- # Gyp type ("static_library", etc.) of this target.
128
- self.type = type
129
- # File representing whether any input dependencies necessary for
130
- # dependent actions have completed.
131
- self.preaction_stamp = None
132
- # File representing whether any input dependencies necessary for
133
- # dependent compiles have completed.
134
- self.precompile_stamp = None
135
- # File representing the completion of actions/rules/copies, if any.
136
- self.actions_stamp = None
137
- # Path to the output of the link step, if any.
138
- self.binary = None
139
- # Path to the file representing the completion of building the bundle,
140
- # if any.
141
- self.bundle = None
142
- # On Windows, incremental linking requires linking against all the .objs
143
- # that compose a .lib (rather than the .lib itself). That list is stored
144
- # here. In this case, we also need to save the compile_deps for the target,
145
- # so that the target that directly depends on the .objs can also depend
146
- # on those.
147
- self.component_objs = None
148
- self.compile_deps = None
149
- # Windows only. The import .lib is the output of a build step, but
150
- # because dependents only link against the lib (not both the lib and the
151
- # dll) we keep track of the import library here.
152
- self.import_lib = None
153
- # Track if this target contains any C++ files, to decide if gcc or g++
154
- # should be used for linking.
155
- self.uses_cpp = False
156
-
157
- def Linkable(self):
158
- """Return true if this is a target that can be linked against."""
159
- return self.type in ("static_library", "shared_library")
160
-
161
- def UsesToc(self, flavor):
162
- """Return true if the target should produce a restat rule based on a TOC
163
- file."""
164
- # For bundles, the .TOC should be produced for the binary, not for
165
- # FinalOutput(). But the naive approach would put the TOC file into the
166
- # bundle, so don't do this for bundles for now.
167
- if flavor == "win" or self.bundle:
168
- return False
169
- return self.type in ("shared_library", "loadable_module")
170
-
171
- def PreActionInput(self, flavor):
172
- """Return the path, if any, that should be used as a dependency of
173
- any dependent action step."""
174
- if self.UsesToc(flavor):
175
- return self.FinalOutput() + ".TOC"
176
- return self.FinalOutput() or self.preaction_stamp
177
-
178
- def PreCompileInput(self):
179
- """Return the path, if any, that should be used as a dependency of
180
- any dependent compile step."""
181
- return self.actions_stamp or self.precompile_stamp
182
-
183
- def FinalOutput(self):
184
- """Return the last output of the target, which depends on all prior
185
- steps."""
186
- return self.bundle or self.binary or self.actions_stamp
187
-
188
-
189
- # A small discourse on paths as used within the Ninja build:
190
- # All files we produce (both at gyp and at build time) appear in the
191
- # build directory (e.g. out/Debug).
192
- #
193
- # Paths within a given .gyp file are always relative to the directory
194
- # containing the .gyp file. Call these "gyp paths". This includes
195
- # sources as well as the starting directory a given gyp rule/action
196
- # expects to be run from. We call the path from the source root to
197
- # the gyp file the "base directory" within the per-.gyp-file
198
- # NinjaWriter code.
199
- #
200
- # All paths as written into the .ninja files are relative to the build
201
- # directory. Call these paths "ninja paths".
202
- #
203
- # We translate between these two notions of paths with two helper
204
- # functions:
205
- #
206
- # - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file)
207
- # into the equivalent ninja path.
208
- #
209
- # - GypPathToUniqueOutput translates a gyp path into a ninja path to write
210
- # an output file; the result can be namespaced such that it is unique
211
- # to the input file name as well as the output target name.
212
-
213
-
214
- class NinjaWriter:
215
- def __init__(
216
- self,
217
- hash_for_rules,
218
- target_outputs,
219
- base_dir,
220
- build_dir,
221
- output_file,
222
- toplevel_build,
223
- output_file_name,
224
- flavor,
225
- toplevel_dir=None,
226
- ):
227
- """
228
- base_dir: path from source root to directory containing this gyp file,
229
- by gyp semantics, all input paths are relative to this
230
- build_dir: path from source root to build output
231
- toplevel_dir: path to the toplevel directory
232
- """
233
-
234
- self.hash_for_rules = hash_for_rules
235
- self.target_outputs = target_outputs
236
- self.base_dir = base_dir
237
- self.build_dir = build_dir
238
- self.ninja = ninja_syntax.Writer(output_file)
239
- self.toplevel_build = toplevel_build
240
- self.output_file_name = output_file_name
241
-
242
- self.flavor = flavor
243
- self.abs_build_dir = None
244
- if toplevel_dir is not None:
245
- self.abs_build_dir = os.path.abspath(os.path.join(toplevel_dir, build_dir))
246
- self.obj_ext = ".obj" if flavor == "win" else ".o"
247
- if flavor == "win":
248
- # See docstring of msvs_emulation.GenerateEnvironmentFiles().
249
- self.win_env = {}
250
- for arch in ("x86", "x64"):
251
- self.win_env[arch] = "environment." + arch
252
-
253
- # Relative path from build output dir to base dir.
254
- build_to_top = gyp.common.InvertRelativePath(build_dir, toplevel_dir)
255
- self.build_to_base = os.path.join(build_to_top, base_dir)
256
- # Relative path from base dir to build dir.
257
- base_to_top = gyp.common.InvertRelativePath(base_dir, toplevel_dir)
258
- self.base_to_build = os.path.join(base_to_top, build_dir)
259
-
260
- def ExpandSpecial(self, path, product_dir=None):
261
- """Expand specials like $!PRODUCT_DIR in |path|.
262
-
263
- If |product_dir| is None, assumes the cwd is already the product
264
- dir. Otherwise, |product_dir| is the relative path to the product
265
- dir.
266
- """
267
-
268
- PRODUCT_DIR = "$!PRODUCT_DIR"
269
- if PRODUCT_DIR in path:
270
- if product_dir:
271
- path = path.replace(PRODUCT_DIR, product_dir)
272
- else:
273
- path = path.replace(PRODUCT_DIR + "/", "")
274
- path = path.replace(PRODUCT_DIR + "\\", "")
275
- path = path.replace(PRODUCT_DIR, ".")
276
-
277
- INTERMEDIATE_DIR = "$!INTERMEDIATE_DIR"
278
- if INTERMEDIATE_DIR in path:
279
- int_dir = self.GypPathToUniqueOutput("gen")
280
- # GypPathToUniqueOutput generates a path relative to the product dir,
281
- # so insert product_dir in front if it is provided.
282
- path = path.replace(
283
- INTERMEDIATE_DIR, os.path.join(product_dir or "", int_dir)
284
- )
285
-
286
- CONFIGURATION_NAME = "$|CONFIGURATION_NAME"
287
- path = path.replace(CONFIGURATION_NAME, self.config_name)
288
-
289
- return path
290
-
291
- def ExpandRuleVariables(self, path, root, dirname, source, ext, name):
292
- if self.flavor == "win":
293
- path = self.msvs_settings.ConvertVSMacros(path, config=self.config_name)
294
- path = path.replace(generator_default_variables["RULE_INPUT_ROOT"], root)
295
- path = path.replace(generator_default_variables["RULE_INPUT_DIRNAME"], dirname)
296
- path = path.replace(generator_default_variables["RULE_INPUT_PATH"], source)
297
- path = path.replace(generator_default_variables["RULE_INPUT_EXT"], ext)
298
- path = path.replace(generator_default_variables["RULE_INPUT_NAME"], name)
299
- return path
300
-
301
- def GypPathToNinja(self, path, env=None):
302
- """Translate a gyp path to a ninja path, optionally expanding environment
303
- variable references in |path| with |env|.
304
-
305
- See the above discourse on path conversions."""
306
- if env:
307
- if self.flavor == "mac":
308
- path = gyp.xcode_emulation.ExpandEnvVars(path, env)
309
- elif self.flavor == "win":
310
- path = gyp.msvs_emulation.ExpandMacros(path, env)
311
- if path.startswith("$!"):
312
- expanded = self.ExpandSpecial(path)
313
- if self.flavor == "win":
314
- expanded = os.path.normpath(expanded)
315
- return expanded
316
- if "$|" in path:
317
- path = self.ExpandSpecial(path)
318
- assert "$" not in path, path
319
- return os.path.normpath(os.path.join(self.build_to_base, path))
320
-
321
- def GypPathToUniqueOutput(self, path, qualified=True):
322
- """Translate a gyp path to a ninja path for writing output.
323
-
324
- If qualified is True, qualify the resulting filename with the name
325
- of the target. This is necessary when e.g. compiling the same
326
- path twice for two separate output targets.
327
-
328
- See the above discourse on path conversions."""
329
-
330
- path = self.ExpandSpecial(path)
331
- assert not path.startswith("$"), path
332
-
333
- # Translate the path following this scheme:
334
- # Input: foo/bar.gyp, target targ, references baz/out.o
335
- # Output: obj/foo/baz/targ.out.o (if qualified)
336
- # obj/foo/baz/out.o (otherwise)
337
- # (and obj.host instead of obj for cross-compiles)
338
- #
339
- # Why this scheme and not some other one?
340
- # 1) for a given input, you can compute all derived outputs by matching
341
- # its path, even if the input is brought via a gyp file with '..'.
342
- # 2) simple files like libraries and stamps have a simple filename.
343
-
344
- obj = "obj"
345
- if self.toolset != "target":
346
- obj += "." + self.toolset
347
-
348
- path_dir, path_basename = os.path.split(path)
349
- assert not os.path.isabs(path_dir), (
350
- "'%s' can not be absolute path (see crbug.com/462153)." % path_dir
351
- )
352
-
353
- if qualified:
354
- path_basename = self.name + "." + path_basename
355
- return os.path.normpath(
356
- os.path.join(obj, self.base_dir, path_dir, path_basename)
357
- )
358
-
359
- def WriteCollapsedDependencies(self, name, targets, order_only=None):
360
- """Given a list of targets, return a path for a single file
361
- representing the result of building all the targets or None.
362
-
363
- Uses a stamp file if necessary."""
364
-
365
- assert targets == [item for item in targets if item], targets
366
- if len(targets) == 0:
367
- assert not order_only
368
- return None
369
- if len(targets) > 1 or order_only:
370
- stamp = self.GypPathToUniqueOutput(name + ".stamp")
371
- targets = self.ninja.build(stamp, "stamp", targets, order_only=order_only)
372
- self.ninja.newline()
373
- return targets[0]
374
-
375
- def _SubninjaNameForArch(self, arch):
376
- output_file_base = os.path.splitext(self.output_file_name)[0]
377
- return f"{output_file_base}.{arch}.ninja"
378
-
379
- def WriteSpec(self, spec, config_name, generator_flags):
380
- """The main entry point for NinjaWriter: write the build rules for a spec.
381
-
382
- Returns a Target object, which represents the output paths for this spec.
383
- Returns None if there are no outputs (e.g. a settings-only 'none' type
384
- target)."""
385
-
386
- self.config_name = config_name
387
- self.name = spec["target_name"]
388
- self.toolset = spec["toolset"]
389
- config = spec["configurations"][config_name]
390
- self.target = Target(spec["type"])
391
- self.is_standalone_static_library = bool(
392
- spec.get("standalone_static_library", 0)
393
- )
394
-
395
- self.target_rpath = generator_flags.get("target_rpath", r"\$$ORIGIN/lib/")
396
-
397
- self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
398
- self.xcode_settings = self.msvs_settings = None
399
- if self.flavor == "mac":
400
- self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
401
- mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
402
- if mac_toolchain_dir:
403
- self.xcode_settings.mac_toolchain_dir = mac_toolchain_dir
404
-
405
- if self.flavor == "win":
406
- self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec, generator_flags)
407
- arch = self.msvs_settings.GetArch(config_name)
408
- self.ninja.variable("arch", self.win_env[arch])
409
- self.ninja.variable("cc", "$cl_" + arch)
410
- self.ninja.variable("cxx", "$cl_" + arch)
411
- self.ninja.variable("cc_host", "$cl_" + arch)
412
- self.ninja.variable("cxx_host", "$cl_" + arch)
413
- self.ninja.variable("asm", "$ml_" + arch)
414
-
415
- if self.flavor == "mac":
416
- self.archs = self.xcode_settings.GetActiveArchs(config_name)
417
- if len(self.archs) > 1:
418
- self.arch_subninjas = {
419
- arch: ninja_syntax.Writer(
420
- OpenOutput(
421
- os.path.join(
422
- self.toplevel_build, self._SubninjaNameForArch(arch)
423
- ),
424
- "w",
425
- )
426
- )
427
- for arch in self.archs
428
- }
429
-
430
- # Compute predepends for all rules.
431
- # actions_depends is the dependencies this target depends on before running
432
- # any of its action/rule/copy steps.
433
- # compile_depends is the dependencies this target depends on before running
434
- # any of its compile steps.
435
- actions_depends = []
436
- compile_depends = []
437
- # TODO(evan): it is rather confusing which things are lists and which
438
- # are strings. Fix these.
439
- if "dependencies" in spec:
440
- for dep in spec["dependencies"]:
441
- if dep in self.target_outputs:
442
- target = self.target_outputs[dep]
443
- actions_depends.append(target.PreActionInput(self.flavor))
444
- compile_depends.append(target.PreCompileInput())
445
- if target.uses_cpp:
446
- self.target.uses_cpp = True
447
- actions_depends = [item for item in actions_depends if item]
448
- compile_depends = [item for item in compile_depends if item]
449
- actions_depends = self.WriteCollapsedDependencies(
450
- "actions_depends", actions_depends
451
- )
452
- compile_depends = self.WriteCollapsedDependencies(
453
- "compile_depends", compile_depends
454
- )
455
- self.target.preaction_stamp = actions_depends
456
- self.target.precompile_stamp = compile_depends
457
-
458
- # Write out actions, rules, and copies. These must happen before we
459
- # compile any sources, so compute a list of predependencies for sources
460
- # while we do it.
461
- extra_sources = []
462
- mac_bundle_depends = []
463
- self.target.actions_stamp = self.WriteActionsRulesCopies(
464
- spec, extra_sources, actions_depends, mac_bundle_depends
465
- )
466
-
467
- # If we have actions/rules/copies, we depend directly on those, but
468
- # otherwise we depend on dependent target's actions/rules/copies etc.
469
- # We never need to explicitly depend on previous target's link steps,
470
- # because no compile ever depends on them.
471
- compile_depends_stamp = self.target.actions_stamp or compile_depends
472
-
473
- # Write out the compilation steps, if any.
474
- link_deps = []
475
- try:
476
- sources = extra_sources + spec.get("sources", [])
477
- except TypeError:
478
- print("extra_sources: ", str(extra_sources))
479
- print('spec.get("sources"): ', str(spec.get("sources")))
480
- raise
481
- if sources:
482
- if self.flavor == "mac" and len(self.archs) > 1:
483
- # Write subninja file containing compile and link commands scoped to
484
- # a single arch if a fat binary is being built.
485
- for arch in self.archs:
486
- self.ninja.subninja(self._SubninjaNameForArch(arch))
487
-
488
- pch = None
489
- if self.flavor == "win":
490
- gyp.msvs_emulation.VerifyMissingSources(
491
- sources, self.abs_build_dir, generator_flags, self.GypPathToNinja
492
- )
493
- pch = gyp.msvs_emulation.PrecompiledHeader(
494
- self.msvs_settings,
495
- config_name,
496
- self.GypPathToNinja,
497
- self.GypPathToUniqueOutput,
498
- self.obj_ext,
499
- )
500
- else:
501
- pch = gyp.xcode_emulation.MacPrefixHeader(
502
- self.xcode_settings,
503
- self.GypPathToNinja,
504
- lambda path, lang: self.GypPathToUniqueOutput(path + "-" + lang),
505
- )
506
- link_deps = self.WriteSources(
507
- self.ninja,
508
- config_name,
509
- config,
510
- sources,
511
- compile_depends_stamp,
512
- pch,
513
- spec,
514
- )
515
- # Some actions/rules output 'sources' that are already object files.
516
- obj_outputs = [f for f in sources if f.endswith(self.obj_ext)]
517
- if obj_outputs:
518
- if self.flavor != "mac" or len(self.archs) == 1:
519
- link_deps += [self.GypPathToNinja(o) for o in obj_outputs]
520
- else:
521
- print(
522
- "Warning: Actions/rules writing object files don't work with "
523
- "multiarch targets, dropping. (target %s)" % spec["target_name"]
524
- )
525
- elif self.flavor == "mac" and len(self.archs) > 1:
526
- link_deps = collections.defaultdict(list)
527
-
528
- compile_deps = self.target.actions_stamp or actions_depends
529
- if self.flavor == "win" and self.target.type == "static_library":
530
- self.target.component_objs = link_deps
531
- self.target.compile_deps = compile_deps
532
-
533
- # Write out a link step, if needed.
534
- output = None
535
- is_empty_bundle = not link_deps and not mac_bundle_depends
536
- if link_deps or self.target.actions_stamp or actions_depends:
537
- output = self.WriteTarget(
538
- spec, config_name, config, link_deps, compile_deps
539
- )
540
- if self.is_mac_bundle:
541
- mac_bundle_depends.append(output)
542
-
543
- # Bundle all of the above together, if needed.
544
- if self.is_mac_bundle:
545
- output = self.WriteMacBundle(spec, mac_bundle_depends, is_empty_bundle)
546
-
547
- if not output:
548
- return None
549
-
550
- assert self.target.FinalOutput(), output
551
- return self.target
552
-
553
- def _WinIdlRule(self, source, prebuild, outputs):
554
- """Handle the implicit VS .idl rule for one source file. Fills |outputs|
555
- with files that are generated."""
556
- outdir, output, vars, flags = self.msvs_settings.GetIdlBuildData(
557
- source, self.config_name
558
- )
559
- outdir = self.GypPathToNinja(outdir)
560
-
561
- def fix_path(path, rel=None):
562
- path = os.path.join(outdir, path)
563
- dirname, basename = os.path.split(source)
564
- root, ext = os.path.splitext(basename)
565
- path = self.ExpandRuleVariables(path, root, dirname, source, ext, basename)
566
- if rel:
567
- path = os.path.relpath(path, rel)
568
- return path
569
-
570
- vars = [(name, fix_path(value, outdir)) for name, value in vars]
571
- output = [fix_path(p) for p in output]
572
- vars.append(("outdir", outdir))
573
- vars.append(("idlflags", flags))
574
- input = self.GypPathToNinja(source)
575
- self.ninja.build(output, "idl", input, variables=vars, order_only=prebuild)
576
- outputs.extend(output)
577
-
578
- def WriteWinIdlFiles(self, spec, prebuild):
579
- """Writes rules to match MSVS's implicit idl handling."""
580
- assert self.flavor == "win"
581
- if self.msvs_settings.HasExplicitIdlRulesOrActions(spec):
582
- return []
583
- outputs = []
584
- for source in filter(lambda x: x.endswith(".idl"), spec["sources"]):
585
- self._WinIdlRule(source, prebuild, outputs)
586
- return outputs
587
-
588
- def WriteActionsRulesCopies(
589
- self, spec, extra_sources, prebuild, mac_bundle_depends
590
- ):
591
- """Write out the Actions, Rules, and Copies steps. Return a path
592
- representing the outputs of these steps."""
593
- outputs = []
594
- if self.is_mac_bundle:
595
- mac_bundle_resources = spec.get("mac_bundle_resources", [])[:]
596
- else:
597
- mac_bundle_resources = []
598
- extra_mac_bundle_resources = []
599
-
600
- if "actions" in spec:
601
- outputs += self.WriteActions(
602
- spec["actions"], extra_sources, prebuild, extra_mac_bundle_resources
603
- )
604
- if "rules" in spec:
605
- outputs += self.WriteRules(
606
- spec["rules"],
607
- extra_sources,
608
- prebuild,
609
- mac_bundle_resources,
610
- extra_mac_bundle_resources,
611
- )
612
- if "copies" in spec:
613
- outputs += self.WriteCopies(spec["copies"], prebuild, mac_bundle_depends)
614
-
615
- if "sources" in spec and self.flavor == "win":
616
- outputs += self.WriteWinIdlFiles(spec, prebuild)
617
-
618
- if self.xcode_settings and self.xcode_settings.IsIosFramework():
619
- self.WriteiOSFrameworkHeaders(spec, outputs, prebuild)
620
-
621
- stamp = self.WriteCollapsedDependencies("actions_rules_copies", outputs)
622
-
623
- if self.is_mac_bundle:
624
- xcassets = self.WriteMacBundleResources(
625
- extra_mac_bundle_resources + mac_bundle_resources, mac_bundle_depends
626
- )
627
- partial_info_plist = self.WriteMacXCassets(xcassets, mac_bundle_depends)
628
- self.WriteMacInfoPlist(partial_info_plist, mac_bundle_depends)
629
-
630
- return stamp
631
-
632
- def GenerateDescription(self, verb, message, fallback):
633
- """Generate and return a description of a build step.
634
-
635
- |verb| is the short summary, e.g. ACTION or RULE.
636
- |message| is a hand-written description, or None if not available.
637
- |fallback| is the gyp-level name of the step, usable as a fallback.
638
- """
639
- if self.toolset != "target":
640
- verb += "(%s)" % self.toolset
641
- if message:
642
- return f"{verb} {self.ExpandSpecial(message)}"
643
- else:
644
- return f"{verb} {self.name}: {fallback}"
645
-
646
- def WriteActions(
647
- self, actions, extra_sources, prebuild, extra_mac_bundle_resources
648
- ):
649
- # Actions cd into the base directory.
650
- env = self.GetToolchainEnv()
651
- all_outputs = []
652
- for action in actions:
653
- # First write out a rule for the action.
654
- name = "{}_{}".format(action["action_name"], self.hash_for_rules)
655
- description = self.GenerateDescription(
656
- "ACTION", action.get("message", None), name
657
- )
658
- win_shell_flags = (
659
- self.msvs_settings.GetRuleShellFlags(action)
660
- if self.flavor == "win"
661
- else None
662
- )
663
- args = action["action"]
664
- depfile = action.get("depfile", None)
665
- if depfile:
666
- depfile = self.ExpandSpecial(depfile, self.base_to_build)
667
- pool = "console" if int(action.get("ninja_use_console", 0)) else None
668
- rule_name, _ = self.WriteNewNinjaRule(
669
- name, args, description, win_shell_flags, env, pool, depfile=depfile
670
- )
671
-
672
- inputs = [self.GypPathToNinja(i, env) for i in action["inputs"]]
673
- if int(action.get("process_outputs_as_sources", False)):
674
- extra_sources += action["outputs"]
675
- if int(action.get("process_outputs_as_mac_bundle_resources", False)):
676
- extra_mac_bundle_resources += action["outputs"]
677
- outputs = [self.GypPathToNinja(o, env) for o in action["outputs"]]
678
-
679
- # Then write out an edge using the rule.
680
- self.ninja.build(outputs, rule_name, inputs, order_only=prebuild)
681
- all_outputs += outputs
682
-
683
- self.ninja.newline()
684
-
685
- return all_outputs
686
-
687
- def WriteRules(
688
- self,
689
- rules,
690
- extra_sources,
691
- prebuild,
692
- mac_bundle_resources,
693
- extra_mac_bundle_resources,
694
- ):
695
- env = self.GetToolchainEnv()
696
- all_outputs = []
697
- for rule in rules:
698
- # Skip a rule with no action and no inputs.
699
- if "action" not in rule and not rule.get("rule_sources", []):
700
- continue
701
-
702
- # First write out a rule for the rule action.
703
- name = "{}_{}".format(rule["rule_name"], self.hash_for_rules)
704
-
705
- args = rule["action"]
706
- description = self.GenerateDescription(
707
- "RULE",
708
- rule.get("message", None),
709
- ("%s " + generator_default_variables["RULE_INPUT_PATH"]) % name,
710
- )
711
- win_shell_flags = (
712
- self.msvs_settings.GetRuleShellFlags(rule)
713
- if self.flavor == "win"
714
- else None
715
- )
716
- pool = "console" if int(rule.get("ninja_use_console", 0)) else None
717
- rule_name, args = self.WriteNewNinjaRule(
718
- name, args, description, win_shell_flags, env, pool
719
- )
720
-
721
- # TODO: if the command references the outputs directly, we should
722
- # simplify it to just use $out.
723
-
724
- # Rules can potentially make use of some special variables which
725
- # must vary per source file.
726
- # Compute the list of variables we'll need to provide.
727
- special_locals = ("source", "root", "dirname", "ext", "name")
728
- needed_variables = {"source"}
729
- for argument in args:
730
- for var in special_locals:
731
- if "${%s}" % var in argument:
732
- needed_variables.add(var)
733
- needed_variables = sorted(needed_variables)
734
-
735
- def cygwin_munge(path):
736
- # pylint: disable=cell-var-from-loop
737
- if win_shell_flags and win_shell_flags.cygwin:
738
- return path.replace("\\", "/")
739
- return path
740
-
741
- inputs = [self.GypPathToNinja(i, env) for i in rule.get("inputs", [])]
742
-
743
- # If there are n source files matching the rule, and m additional rule
744
- # inputs, then adding 'inputs' to each build edge written below will
745
- # write m * n inputs. Collapsing reduces this to m + n.
746
- sources = rule.get("rule_sources", [])
747
- num_inputs = len(inputs)
748
- if prebuild:
749
- num_inputs += 1
750
- if num_inputs > 2 and len(sources) > 2:
751
- inputs = [
752
- self.WriteCollapsedDependencies(
753
- rule["rule_name"], inputs, order_only=prebuild
754
- )
755
- ]
756
- prebuild = []
757
-
758
- # For each source file, write an edge that generates all the outputs.
759
- for source in sources:
760
- source = os.path.normpath(source)
761
- dirname, basename = os.path.split(source)
762
- root, ext = os.path.splitext(basename)
763
-
764
- # Gather the list of inputs and outputs, expanding $vars if possible.
765
- outputs = [
766
- self.ExpandRuleVariables(o, root, dirname, source, ext, basename)
767
- for o in rule["outputs"]
768
- ]
769
-
770
- if int(rule.get("process_outputs_as_sources", False)):
771
- extra_sources += outputs
772
-
773
- was_mac_bundle_resource = source in mac_bundle_resources
774
- if was_mac_bundle_resource or int(
775
- rule.get("process_outputs_as_mac_bundle_resources", False)
776
- ):
777
- extra_mac_bundle_resources += outputs
778
- # Note: This is n_resources * n_outputs_in_rule.
779
- # Put to-be-removed items in a set and
780
- # remove them all in a single pass
781
- # if this becomes a performance issue.
782
- if was_mac_bundle_resource:
783
- mac_bundle_resources.remove(source)
784
-
785
- extra_bindings = []
786
- for var in needed_variables:
787
- if var == "root":
788
- extra_bindings.append(("root", cygwin_munge(root)))
789
- elif var == "dirname":
790
- # '$dirname' is a parameter to the rule action, which means
791
- # it shouldn't be converted to a Ninja path. But we don't
792
- # want $!PRODUCT_DIR in there either.
793
- dirname_expanded = self.ExpandSpecial(
794
- dirname, self.base_to_build
795
- )
796
- extra_bindings.append(
797
- ("dirname", cygwin_munge(dirname_expanded))
798
- )
799
- elif var == "source":
800
- # '$source' is a parameter to the rule action, which means
801
- # it shouldn't be converted to a Ninja path. But we don't
802
- # want $!PRODUCT_DIR in there either.
803
- source_expanded = self.ExpandSpecial(source, self.base_to_build)
804
- extra_bindings.append(("source", cygwin_munge(source_expanded)))
805
- elif var == "ext":
806
- extra_bindings.append(("ext", ext))
807
- elif var == "name":
808
- extra_bindings.append(("name", cygwin_munge(basename)))
809
- else:
810
- assert var is None, repr(var)
811
-
812
- outputs = [self.GypPathToNinja(o, env) for o in outputs]
813
- if self.flavor == "win":
814
- # WriteNewNinjaRule uses unique_name to create a rsp file on win.
815
- extra_bindings.append(
816
- ("unique_name", hashlib.md5(outputs[0]).hexdigest())
817
- )
818
-
819
- self.ninja.build(
820
- outputs,
821
- rule_name,
822
- self.GypPathToNinja(source),
823
- implicit=inputs,
824
- order_only=prebuild,
825
- variables=extra_bindings,
826
- )
827
-
828
- all_outputs.extend(outputs)
829
-
830
- return all_outputs
831
-
832
- def WriteCopies(self, copies, prebuild, mac_bundle_depends):
833
- outputs = []
834
- if self.xcode_settings:
835
- extra_env = self.xcode_settings.GetPerTargetSettings()
836
- env = self.GetToolchainEnv(additional_settings=extra_env)
837
- else:
838
- env = self.GetToolchainEnv()
839
- for to_copy in copies:
840
- for path in to_copy["files"]:
841
- # Normalize the path so trailing slashes don't confuse us.
842
- path = os.path.normpath(path)
843
- basename = os.path.split(path)[1]
844
- src = self.GypPathToNinja(path, env)
845
- dst = self.GypPathToNinja(
846
- os.path.join(to_copy["destination"], basename), env
847
- )
848
- outputs += self.ninja.build(dst, "copy", src, order_only=prebuild)
849
- if self.is_mac_bundle:
850
- # gyp has mac_bundle_resources to copy things into a bundle's
851
- # Resources folder, but there's no built-in way to copy files
852
- # to other places in the bundle.
853
- # Hence, some targets use copies for this.
854
- # Check if this file is copied into the current bundle,
855
- # and if so add it to the bundle depends so
856
- # that dependent targets get rebuilt if the copy input changes.
857
- if dst.startswith(
858
- self.xcode_settings.GetBundleContentsFolderPath()
859
- ):
860
- mac_bundle_depends.append(dst)
861
-
862
- return outputs
863
-
864
- def WriteiOSFrameworkHeaders(self, spec, outputs, prebuild):
865
- """Prebuild steps to generate hmap files and copy headers to destination."""
866
- framework = self.ComputeMacBundleOutput()
867
- all_sources = spec["sources"]
868
- copy_headers = spec["mac_framework_headers"]
869
- output = self.GypPathToUniqueOutput("headers.hmap")
870
- self.xcode_settings.header_map_path = output
871
- all_headers = map(
872
- self.GypPathToNinja, filter(lambda x: x.endswith(".h"), all_sources)
873
- )
874
- variables = [
875
- ("framework", framework),
876
- ("copy_headers", map(self.GypPathToNinja, copy_headers)),
877
- ]
878
- outputs.extend(
879
- self.ninja.build(
880
- output,
881
- "compile_ios_framework_headers",
882
- all_headers,
883
- variables=variables,
884
- order_only=prebuild,
885
- )
886
- )
887
-
888
- def WriteMacBundleResources(self, resources, bundle_depends):
889
- """Writes ninja edges for 'mac_bundle_resources'."""
890
- xcassets = []
891
-
892
- extra_env = self.xcode_settings.GetPerTargetSettings()
893
- env = self.GetSortedXcodeEnv(additional_settings=extra_env)
894
- env = self.ComputeExportEnvString(env)
895
- isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name)
896
-
897
- for output, res in gyp.xcode_emulation.GetMacBundleResources(
898
- generator_default_variables["PRODUCT_DIR"],
899
- self.xcode_settings,
900
- map(self.GypPathToNinja, resources),
901
- ):
902
- output = self.ExpandSpecial(output)
903
- if os.path.splitext(output)[-1] != ".xcassets":
904
- self.ninja.build(
905
- output,
906
- "mac_tool",
907
- res,
908
- variables=[
909
- ("mactool_cmd", "copy-bundle-resource"),
910
- ("env", env),
911
- ("binary", isBinary),
912
- ],
913
- )
914
- bundle_depends.append(output)
915
- else:
916
- xcassets.append(res)
917
- return xcassets
918
-
919
- def WriteMacXCassets(self, xcassets, bundle_depends):
920
- """Writes ninja edges for 'mac_bundle_resources' .xcassets files.
921
-
922
- This add an invocation of 'actool' via the 'mac_tool.py' helper script.
923
- It assumes that the assets catalogs define at least one imageset and
924
- thus an Assets.car file will be generated in the application resources
925
- directory. If this is not the case, then the build will probably be done
926
- at each invocation of ninja."""
927
- if not xcassets:
928
- return
929
-
930
- extra_arguments = {}
931
- settings_to_arg = {
932
- "XCASSETS_APP_ICON": "app-icon",
933
- "XCASSETS_LAUNCH_IMAGE": "launch-image",
934
- }
935
- settings = self.xcode_settings.xcode_settings[self.config_name]
936
- for settings_key, arg_name in settings_to_arg.items():
937
- value = settings.get(settings_key)
938
- if value:
939
- extra_arguments[arg_name] = value
940
-
941
- partial_info_plist = None
942
- if extra_arguments:
943
- partial_info_plist = self.GypPathToUniqueOutput(
944
- "assetcatalog_generated_info.plist"
945
- )
946
- extra_arguments["output-partial-info-plist"] = partial_info_plist
947
-
948
- outputs = []
949
- outputs.append(
950
- os.path.join(self.xcode_settings.GetBundleResourceFolder(), "Assets.car")
951
- )
952
- if partial_info_plist:
953
- outputs.append(partial_info_plist)
954
-
955
- keys = QuoteShellArgument(json.dumps(extra_arguments), self.flavor)
956
- extra_env = self.xcode_settings.GetPerTargetSettings()
957
- env = self.GetSortedXcodeEnv(additional_settings=extra_env)
958
- env = self.ComputeExportEnvString(env)
959
-
960
- bundle_depends.extend(
961
- self.ninja.build(
962
- outputs,
963
- "compile_xcassets",
964
- xcassets,
965
- variables=[("env", env), ("keys", keys)],
966
- )
967
- )
968
- return partial_info_plist
969
-
970
- def WriteMacInfoPlist(self, partial_info_plist, bundle_depends):
971
- """Write build rules for bundle Info.plist files."""
972
- info_plist, out, defines, extra_env = gyp.xcode_emulation.GetMacInfoPlist(
973
- generator_default_variables["PRODUCT_DIR"],
974
- self.xcode_settings,
975
- self.GypPathToNinja,
976
- )
977
- if not info_plist:
978
- return
979
- out = self.ExpandSpecial(out)
980
- if defines:
981
- # Create an intermediate file to store preprocessed results.
982
- intermediate_plist = self.GypPathToUniqueOutput(
983
- os.path.basename(info_plist)
984
- )
985
- defines = " ".join([Define(d, self.flavor) for d in defines])
986
- info_plist = self.ninja.build(
987
- intermediate_plist,
988
- "preprocess_infoplist",
989
- info_plist,
990
- variables=[("defines", defines)],
991
- )
992
-
993
- env = self.GetSortedXcodeEnv(additional_settings=extra_env)
994
- env = self.ComputeExportEnvString(env)
995
-
996
- if partial_info_plist:
997
- intermediate_plist = self.GypPathToUniqueOutput("merged_info.plist")
998
- info_plist = self.ninja.build(
999
- intermediate_plist, "merge_infoplist", [partial_info_plist, info_plist]
1000
- )
1001
-
1002
- keys = self.xcode_settings.GetExtraPlistItems(self.config_name)
1003
- keys = QuoteShellArgument(json.dumps(keys), self.flavor)
1004
- isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name)
1005
- self.ninja.build(
1006
- out,
1007
- "copy_infoplist",
1008
- info_plist,
1009
- variables=[("env", env), ("keys", keys), ("binary", isBinary)],
1010
- )
1011
- bundle_depends.append(out)
1012
-
1013
- def WriteSources(
1014
- self,
1015
- ninja_file,
1016
- config_name,
1017
- config,
1018
- sources,
1019
- predepends,
1020
- precompiled_header,
1021
- spec,
1022
- ):
1023
- """Write build rules to compile all of |sources|."""
1024
- if self.toolset == "host":
1025
- self.ninja.variable("ar", "$ar_host")
1026
- self.ninja.variable("cc", "$cc_host")
1027
- self.ninja.variable("cxx", "$cxx_host")
1028
- self.ninja.variable("ld", "$ld_host")
1029
- self.ninja.variable("ldxx", "$ldxx_host")
1030
- self.ninja.variable("nm", "$nm_host")
1031
- self.ninja.variable("readelf", "$readelf_host")
1032
-
1033
- if self.flavor != "mac" or len(self.archs) == 1:
1034
- return self.WriteSourcesForArch(
1035
- self.ninja,
1036
- config_name,
1037
- config,
1038
- sources,
1039
- predepends,
1040
- precompiled_header,
1041
- spec,
1042
- )
1043
- else:
1044
- return {
1045
- arch: self.WriteSourcesForArch(
1046
- self.arch_subninjas[arch],
1047
- config_name,
1048
- config,
1049
- sources,
1050
- predepends,
1051
- precompiled_header,
1052
- spec,
1053
- arch=arch,
1054
- )
1055
- for arch in self.archs
1056
- }
1057
-
1058
- def WriteSourcesForArch(
1059
- self,
1060
- ninja_file,
1061
- config_name,
1062
- config,
1063
- sources,
1064
- predepends,
1065
- precompiled_header,
1066
- spec,
1067
- arch=None,
1068
- ):
1069
- """Write build rules to compile all of |sources|."""
1070
-
1071
- extra_defines = []
1072
- if self.flavor == "mac":
1073
- cflags = self.xcode_settings.GetCflags(config_name, arch=arch)
1074
- cflags_c = self.xcode_settings.GetCflagsC(config_name)
1075
- cflags_cc = self.xcode_settings.GetCflagsCC(config_name)
1076
- cflags_objc = ["$cflags_c"] + self.xcode_settings.GetCflagsObjC(config_name)
1077
- cflags_objcc = ["$cflags_cc"] + self.xcode_settings.GetCflagsObjCC(
1078
- config_name
1079
- )
1080
- elif self.flavor == "win":
1081
- asmflags = self.msvs_settings.GetAsmflags(config_name)
1082
- cflags = self.msvs_settings.GetCflags(config_name)
1083
- cflags_c = self.msvs_settings.GetCflagsC(config_name)
1084
- cflags_cc = self.msvs_settings.GetCflagsCC(config_name)
1085
- extra_defines = self.msvs_settings.GetComputedDefines(config_name)
1086
- # See comment at cc_command for why there's two .pdb files.
1087
- pdbpath_c = pdbpath_cc = self.msvs_settings.GetCompilerPdbName(
1088
- config_name, self.ExpandSpecial
1089
- )
1090
- if not pdbpath_c:
1091
- obj = "obj"
1092
- if self.toolset != "target":
1093
- obj += "." + self.toolset
1094
- pdbpath = os.path.normpath(os.path.join(obj, self.base_dir, self.name))
1095
- pdbpath_c = pdbpath + ".c.pdb"
1096
- pdbpath_cc = pdbpath + ".cc.pdb"
1097
- self.WriteVariableList(ninja_file, "pdbname_c", [pdbpath_c])
1098
- self.WriteVariableList(ninja_file, "pdbname_cc", [pdbpath_cc])
1099
- self.WriteVariableList(ninja_file, "pchprefix", [self.name])
1100
- else:
1101
- cflags = config.get("cflags", [])
1102
- cflags_c = config.get("cflags_c", [])
1103
- cflags_cc = config.get("cflags_cc", [])
1104
-
1105
- # Respect environment variables related to build, but target-specific
1106
- # flags can still override them.
1107
- if self.toolset == "target":
1108
- cflags_c = (
1109
- os.environ.get("CPPFLAGS", "").split()
1110
- + os.environ.get("CFLAGS", "").split()
1111
- + cflags_c
1112
- )
1113
- cflags_cc = (
1114
- os.environ.get("CPPFLAGS", "").split()
1115
- + os.environ.get("CXXFLAGS", "").split()
1116
- + cflags_cc
1117
- )
1118
- elif self.toolset == "host":
1119
- cflags_c = (
1120
- os.environ.get("CPPFLAGS_host", "").split()
1121
- + os.environ.get("CFLAGS_host", "").split()
1122
- + cflags_c
1123
- )
1124
- cflags_cc = (
1125
- os.environ.get("CPPFLAGS_host", "").split()
1126
- + os.environ.get("CXXFLAGS_host", "").split()
1127
- + cflags_cc
1128
- )
1129
-
1130
- defines = config.get("defines", []) + extra_defines
1131
- self.WriteVariableList(
1132
- ninja_file, "defines", [Define(d, self.flavor) for d in defines]
1133
- )
1134
- if self.flavor == "win":
1135
- self.WriteVariableList(
1136
- ninja_file, "asmflags", map(self.ExpandSpecial, asmflags)
1137
- )
1138
- self.WriteVariableList(
1139
- ninja_file,
1140
- "rcflags",
1141
- [
1142
- QuoteShellArgument(self.ExpandSpecial(f), self.flavor)
1143
- for f in self.msvs_settings.GetRcflags(
1144
- config_name, self.GypPathToNinja
1145
- )
1146
- ],
1147
- )
1148
-
1149
- include_dirs = config.get("include_dirs", [])
1150
-
1151
- env = self.GetToolchainEnv()
1152
- if self.flavor == "win":
1153
- include_dirs = self.msvs_settings.AdjustIncludeDirs(
1154
- include_dirs, config_name
1155
- )
1156
- self.WriteVariableList(
1157
- ninja_file,
1158
- "includes",
1159
- [
1160
- QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
1161
- for i in include_dirs
1162
- ],
1163
- )
1164
-
1165
- if self.flavor == "win":
1166
- midl_include_dirs = config.get("midl_include_dirs", [])
1167
- midl_include_dirs = self.msvs_settings.AdjustMidlIncludeDirs(
1168
- midl_include_dirs, config_name
1169
- )
1170
- self.WriteVariableList(
1171
- ninja_file,
1172
- "midl_includes",
1173
- [
1174
- QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
1175
- for i in midl_include_dirs
1176
- ],
1177
- )
1178
-
1179
- pch_commands = precompiled_header.GetPchBuildCommands(arch)
1180
- if self.flavor == "mac":
1181
- # Most targets use no precompiled headers, so only write these if needed.
1182
- for ext, var in [
1183
- ("c", "cflags_pch_c"),
1184
- ("cc", "cflags_pch_cc"),
1185
- ("m", "cflags_pch_objc"),
1186
- ("mm", "cflags_pch_objcc"),
1187
- ]:
1188
- include = precompiled_header.GetInclude(ext, arch)
1189
- if include:
1190
- ninja_file.variable(var, include)
1191
-
1192
- arflags = config.get("arflags", [])
1193
-
1194
- self.WriteVariableList(ninja_file, "cflags", map(self.ExpandSpecial, cflags))
1195
- self.WriteVariableList(
1196
- ninja_file, "cflags_c", map(self.ExpandSpecial, cflags_c)
1197
- )
1198
- self.WriteVariableList(
1199
- ninja_file, "cflags_cc", map(self.ExpandSpecial, cflags_cc)
1200
- )
1201
- if self.flavor == "mac":
1202
- self.WriteVariableList(
1203
- ninja_file, "cflags_objc", map(self.ExpandSpecial, cflags_objc)
1204
- )
1205
- self.WriteVariableList(
1206
- ninja_file, "cflags_objcc", map(self.ExpandSpecial, cflags_objcc)
1207
- )
1208
- self.WriteVariableList(ninja_file, "arflags", map(self.ExpandSpecial, arflags))
1209
- ninja_file.newline()
1210
- outputs = []
1211
- has_rc_source = False
1212
- for source in sources:
1213
- filename, ext = os.path.splitext(source)
1214
- ext = ext[1:]
1215
- obj_ext = self.obj_ext
1216
- if ext in ("cc", "cpp", "cxx"):
1217
- command = "cxx"
1218
- self.target.uses_cpp = True
1219
- elif ext == "c" or (ext == "S" and self.flavor != "win"):
1220
- command = "cc"
1221
- elif ext == "s" and self.flavor != "win": # Doesn't generate .o.d files.
1222
- command = "cc_s"
1223
- elif (
1224
- self.flavor == "win"
1225
- and ext in ("asm", "S")
1226
- and not self.msvs_settings.HasExplicitAsmRules(spec)
1227
- ):
1228
- command = "asm"
1229
- # Add the _asm suffix as msvs is capable of handling .cc and
1230
- # .asm files of the same name without collision.
1231
- obj_ext = "_asm.obj"
1232
- elif self.flavor == "mac" and ext == "m":
1233
- command = "objc"
1234
- elif self.flavor == "mac" and ext == "mm":
1235
- command = "objcxx"
1236
- self.target.uses_cpp = True
1237
- elif self.flavor == "win" and ext == "rc":
1238
- command = "rc"
1239
- obj_ext = ".res"
1240
- has_rc_source = True
1241
- else:
1242
- # Ignore unhandled extensions.
1243
- continue
1244
- input = self.GypPathToNinja(source)
1245
- output = self.GypPathToUniqueOutput(filename + obj_ext)
1246
- if arch is not None:
1247
- output = AddArch(output, arch)
1248
- implicit = precompiled_header.GetObjDependencies([input], [output], arch)
1249
- variables = []
1250
- if self.flavor == "win":
1251
- variables, output, implicit = precompiled_header.GetFlagsModifications(
1252
- input,
1253
- output,
1254
- implicit,
1255
- command,
1256
- cflags_c,
1257
- cflags_cc,
1258
- self.ExpandSpecial,
1259
- )
1260
- ninja_file.build(
1261
- output,
1262
- command,
1263
- input,
1264
- implicit=[gch for _, _, gch in implicit],
1265
- order_only=predepends,
1266
- variables=variables,
1267
- )
1268
- outputs.append(output)
1269
-
1270
- if has_rc_source:
1271
- resource_include_dirs = config.get("resource_include_dirs", include_dirs)
1272
- self.WriteVariableList(
1273
- ninja_file,
1274
- "resource_includes",
1275
- [
1276
- QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
1277
- for i in resource_include_dirs
1278
- ],
1279
- )
1280
-
1281
- self.WritePchTargets(ninja_file, pch_commands)
1282
-
1283
- ninja_file.newline()
1284
- return outputs
1285
-
1286
- def WritePchTargets(self, ninja_file, pch_commands):
1287
- """Writes ninja rules to compile prefix headers."""
1288
- if not pch_commands:
1289
- return
1290
-
1291
- for gch, lang_flag, lang, input in pch_commands:
1292
- var_name = {
1293
- "c": "cflags_pch_c",
1294
- "cc": "cflags_pch_cc",
1295
- "m": "cflags_pch_objc",
1296
- "mm": "cflags_pch_objcc",
1297
- }[lang]
1298
-
1299
- map = {
1300
- "c": "cc",
1301
- "cc": "cxx",
1302
- "m": "objc",
1303
- "mm": "objcxx",
1304
- }
1305
- cmd = map.get(lang)
1306
- ninja_file.build(gch, cmd, input, variables=[(var_name, lang_flag)])
1307
-
1308
- def WriteLink(self, spec, config_name, config, link_deps, compile_deps):
1309
- """Write out a link step. Fills out target.binary. """
1310
- if self.flavor != "mac" or len(self.archs) == 1:
1311
- return self.WriteLinkForArch(
1312
- self.ninja, spec, config_name, config, link_deps, compile_deps
1313
- )
1314
- else:
1315
- output = self.ComputeOutput(spec)
1316
- inputs = [
1317
- self.WriteLinkForArch(
1318
- self.arch_subninjas[arch],
1319
- spec,
1320
- config_name,
1321
- config,
1322
- link_deps[arch],
1323
- compile_deps,
1324
- arch=arch,
1325
- )
1326
- for arch in self.archs
1327
- ]
1328
- extra_bindings = []
1329
- build_output = output
1330
- if not self.is_mac_bundle:
1331
- self.AppendPostbuildVariable(extra_bindings, spec, output, output)
1332
-
1333
- # TODO(yyanagisawa): more work needed to fix:
1334
- # https://code.google.com/p/gyp/issues/detail?id=411
1335
- if (
1336
- spec["type"] in ("shared_library", "loadable_module")
1337
- and not self.is_mac_bundle
1338
- ):
1339
- extra_bindings.append(("lib", output))
1340
- self.ninja.build(
1341
- [output, output + ".TOC"],
1342
- "solipo",
1343
- inputs,
1344
- variables=extra_bindings,
1345
- )
1346
- else:
1347
- self.ninja.build(build_output, "lipo", inputs, variables=extra_bindings)
1348
- return output
1349
-
1350
- def WriteLinkForArch(
1351
- self, ninja_file, spec, config_name, config, link_deps, compile_deps, arch=None
1352
- ):
1353
- """Write out a link step. Fills out target.binary. """
1354
- command = {
1355
- "executable": "link",
1356
- "loadable_module": "solink_module",
1357
- "shared_library": "solink",
1358
- }[spec["type"]]
1359
- command_suffix = ""
1360
-
1361
- implicit_deps = set()
1362
- solibs = set()
1363
- order_deps = set()
1364
-
1365
- if compile_deps:
1366
- # Normally, the compiles of the target already depend on compile_deps,
1367
- # but a shared_library target might have no sources and only link together
1368
- # a few static_library deps, so the link step also needs to depend
1369
- # on compile_deps to make sure actions in the shared_library target
1370
- # get run before the link.
1371
- order_deps.add(compile_deps)
1372
-
1373
- if "dependencies" in spec:
1374
- # Two kinds of dependencies:
1375
- # - Linkable dependencies (like a .a or a .so): add them to the link line.
1376
- # - Non-linkable dependencies (like a rule that generates a file
1377
- # and writes a stamp file): add them to implicit_deps
1378
- extra_link_deps = set()
1379
- for dep in spec["dependencies"]:
1380
- target = self.target_outputs.get(dep)
1381
- if not target:
1382
- continue
1383
- linkable = target.Linkable()
1384
- if linkable:
1385
- new_deps = []
1386
- if (
1387
- self.flavor == "win"
1388
- and target.component_objs
1389
- and self.msvs_settings.IsUseLibraryDependencyInputs(config_name)
1390
- ):
1391
- new_deps = target.component_objs
1392
- if target.compile_deps:
1393
- order_deps.add(target.compile_deps)
1394
- elif self.flavor == "win" and target.import_lib:
1395
- new_deps = [target.import_lib]
1396
- elif target.UsesToc(self.flavor):
1397
- solibs.add(target.binary)
1398
- implicit_deps.add(target.binary + ".TOC")
1399
- else:
1400
- new_deps = [target.binary]
1401
- for new_dep in new_deps:
1402
- if new_dep not in extra_link_deps:
1403
- extra_link_deps.add(new_dep)
1404
- link_deps.append(new_dep)
1405
-
1406
- final_output = target.FinalOutput()
1407
- if not linkable or final_output != target.binary:
1408
- implicit_deps.add(final_output)
1409
-
1410
- extra_bindings = []
1411
- if self.target.uses_cpp and self.flavor != "win":
1412
- extra_bindings.append(("ld", "$ldxx"))
1413
-
1414
- output = self.ComputeOutput(spec, arch)
1415
- if arch is None and not self.is_mac_bundle:
1416
- self.AppendPostbuildVariable(extra_bindings, spec, output, output)
1417
-
1418
- is_executable = spec["type"] == "executable"
1419
- # The ldflags config key is not used on mac or win. On those platforms
1420
- # linker flags are set via xcode_settings and msvs_settings, respectively.
1421
- if self.toolset == "target":
1422
- env_ldflags = os.environ.get("LDFLAGS", "").split()
1423
- elif self.toolset == "host":
1424
- env_ldflags = os.environ.get("LDFLAGS_host", "").split()
1425
-
1426
- if self.flavor == "mac":
1427
- ldflags = self.xcode_settings.GetLdflags(
1428
- config_name,
1429
- self.ExpandSpecial(generator_default_variables["PRODUCT_DIR"]),
1430
- self.GypPathToNinja,
1431
- arch,
1432
- )
1433
- ldflags = env_ldflags + ldflags
1434
- elif self.flavor == "win":
1435
- manifest_base_name = self.GypPathToUniqueOutput(
1436
- self.ComputeOutputFileName(spec)
1437
- )
1438
- (
1439
- ldflags,
1440
- intermediate_manifest,
1441
- manifest_files,
1442
- ) = self.msvs_settings.GetLdflags(
1443
- config_name,
1444
- self.GypPathToNinja,
1445
- self.ExpandSpecial,
1446
- manifest_base_name,
1447
- output,
1448
- is_executable,
1449
- self.toplevel_build,
1450
- )
1451
- ldflags = env_ldflags + ldflags
1452
- self.WriteVariableList(ninja_file, "manifests", manifest_files)
1453
- implicit_deps = implicit_deps.union(manifest_files)
1454
- if intermediate_manifest:
1455
- self.WriteVariableList(
1456
- ninja_file, "intermediatemanifest", [intermediate_manifest]
1457
- )
1458
- command_suffix = _GetWinLinkRuleNameSuffix(
1459
- self.msvs_settings.IsEmbedManifest(config_name)
1460
- )
1461
- def_file = self.msvs_settings.GetDefFile(self.GypPathToNinja)
1462
- if def_file:
1463
- implicit_deps.add(def_file)
1464
- else:
1465
- # Respect environment variables related to build, but target-specific
1466
- # flags can still override them.
1467
- ldflags = env_ldflags + config.get("ldflags", [])
1468
- if is_executable and len(solibs):
1469
- rpath = "lib/"
1470
- if self.toolset != "target":
1471
- rpath += self.toolset
1472
- ldflags.append(r"-Wl,-rpath=\$$ORIGIN/%s" % rpath)
1473
- else:
1474
- ldflags.append("-Wl,-rpath=%s" % self.target_rpath)
1475
- ldflags.append("-Wl,-rpath-link=%s" % rpath)
1476
- self.WriteVariableList(ninja_file, "ldflags", map(self.ExpandSpecial, ldflags))
1477
-
1478
- library_dirs = config.get("library_dirs", [])
1479
- if self.flavor == "win":
1480
- library_dirs = [
1481
- self.msvs_settings.ConvertVSMacros(library_dir, config_name)
1482
- for library_dir in library_dirs
1483
- ]
1484
- library_dirs = [
1485
- "/LIBPATH:"
1486
- + QuoteShellArgument(self.GypPathToNinja(library_dir), self.flavor)
1487
- for library_dir in library_dirs
1488
- ]
1489
- else:
1490
- library_dirs = [
1491
- QuoteShellArgument("-L" + self.GypPathToNinja(library_dir), self.flavor)
1492
- for library_dir in library_dirs
1493
- ]
1494
-
1495
- libraries = gyp.common.uniquer(
1496
- map(self.ExpandSpecial, spec.get("libraries", []))
1497
- )
1498
- if self.flavor == "mac":
1499
- libraries = self.xcode_settings.AdjustLibraries(libraries, config_name)
1500
- elif self.flavor == "win":
1501
- libraries = self.msvs_settings.AdjustLibraries(libraries)
1502
-
1503
- self.WriteVariableList(ninja_file, "libs", library_dirs + libraries)
1504
-
1505
- linked_binary = output
1506
-
1507
- if command in ("solink", "solink_module"):
1508
- extra_bindings.append(("soname", os.path.split(output)[1]))
1509
- extra_bindings.append(("lib", gyp.common.EncodePOSIXShellArgument(output)))
1510
- if self.flavor != "win":
1511
- link_file_list = output
1512
- if self.is_mac_bundle:
1513
- # 'Dependency Framework.framework/Versions/A/Dependency Framework'
1514
- # -> 'Dependency Framework.framework.rsp'
1515
- link_file_list = self.xcode_settings.GetWrapperName()
1516
- if arch:
1517
- link_file_list += "." + arch
1518
- link_file_list += ".rsp"
1519
- # If an rspfile contains spaces, ninja surrounds the filename with
1520
- # quotes around it and then passes it to open(), creating a file with
1521
- # quotes in its name (and when looking for the rsp file, the name
1522
- # makes it through bash which strips the quotes) :-/
1523
- link_file_list = link_file_list.replace(" ", "_")
1524
- extra_bindings.append(
1525
- (
1526
- "link_file_list",
1527
- gyp.common.EncodePOSIXShellArgument(link_file_list),
1528
- )
1529
- )
1530
- if self.flavor == "win":
1531
- extra_bindings.append(("binary", output))
1532
- if (
1533
- "/NOENTRY" not in ldflags
1534
- and not self.msvs_settings.GetNoImportLibrary(config_name)
1535
- ):
1536
- self.target.import_lib = output + ".lib"
1537
- extra_bindings.append(
1538
- ("implibflag", "/IMPLIB:%s" % self.target.import_lib)
1539
- )
1540
- pdbname = self.msvs_settings.GetPDBName(
1541
- config_name, self.ExpandSpecial, output + ".pdb"
1542
- )
1543
- output = [output, self.target.import_lib]
1544
- if pdbname:
1545
- output.append(pdbname)
1546
- elif not self.is_mac_bundle:
1547
- output = [output, output + ".TOC"]
1548
- else:
1549
- command = command + "_notoc"
1550
- elif self.flavor == "win":
1551
- extra_bindings.append(("binary", output))
1552
- pdbname = self.msvs_settings.GetPDBName(
1553
- config_name, self.ExpandSpecial, output + ".pdb"
1554
- )
1555
- if pdbname:
1556
- output = [output, pdbname]
1557
-
1558
- if len(solibs):
1559
- extra_bindings.append(
1560
- ("solibs", gyp.common.EncodePOSIXShellList(sorted(solibs)))
1561
- )
1562
-
1563
- ninja_file.build(
1564
- output,
1565
- command + command_suffix,
1566
- link_deps,
1567
- implicit=sorted(implicit_deps),
1568
- order_only=list(order_deps),
1569
- variables=extra_bindings,
1570
- )
1571
- return linked_binary
1572
-
1573
- def WriteTarget(self, spec, config_name, config, link_deps, compile_deps):
1574
- extra_link_deps = any(
1575
- self.target_outputs.get(dep).Linkable()
1576
- for dep in spec.get("dependencies", [])
1577
- if dep in self.target_outputs
1578
- )
1579
- if spec["type"] == "none" or (not link_deps and not extra_link_deps):
1580
- # TODO(evan): don't call this function for 'none' target types, as
1581
- # it doesn't do anything, and we fake out a 'binary' with a stamp file.
1582
- self.target.binary = compile_deps
1583
- self.target.type = "none"
1584
- elif spec["type"] == "static_library":
1585
- self.target.binary = self.ComputeOutput(spec)
1586
- if (
1587
- self.flavor not in ("ios", "mac", "netbsd", "openbsd", "win")
1588
- and not self.is_standalone_static_library
1589
- ):
1590
- self.ninja.build(
1591
- self.target.binary, "alink_thin", link_deps, order_only=compile_deps
1592
- )
1593
- else:
1594
- variables = []
1595
- if self.xcode_settings:
1596
- libtool_flags = self.xcode_settings.GetLibtoolflags(config_name)
1597
- if libtool_flags:
1598
- variables.append(("libtool_flags", libtool_flags))
1599
- if self.msvs_settings:
1600
- libflags = self.msvs_settings.GetLibFlags(
1601
- config_name, self.GypPathToNinja
1602
- )
1603
- variables.append(("libflags", libflags))
1604
-
1605
- if self.flavor != "mac" or len(self.archs) == 1:
1606
- self.AppendPostbuildVariable(
1607
- variables, spec, self.target.binary, self.target.binary
1608
- )
1609
- self.ninja.build(
1610
- self.target.binary,
1611
- "alink",
1612
- link_deps,
1613
- order_only=compile_deps,
1614
- variables=variables,
1615
- )
1616
- else:
1617
- inputs = []
1618
- for arch in self.archs:
1619
- output = self.ComputeOutput(spec, arch)
1620
- self.arch_subninjas[arch].build(
1621
- output,
1622
- "alink",
1623
- link_deps[arch],
1624
- order_only=compile_deps,
1625
- variables=variables,
1626
- )
1627
- inputs.append(output)
1628
- # TODO: It's not clear if
1629
- # libtool_flags should be passed to the alink
1630
- # call that combines single-arch .a files into a fat .a file.
1631
- self.AppendPostbuildVariable(
1632
- variables, spec, self.target.binary, self.target.binary
1633
- )
1634
- self.ninja.build(
1635
- self.target.binary,
1636
- "alink",
1637
- inputs,
1638
- # FIXME: test proving order_only=compile_deps isn't
1639
- # needed.
1640
- variables=variables,
1641
- )
1642
- else:
1643
- self.target.binary = self.WriteLink(
1644
- spec, config_name, config, link_deps, compile_deps
1645
- )
1646
- return self.target.binary
1647
-
1648
- def WriteMacBundle(self, spec, mac_bundle_depends, is_empty):
1649
- assert self.is_mac_bundle
1650
- package_framework = spec["type"] in ("shared_library", "loadable_module")
1651
- output = self.ComputeMacBundleOutput()
1652
- if is_empty:
1653
- output += ".stamp"
1654
- variables = []
1655
- self.AppendPostbuildVariable(
1656
- variables,
1657
- spec,
1658
- output,
1659
- self.target.binary,
1660
- is_command_start=not package_framework,
1661
- )
1662
- if package_framework and not is_empty:
1663
- if spec["type"] == "shared_library" and self.xcode_settings.isIOS:
1664
- self.ninja.build(
1665
- output,
1666
- "package_ios_framework",
1667
- mac_bundle_depends,
1668
- variables=variables,
1669
- )
1670
- else:
1671
- variables.append(("version", self.xcode_settings.GetFrameworkVersion()))
1672
- self.ninja.build(
1673
- output, "package_framework", mac_bundle_depends, variables=variables
1674
- )
1675
- else:
1676
- self.ninja.build(output, "stamp", mac_bundle_depends, variables=variables)
1677
- self.target.bundle = output
1678
- return output
1679
-
1680
- def GetToolchainEnv(self, additional_settings=None):
1681
- """Returns the variables toolchain would set for build steps."""
1682
- env = self.GetSortedXcodeEnv(additional_settings=additional_settings)
1683
- if self.flavor == "win":
1684
- env = self.GetMsvsToolchainEnv(additional_settings=additional_settings)
1685
- return env
1686
-
1687
- def GetMsvsToolchainEnv(self, additional_settings=None):
1688
- """Returns the variables Visual Studio would set for build steps."""
1689
- return self.msvs_settings.GetVSMacroEnv(
1690
- "$!PRODUCT_DIR", config=self.config_name
1691
- )
1692
-
1693
- def GetSortedXcodeEnv(self, additional_settings=None):
1694
- """Returns the variables Xcode would set for build steps."""
1695
- assert self.abs_build_dir
1696
- abs_build_dir = self.abs_build_dir
1697
- return gyp.xcode_emulation.GetSortedXcodeEnv(
1698
- self.xcode_settings,
1699
- abs_build_dir,
1700
- os.path.join(abs_build_dir, self.build_to_base),
1701
- self.config_name,
1702
- additional_settings,
1703
- )
1704
-
1705
- def GetSortedXcodePostbuildEnv(self):
1706
- """Returns the variables Xcode would set for postbuild steps."""
1707
- postbuild_settings = {}
1708
- # CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack.
1709
- # TODO(thakis): It would be nice to have some general mechanism instead.
1710
- strip_save_file = self.xcode_settings.GetPerTargetSetting(
1711
- "CHROMIUM_STRIP_SAVE_FILE"
1712
- )
1713
- if strip_save_file:
1714
- postbuild_settings["CHROMIUM_STRIP_SAVE_FILE"] = strip_save_file
1715
- return self.GetSortedXcodeEnv(additional_settings=postbuild_settings)
1716
-
1717
- def AppendPostbuildVariable(
1718
- self, variables, spec, output, binary, is_command_start=False
1719
- ):
1720
- """Adds a 'postbuild' variable if there is a postbuild for |output|."""
1721
- postbuild = self.GetPostbuildCommand(spec, output, binary, is_command_start)
1722
- if postbuild:
1723
- variables.append(("postbuilds", postbuild))
1724
-
1725
- def GetPostbuildCommand(self, spec, output, output_binary, is_command_start):
1726
- """Returns a shell command that runs all the postbuilds, and removes
1727
- |output| if any of them fails. If |is_command_start| is False, then the
1728
- returned string will start with ' && '."""
1729
- if not self.xcode_settings or spec["type"] == "none" or not output:
1730
- return ""
1731
- output = QuoteShellArgument(output, self.flavor)
1732
- postbuilds = gyp.xcode_emulation.GetSpecPostbuildCommands(spec, quiet=True)
1733
- if output_binary is not None:
1734
- postbuilds = self.xcode_settings.AddImplicitPostbuilds(
1735
- self.config_name,
1736
- os.path.normpath(os.path.join(self.base_to_build, output)),
1737
- QuoteShellArgument(
1738
- os.path.normpath(os.path.join(self.base_to_build, output_binary)),
1739
- self.flavor,
1740
- ),
1741
- postbuilds,
1742
- quiet=True,
1743
- )
1744
-
1745
- if not postbuilds:
1746
- return ""
1747
- # Postbuilds expect to be run in the gyp file's directory, so insert an
1748
- # implicit postbuild to cd to there.
1749
- postbuilds.insert(
1750
- 0, gyp.common.EncodePOSIXShellList(["cd", self.build_to_base])
1751
- )
1752
- env = self.ComputeExportEnvString(self.GetSortedXcodePostbuildEnv())
1753
- # G will be non-null if any postbuild fails. Run all postbuilds in a
1754
- # subshell.
1755
- commands = (
1756
- env
1757
- + " ("
1758
- + " && ".join([ninja_syntax.escape(command) for command in postbuilds])
1759
- )
1760
- command_string = (
1761
- commands
1762
- + "); G=$$?; "
1763
- # Remove the final output if any postbuild failed.
1764
- "((exit $$G) || rm -rf %s) " % output
1765
- + "&& exit $$G)"
1766
- )
1767
- if is_command_start:
1768
- return "(" + command_string + " && "
1769
- else:
1770
- return "$ && (" + command_string
1771
-
1772
- def ComputeExportEnvString(self, env):
1773
- """Given an environment, returns a string looking like
1774
- 'export FOO=foo; export BAR="${FOO} bar;'
1775
- that exports |env| to the shell."""
1776
- export_str = []
1777
- for k, v in env:
1778
- export_str.append(
1779
- "export %s=%s;"
1780
- % (k, ninja_syntax.escape(gyp.common.EncodePOSIXShellArgument(v)))
1781
- )
1782
- return " ".join(export_str)
1783
-
1784
- def ComputeMacBundleOutput(self):
1785
- """Return the 'output' (full output path) to a bundle output directory."""
1786
- assert self.is_mac_bundle
1787
- path = generator_default_variables["PRODUCT_DIR"]
1788
- return self.ExpandSpecial(
1789
- os.path.join(path, self.xcode_settings.GetWrapperName())
1790
- )
1791
-
1792
- def ComputeOutputFileName(self, spec, type=None):
1793
- """Compute the filename of the final output for the current target."""
1794
- if not type:
1795
- type = spec["type"]
1796
-
1797
- default_variables = copy.copy(generator_default_variables)
1798
- CalculateVariables(default_variables, {"flavor": self.flavor})
1799
-
1800
- # Compute filename prefix: the product prefix, or a default for
1801
- # the product type.
1802
- DEFAULT_PREFIX = {
1803
- "loadable_module": default_variables["SHARED_LIB_PREFIX"],
1804
- "shared_library": default_variables["SHARED_LIB_PREFIX"],
1805
- "static_library": default_variables["STATIC_LIB_PREFIX"],
1806
- "executable": default_variables["EXECUTABLE_PREFIX"],
1807
- }
1808
- prefix = spec.get("product_prefix", DEFAULT_PREFIX.get(type, ""))
1809
-
1810
- # Compute filename extension: the product extension, or a default
1811
- # for the product type.
1812
- DEFAULT_EXTENSION = {
1813
- "loadable_module": default_variables["SHARED_LIB_SUFFIX"],
1814
- "shared_library": default_variables["SHARED_LIB_SUFFIX"],
1815
- "static_library": default_variables["STATIC_LIB_SUFFIX"],
1816
- "executable": default_variables["EXECUTABLE_SUFFIX"],
1817
- }
1818
- extension = spec.get("product_extension")
1819
- extension = "." + extension if extension else DEFAULT_EXTENSION.get(type, "")
1820
-
1821
- if "product_name" in spec:
1822
- # If we were given an explicit name, use that.
1823
- target = spec["product_name"]
1824
- else:
1825
- # Otherwise, derive a name from the target name.
1826
- target = spec["target_name"]
1827
- if prefix == "lib":
1828
- # Snip out an extra 'lib' from libs if appropriate.
1829
- target = StripPrefix(target, "lib")
1830
-
1831
- if type in (
1832
- "static_library",
1833
- "loadable_module",
1834
- "shared_library",
1835
- "executable",
1836
- ):
1837
- return f"{prefix}{target}{extension}"
1838
- elif type == "none":
1839
- return "%s.stamp" % target
1840
- else:
1841
- raise Exception("Unhandled output type %s" % type)
1842
-
1843
- def ComputeOutput(self, spec, arch=None):
1844
- """Compute the path for the final output of the spec."""
1845
- type = spec["type"]
1846
-
1847
- if self.flavor == "win":
1848
- override = self.msvs_settings.GetOutputName(
1849
- self.config_name, self.ExpandSpecial
1850
- )
1851
- if override:
1852
- return override
1853
-
1854
- if (
1855
- arch is None
1856
- and self.flavor == "mac"
1857
- and type
1858
- in ("static_library", "executable", "shared_library", "loadable_module")
1859
- ):
1860
- filename = self.xcode_settings.GetExecutablePath()
1861
- else:
1862
- filename = self.ComputeOutputFileName(spec, type)
1863
-
1864
- if arch is None and "product_dir" in spec:
1865
- path = os.path.join(spec["product_dir"], filename)
1866
- return self.ExpandSpecial(path)
1867
-
1868
- # Some products go into the output root, libraries go into shared library
1869
- # dir, and everything else goes into the normal place.
1870
- type_in_output_root = ["executable", "loadable_module"]
1871
- if self.flavor == "mac" and self.toolset == "target":
1872
- type_in_output_root += ["shared_library", "static_library"]
1873
- elif self.flavor == "win" and self.toolset == "target":
1874
- type_in_output_root += ["shared_library"]
1875
-
1876
- if arch is not None:
1877
- # Make sure partial executables don't end up in a bundle or the regular
1878
- # output directory.
1879
- archdir = "arch"
1880
- if self.toolset != "target":
1881
- archdir = os.path.join("arch", "%s" % self.toolset)
1882
- return os.path.join(archdir, AddArch(filename, arch))
1883
- elif type in type_in_output_root or self.is_standalone_static_library:
1884
- return filename
1885
- elif type == "shared_library":
1886
- libdir = "lib"
1887
- if self.toolset != "target":
1888
- libdir = os.path.join("lib", "%s" % self.toolset)
1889
- return os.path.join(libdir, filename)
1890
- else:
1891
- return self.GypPathToUniqueOutput(filename, qualified=False)
1892
-
1893
- def WriteVariableList(self, ninja_file, var, values):
1894
- assert not isinstance(values, str)
1895
- if values is None:
1896
- values = []
1897
- ninja_file.variable(var, " ".join(values))
1898
-
1899
- def WriteNewNinjaRule(
1900
- self, name, args, description, win_shell_flags, env, pool, depfile=None
1901
- ):
1902
- """Write out a new ninja "rule" statement for a given command.
1903
-
1904
- Returns the name of the new rule, and a copy of |args| with variables
1905
- expanded."""
1906
-
1907
- if self.flavor == "win":
1908
- args = [
1909
- self.msvs_settings.ConvertVSMacros(
1910
- arg, self.base_to_build, config=self.config_name
1911
- )
1912
- for arg in args
1913
- ]
1914
- description = self.msvs_settings.ConvertVSMacros(
1915
- description, config=self.config_name
1916
- )
1917
- elif self.flavor == "mac":
1918
- # |env| is an empty list on non-mac.
1919
- args = [gyp.xcode_emulation.ExpandEnvVars(arg, env) for arg in args]
1920
- description = gyp.xcode_emulation.ExpandEnvVars(description, env)
1921
-
1922
- # TODO: we shouldn't need to qualify names; we do it because
1923
- # currently the ninja rule namespace is global, but it really
1924
- # should be scoped to the subninja.
1925
- rule_name = self.name
1926
- if self.toolset == "target":
1927
- rule_name += "." + self.toolset
1928
- rule_name += "." + name
1929
- rule_name = re.sub("[^a-zA-Z0-9_]", "_", rule_name)
1930
-
1931
- # Remove variable references, but not if they refer to the magic rule
1932
- # variables. This is not quite right, as it also protects these for
1933
- # actions, not just for rules where they are valid. Good enough.
1934
- protect = ["${root}", "${dirname}", "${source}", "${ext}", "${name}"]
1935
- protect = "(?!" + "|".join(map(re.escape, protect)) + ")"
1936
- description = re.sub(protect + r"\$", "_", description)
1937
-
1938
- # gyp dictates that commands are run from the base directory.
1939
- # cd into the directory before running, and adjust paths in
1940
- # the arguments to point to the proper locations.
1941
- rspfile = None
1942
- rspfile_content = None
1943
- args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args]
1944
- if self.flavor == "win":
1945
- rspfile = rule_name + ".$unique_name.rsp"
1946
- # The cygwin case handles this inside the bash sub-shell.
1947
- run_in = "" if win_shell_flags.cygwin else " " + self.build_to_base
1948
- if win_shell_flags.cygwin:
1949
- rspfile_content = self.msvs_settings.BuildCygwinBashCommandLine(
1950
- args, self.build_to_base
1951
- )
1952
- else:
1953
- rspfile_content = gyp.msvs_emulation.EncodeRspFileList(
1954
- args, win_shell_flags.quote)
1955
- command = (
1956
- "%s gyp-win-tool action-wrapper $arch " % sys.executable
1957
- + rspfile
1958
- + run_in
1959
- )
1960
- else:
1961
- env = self.ComputeExportEnvString(env)
1962
- command = gyp.common.EncodePOSIXShellList(args)
1963
- command = "cd %s; " % self.build_to_base + env + command
1964
-
1965
- # GYP rules/actions express being no-ops by not touching their outputs.
1966
- # Avoid executing downstream dependencies in this case by specifying
1967
- # restat=1 to ninja.
1968
- self.ninja.rule(
1969
- rule_name,
1970
- command,
1971
- description,
1972
- depfile=depfile,
1973
- restat=True,
1974
- pool=pool,
1975
- rspfile=rspfile,
1976
- rspfile_content=rspfile_content,
1977
- )
1978
- self.ninja.newline()
1979
-
1980
- return rule_name, args
1981
-
1982
-
1983
- def CalculateVariables(default_variables, params):
1984
- """Calculate additional variables for use in the build (called by gyp)."""
1985
- global generator_additional_non_configuration_keys
1986
- global generator_additional_path_sections
1987
- flavor = gyp.common.GetFlavor(params)
1988
- if flavor == "mac":
1989
- default_variables.setdefault("OS", "mac")
1990
- default_variables.setdefault("SHARED_LIB_SUFFIX", ".dylib")
1991
- default_variables.setdefault(
1992
- "SHARED_LIB_DIR", generator_default_variables["PRODUCT_DIR"]
1993
- )
1994
- default_variables.setdefault(
1995
- "LIB_DIR", generator_default_variables["PRODUCT_DIR"]
1996
- )
1997
-
1998
- # Copy additional generator configuration data from Xcode, which is shared
1999
- # by the Mac Ninja generator.
2000
- import gyp.generator.xcode as xcode_generator
2001
-
2002
- generator_additional_non_configuration_keys = getattr(
2003
- xcode_generator, "generator_additional_non_configuration_keys", []
2004
- )
2005
- generator_additional_path_sections = getattr(
2006
- xcode_generator, "generator_additional_path_sections", []
2007
- )
2008
- global generator_extra_sources_for_rules
2009
- generator_extra_sources_for_rules = getattr(
2010
- xcode_generator, "generator_extra_sources_for_rules", []
2011
- )
2012
- elif flavor == "win":
2013
- exts = gyp.MSVSUtil.TARGET_TYPE_EXT
2014
- default_variables.setdefault("OS", "win")
2015
- default_variables["EXECUTABLE_SUFFIX"] = "." + exts["executable"]
2016
- default_variables["STATIC_LIB_PREFIX"] = ""
2017
- default_variables["STATIC_LIB_SUFFIX"] = "." + exts["static_library"]
2018
- default_variables["SHARED_LIB_PREFIX"] = ""
2019
- default_variables["SHARED_LIB_SUFFIX"] = "." + exts["shared_library"]
2020
-
2021
- # Copy additional generator configuration data from VS, which is shared
2022
- # by the Windows Ninja generator.
2023
- import gyp.generator.msvs as msvs_generator
2024
-
2025
- generator_additional_non_configuration_keys = getattr(
2026
- msvs_generator, "generator_additional_non_configuration_keys", []
2027
- )
2028
- generator_additional_path_sections = getattr(
2029
- msvs_generator, "generator_additional_path_sections", []
2030
- )
2031
-
2032
- gyp.msvs_emulation.CalculateCommonVariables(default_variables, params)
2033
- else:
2034
- operating_system = flavor
2035
- if flavor == "android":
2036
- operating_system = "linux" # Keep this legacy behavior for now.
2037
- default_variables.setdefault("OS", operating_system)
2038
- default_variables.setdefault("SHARED_LIB_SUFFIX", ".so")
2039
- default_variables.setdefault(
2040
- "SHARED_LIB_DIR", os.path.join("$!PRODUCT_DIR", "lib")
2041
- )
2042
- default_variables.setdefault("LIB_DIR", os.path.join("$!PRODUCT_DIR", "obj"))
2043
-
2044
-
2045
- def ComputeOutputDir(params):
2046
- """Returns the path from the toplevel_dir to the build output directory."""
2047
- # generator_dir: relative path from pwd to where make puts build files.
2048
- # Makes migrating from make to ninja easier, ninja doesn't put anything here.
2049
- generator_dir = os.path.relpath(params["options"].generator_output or ".")
2050
-
2051
- # output_dir: relative path from generator_dir to the build directory.
2052
- output_dir = params.get("generator_flags", {}).get("output_dir", "out")
2053
-
2054
- # Relative path from source root to our output files. e.g. "out"
2055
- return os.path.normpath(os.path.join(generator_dir, output_dir))
2056
-
2057
-
2058
- def CalculateGeneratorInputInfo(params):
2059
- """Called by __init__ to initialize generator values based on params."""
2060
- # E.g. "out/gypfiles"
2061
- toplevel = params["options"].toplevel_dir
2062
- qualified_out_dir = os.path.normpath(
2063
- os.path.join(toplevel, ComputeOutputDir(params), "gypfiles")
2064
- )
2065
-
2066
- global generator_filelist_paths
2067
- generator_filelist_paths = {
2068
- "toplevel": toplevel,
2069
- "qualified_out_dir": qualified_out_dir,
2070
- }
2071
-
2072
-
2073
- def OpenOutput(path, mode="w"):
2074
- """Open |path| for writing, creating directories if necessary."""
2075
- gyp.common.EnsureDirExists(path)
2076
- return open(path, mode)
2077
-
2078
-
2079
- def CommandWithWrapper(cmd, wrappers, prog):
2080
- wrapper = wrappers.get(cmd, "")
2081
- if wrapper:
2082
- return wrapper + " " + prog
2083
- return prog
2084
-
2085
-
2086
- def GetDefaultConcurrentLinks():
2087
- """Returns a best-guess for a number of concurrent links."""
2088
- pool_size = int(os.environ.get("GYP_LINK_CONCURRENCY", 0))
2089
- if pool_size:
2090
- return pool_size
2091
-
2092
- if sys.platform in ("win32", "cygwin"):
2093
- import ctypes
2094
-
2095
- class MEMORYSTATUSEX(ctypes.Structure):
2096
- _fields_ = [
2097
- ("dwLength", ctypes.c_ulong),
2098
- ("dwMemoryLoad", ctypes.c_ulong),
2099
- ("ullTotalPhys", ctypes.c_ulonglong),
2100
- ("ullAvailPhys", ctypes.c_ulonglong),
2101
- ("ullTotalPageFile", ctypes.c_ulonglong),
2102
- ("ullAvailPageFile", ctypes.c_ulonglong),
2103
- ("ullTotalVirtual", ctypes.c_ulonglong),
2104
- ("ullAvailVirtual", ctypes.c_ulonglong),
2105
- ("sullAvailExtendedVirtual", ctypes.c_ulonglong),
2106
- ]
2107
-
2108
- stat = MEMORYSTATUSEX()
2109
- stat.dwLength = ctypes.sizeof(stat)
2110
- ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat))
2111
-
2112
- # VS 2015 uses 20% more working set than VS 2013 and can consume all RAM
2113
- # on a 64 GiB machine.
2114
- mem_limit = max(1, stat.ullTotalPhys // (5 * (2 ** 30))) # total / 5GiB
2115
- hard_cap = max(1, int(os.environ.get("GYP_LINK_CONCURRENCY_MAX", 2 ** 32)))
2116
- return min(mem_limit, hard_cap)
2117
- elif sys.platform.startswith("linux"):
2118
- if os.path.exists("/proc/meminfo"):
2119
- with open("/proc/meminfo") as meminfo:
2120
- memtotal_re = re.compile(r"^MemTotal:\s*(\d*)\s*kB")
2121
- for line in meminfo:
2122
- match = memtotal_re.match(line)
2123
- if not match:
2124
- continue
2125
- # Allow 8Gb per link on Linux because Gold is quite memory hungry
2126
- return max(1, int(match.group(1)) // (8 * (2 ** 20)))
2127
- return 1
2128
- elif sys.platform == "darwin":
2129
- try:
2130
- avail_bytes = int(subprocess.check_output(["sysctl", "-n", "hw.memsize"]))
2131
- # A static library debug build of Chromium's unit_tests takes ~2.7GB, so
2132
- # 4GB per ld process allows for some more bloat.
2133
- return max(1, avail_bytes // (4 * (2 ** 30))) # total / 4GB
2134
- except subprocess.CalledProcessError:
2135
- return 1
2136
- else:
2137
- # TODO(scottmg): Implement this for other platforms.
2138
- return 1
2139
-
2140
-
2141
- def _GetWinLinkRuleNameSuffix(embed_manifest):
2142
- """Returns the suffix used to select an appropriate linking rule depending on
2143
- whether the manifest embedding is enabled."""
2144
- return "_embed" if embed_manifest else ""
2145
-
2146
-
2147
- def _AddWinLinkRules(master_ninja, embed_manifest):
2148
- """Adds link rules for Windows platform to |master_ninja|."""
2149
-
2150
- def FullLinkCommand(ldcmd, out, binary_type):
2151
- resource_name = {"exe": "1", "dll": "2"}[binary_type]
2152
- return (
2153
- "%(python)s gyp-win-tool link-with-manifests $arch %(embed)s "
2154
- '%(out)s "%(ldcmd)s" %(resname)s $mt $rc "$intermediatemanifest" '
2155
- "$manifests"
2156
- % {
2157
- "python": sys.executable,
2158
- "out": out,
2159
- "ldcmd": ldcmd,
2160
- "resname": resource_name,
2161
- "embed": embed_manifest,
2162
- }
2163
- )
2164
-
2165
- rule_name_suffix = _GetWinLinkRuleNameSuffix(embed_manifest)
2166
- use_separate_mspdbsrv = int(os.environ.get("GYP_USE_SEPARATE_MSPDBSRV", "0")) != 0
2167
- dlldesc = "LINK%s(DLL) $binary" % rule_name_suffix.upper()
2168
- dllcmd = (
2169
- "%s gyp-win-tool link-wrapper $arch %s "
2170
- "$ld /nologo $implibflag /DLL /OUT:$binary "
2171
- "@$binary.rsp" % (sys.executable, use_separate_mspdbsrv)
2172
- )
2173
- dllcmd = FullLinkCommand(dllcmd, "$binary", "dll")
2174
- master_ninja.rule(
2175
- "solink" + rule_name_suffix,
2176
- description=dlldesc,
2177
- command=dllcmd,
2178
- rspfile="$binary.rsp",
2179
- rspfile_content="$libs $in_newline $ldflags",
2180
- restat=True,
2181
- pool="link_pool",
2182
- )
2183
- master_ninja.rule(
2184
- "solink_module" + rule_name_suffix,
2185
- description=dlldesc,
2186
- command=dllcmd,
2187
- rspfile="$binary.rsp",
2188
- rspfile_content="$libs $in_newline $ldflags",
2189
- restat=True,
2190
- pool="link_pool",
2191
- )
2192
- # Note that ldflags goes at the end so that it has the option of
2193
- # overriding default settings earlier in the command line.
2194
- exe_cmd = (
2195
- "%s gyp-win-tool link-wrapper $arch %s "
2196
- "$ld /nologo /OUT:$binary @$binary.rsp"
2197
- % (sys.executable, use_separate_mspdbsrv)
2198
- )
2199
- exe_cmd = FullLinkCommand(exe_cmd, "$binary", "exe")
2200
- master_ninja.rule(
2201
- "link" + rule_name_suffix,
2202
- description="LINK%s $binary" % rule_name_suffix.upper(),
2203
- command=exe_cmd,
2204
- rspfile="$binary.rsp",
2205
- rspfile_content="$in_newline $libs $ldflags",
2206
- pool="link_pool",
2207
- )
2208
-
2209
-
2210
- def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name):
2211
- options = params["options"]
2212
- flavor = gyp.common.GetFlavor(params)
2213
- generator_flags = params.get("generator_flags", {})
2214
- generate_compile_commands = generator_flags.get("compile_commands", False)
2215
-
2216
- # build_dir: relative path from source root to our output files.
2217
- # e.g. "out/Debug"
2218
- build_dir = os.path.normpath(os.path.join(ComputeOutputDir(params), config_name))
2219
-
2220
- toplevel_build = os.path.join(options.toplevel_dir, build_dir)
2221
-
2222
- master_ninja_file = OpenOutput(os.path.join(toplevel_build, "build.ninja"))
2223
- master_ninja = ninja_syntax.Writer(master_ninja_file, width=120)
2224
-
2225
- # Put build-time support tools in out/{config_name}.
2226
- gyp.common.CopyTool(flavor, toplevel_build, generator_flags)
2227
-
2228
- # Grab make settings for CC/CXX.
2229
- # The rules are
2230
- # - The priority from low to high is gcc/g++, the 'make_global_settings' in
2231
- # gyp, the environment variable.
2232
- # - If there is no 'make_global_settings' for CC.host/CXX.host or
2233
- # 'CC_host'/'CXX_host' environment variable, cc_host/cxx_host should be set
2234
- # to cc/cxx.
2235
- if flavor == "win":
2236
- ar = "lib.exe"
2237
- # cc and cxx must be set to the correct architecture by overriding with one
2238
- # of cl_x86 or cl_x64 below.
2239
- cc = "UNSET"
2240
- cxx = "UNSET"
2241
- ld = "link.exe"
2242
- ld_host = "$ld"
2243
- else:
2244
- ar = "ar"
2245
- cc = "cc"
2246
- cxx = "c++"
2247
- ld = "$cc"
2248
- ldxx = "$cxx"
2249
- ld_host = "$cc_host"
2250
- ldxx_host = "$cxx_host"
2251
-
2252
- ar_host = ar
2253
- cc_host = None
2254
- cxx_host = None
2255
- cc_host_global_setting = None
2256
- cxx_host_global_setting = None
2257
- clang_cl = None
2258
- nm = "nm"
2259
- nm_host = "nm"
2260
- readelf = "readelf"
2261
- readelf_host = "readelf"
2262
-
2263
- build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
2264
- make_global_settings = data[build_file].get("make_global_settings", [])
2265
- build_to_root = gyp.common.InvertRelativePath(build_dir, options.toplevel_dir)
2266
- wrappers = {}
2267
- for key, value in make_global_settings:
2268
- if key == "AR":
2269
- ar = os.path.join(build_to_root, value)
2270
- if key == "AR.host":
2271
- ar_host = os.path.join(build_to_root, value)
2272
- if key == "CC":
2273
- cc = os.path.join(build_to_root, value)
2274
- if cc.endswith("clang-cl"):
2275
- clang_cl = cc
2276
- if key == "CXX":
2277
- cxx = os.path.join(build_to_root, value)
2278
- if key == "CC.host":
2279
- cc_host = os.path.join(build_to_root, value)
2280
- cc_host_global_setting = value
2281
- if key == "CXX.host":
2282
- cxx_host = os.path.join(build_to_root, value)
2283
- cxx_host_global_setting = value
2284
- if key == "LD":
2285
- ld = os.path.join(build_to_root, value)
2286
- if key == "LD.host":
2287
- ld_host = os.path.join(build_to_root, value)
2288
- if key == "LDXX":
2289
- ldxx = os.path.join(build_to_root, value)
2290
- if key == "LDXX.host":
2291
- ldxx_host = os.path.join(build_to_root, value)
2292
- if key == "NM":
2293
- nm = os.path.join(build_to_root, value)
2294
- if key == "NM.host":
2295
- nm_host = os.path.join(build_to_root, value)
2296
- if key == "READELF":
2297
- readelf = os.path.join(build_to_root, value)
2298
- if key == "READELF.host":
2299
- readelf_host = os.path.join(build_to_root, value)
2300
- if key.endswith("_wrapper"):
2301
- wrappers[key[: -len("_wrapper")]] = os.path.join(build_to_root, value)
2302
-
2303
- # Support wrappers from environment variables too.
2304
- for key, value in os.environ.items():
2305
- if key.lower().endswith("_wrapper"):
2306
- key_prefix = key[: -len("_wrapper")]
2307
- key_prefix = re.sub(r"\.HOST$", ".host", key_prefix)
2308
- wrappers[key_prefix] = os.path.join(build_to_root, value)
2309
-
2310
- mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
2311
- if mac_toolchain_dir:
2312
- wrappers["LINK"] = "export DEVELOPER_DIR='%s' &&" % mac_toolchain_dir
2313
-
2314
- if flavor == "win":
2315
- configs = [
2316
- target_dicts[qualified_target]["configurations"][config_name]
2317
- for qualified_target in target_list
2318
- ]
2319
- shared_system_includes = None
2320
- if not generator_flags.get("ninja_use_custom_environment_files", 0):
2321
- shared_system_includes = gyp.msvs_emulation.ExtractSharedMSVSSystemIncludes(
2322
- configs, generator_flags
2323
- )
2324
- cl_paths = gyp.msvs_emulation.GenerateEnvironmentFiles(
2325
- toplevel_build, generator_flags, shared_system_includes, OpenOutput
2326
- )
2327
- for arch, path in sorted(cl_paths.items()):
2328
- if clang_cl:
2329
- # If we have selected clang-cl, use that instead.
2330
- path = clang_cl
2331
- command = CommandWithWrapper(
2332
- "CC", wrappers, QuoteShellArgument(path, "win")
2333
- )
2334
- if clang_cl:
2335
- # Use clang-cl to cross-compile for x86 or x86_64.
2336
- command += " -m32" if arch == "x86" else " -m64"
2337
- master_ninja.variable("cl_" + arch, command)
2338
-
2339
- cc = GetEnvironFallback(["CC_target", "CC"], cc)
2340
- master_ninja.variable("cc", CommandWithWrapper("CC", wrappers, cc))
2341
- cxx = GetEnvironFallback(["CXX_target", "CXX"], cxx)
2342
- master_ninja.variable("cxx", CommandWithWrapper("CXX", wrappers, cxx))
2343
-
2344
- if flavor == "win":
2345
- master_ninja.variable("ld", ld)
2346
- master_ninja.variable("idl", "midl.exe")
2347
- master_ninja.variable("ar", ar)
2348
- master_ninja.variable("rc", "rc.exe")
2349
- master_ninja.variable("ml_x86", "ml.exe")
2350
- master_ninja.variable("ml_x64", "ml64.exe")
2351
- master_ninja.variable("mt", "mt.exe")
2352
- else:
2353
- master_ninja.variable("ld", CommandWithWrapper("LINK", wrappers, ld))
2354
- master_ninja.variable("ldxx", CommandWithWrapper("LINK", wrappers, ldxx))
2355
- master_ninja.variable("ar", GetEnvironFallback(["AR_target", "AR"], ar))
2356
- if flavor != "mac":
2357
- # Mac does not use readelf/nm for .TOC generation, so avoiding polluting
2358
- # the master ninja with extra unused variables.
2359
- master_ninja.variable("nm", GetEnvironFallback(["NM_target", "NM"], nm))
2360
- master_ninja.variable(
2361
- "readelf", GetEnvironFallback(["READELF_target", "READELF"], readelf)
2362
- )
2363
-
2364
- if generator_supports_multiple_toolsets:
2365
- if not cc_host:
2366
- cc_host = cc
2367
- if not cxx_host:
2368
- cxx_host = cxx
2369
-
2370
- master_ninja.variable("ar_host", GetEnvironFallback(["AR_host"], ar_host))
2371
- master_ninja.variable("nm_host", GetEnvironFallback(["NM_host"], nm_host))
2372
- master_ninja.variable(
2373
- "readelf_host", GetEnvironFallback(["READELF_host"], readelf_host)
2374
- )
2375
- cc_host = GetEnvironFallback(["CC_host"], cc_host)
2376
- cxx_host = GetEnvironFallback(["CXX_host"], cxx_host)
2377
-
2378
- # The environment variable could be used in 'make_global_settings', like
2379
- # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here.
2380
- if "$(CC)" in cc_host and cc_host_global_setting:
2381
- cc_host = cc_host_global_setting.replace("$(CC)", cc)
2382
- if "$(CXX)" in cxx_host and cxx_host_global_setting:
2383
- cxx_host = cxx_host_global_setting.replace("$(CXX)", cxx)
2384
- master_ninja.variable(
2385
- "cc_host", CommandWithWrapper("CC.host", wrappers, cc_host)
2386
- )
2387
- master_ninja.variable(
2388
- "cxx_host", CommandWithWrapper("CXX.host", wrappers, cxx_host)
2389
- )
2390
- if flavor == "win":
2391
- master_ninja.variable("ld_host", ld_host)
2392
- else:
2393
- master_ninja.variable(
2394
- "ld_host", CommandWithWrapper("LINK", wrappers, ld_host)
2395
- )
2396
- master_ninja.variable(
2397
- "ldxx_host", CommandWithWrapper("LINK", wrappers, ldxx_host)
2398
- )
2399
-
2400
- master_ninja.newline()
2401
-
2402
- master_ninja.pool("link_pool", depth=GetDefaultConcurrentLinks())
2403
- master_ninja.newline()
2404
-
2405
- deps = "msvc" if flavor == "win" else "gcc"
2406
-
2407
- if flavor != "win":
2408
- master_ninja.rule(
2409
- "cc",
2410
- description="CC $out",
2411
- command=(
2412
- "$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c "
2413
- "$cflags_pch_c -c $in -o $out"
2414
- ),
2415
- depfile="$out.d",
2416
- deps=deps,
2417
- )
2418
- master_ninja.rule(
2419
- "cc_s",
2420
- description="CC $out",
2421
- command=(
2422
- "$cc $defines $includes $cflags $cflags_c "
2423
- "$cflags_pch_c -c $in -o $out"
2424
- ),
2425
- )
2426
- master_ninja.rule(
2427
- "cxx",
2428
- description="CXX $out",
2429
- command=(
2430
- "$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_cc "
2431
- "$cflags_pch_cc -c $in -o $out"
2432
- ),
2433
- depfile="$out.d",
2434
- deps=deps,
2435
- )
2436
- else:
2437
- # TODO(scottmg) Separate pdb names is a test to see if it works around
2438
- # http://crbug.com/142362. It seems there's a race between the creation of
2439
- # the .pdb by the precompiled header step for .cc and the compilation of
2440
- # .c files. This should be handled by mspdbsrv, but rarely errors out with
2441
- # c1xx : fatal error C1033: cannot open program database
2442
- # By making the rules target separate pdb files this might be avoided.
2443
- cc_command = (
2444
- "ninja -t msvc -e $arch " + "-- "
2445
- "$cc /nologo /showIncludes /FC "
2446
- "@$out.rsp /c $in /Fo$out /Fd$pdbname_c "
2447
- )
2448
- cxx_command = (
2449
- "ninja -t msvc -e $arch " + "-- "
2450
- "$cxx /nologo /showIncludes /FC "
2451
- "@$out.rsp /c $in /Fo$out /Fd$pdbname_cc "
2452
- )
2453
- master_ninja.rule(
2454
- "cc",
2455
- description="CC $out",
2456
- command=cc_command,
2457
- rspfile="$out.rsp",
2458
- rspfile_content="$defines $includes $cflags $cflags_c",
2459
- deps=deps,
2460
- )
2461
- master_ninja.rule(
2462
- "cxx",
2463
- description="CXX $out",
2464
- command=cxx_command,
2465
- rspfile="$out.rsp",
2466
- rspfile_content="$defines $includes $cflags $cflags_cc",
2467
- deps=deps,
2468
- )
2469
- master_ninja.rule(
2470
- "idl",
2471
- description="IDL $in",
2472
- command=(
2473
- "%s gyp-win-tool midl-wrapper $arch $outdir "
2474
- "$tlb $h $dlldata $iid $proxy $in "
2475
- "$midl_includes $idlflags" % sys.executable
2476
- ),
2477
- )
2478
- master_ninja.rule(
2479
- "rc",
2480
- description="RC $in",
2481
- # Note: $in must be last otherwise rc.exe complains.
2482
- command=(
2483
- "%s gyp-win-tool rc-wrapper "
2484
- "$arch $rc $defines $resource_includes $rcflags /fo$out $in"
2485
- % sys.executable
2486
- ),
2487
- )
2488
- master_ninja.rule(
2489
- "asm",
2490
- description="ASM $out",
2491
- command=(
2492
- "%s gyp-win-tool asm-wrapper "
2493
- "$arch $asm $defines $includes $asmflags /c /Fo $out $in"
2494
- % sys.executable
2495
- ),
2496
- )
2497
-
2498
- if flavor not in ("ios", "mac", "win"):
2499
- master_ninja.rule(
2500
- "alink",
2501
- description="AR $out",
2502
- command="rm -f $out && $ar rcs $arflags $out $in",
2503
- )
2504
- master_ninja.rule(
2505
- "alink_thin",
2506
- description="AR $out",
2507
- command="rm -f $out && $ar rcsT $arflags $out $in",
2508
- )
2509
-
2510
- # This allows targets that only need to depend on $lib's API to declare an
2511
- # order-only dependency on $lib.TOC and avoid relinking such downstream
2512
- # dependencies when $lib changes only in non-public ways.
2513
- # The resulting string leaves an uninterpolated %{suffix} which
2514
- # is used in the final substitution below.
2515
- mtime_preserving_solink_base = (
2516
- "if [ ! -e $lib -o ! -e $lib.TOC ]; then "
2517
- "%(solink)s && %(extract_toc)s > $lib.TOC; else "
2518
- "%(solink)s && %(extract_toc)s > $lib.tmp && "
2519
- "if ! cmp -s $lib.tmp $lib.TOC; then mv $lib.tmp $lib.TOC ; "
2520
- "fi; fi"
2521
- % {
2522
- "solink": "$ld -shared $ldflags -o $lib -Wl,-soname=$soname %(suffix)s",
2523
- "extract_toc": (
2524
- "{ $readelf -d $lib | grep SONAME ; "
2525
- "$nm -gD -f p $lib | cut -f1-2 -d' '; }"
2526
- ),
2527
- }
2528
- )
2529
-
2530
- master_ninja.rule(
2531
- "solink",
2532
- description="SOLINK $lib",
2533
- restat=True,
2534
- command=mtime_preserving_solink_base
2535
- % {"suffix": "@$link_file_list"},
2536
- rspfile="$link_file_list",
2537
- rspfile_content=(
2538
- "-Wl,--whole-archive $in $solibs -Wl," "--no-whole-archive $libs"
2539
- ),
2540
- pool="link_pool",
2541
- )
2542
- master_ninja.rule(
2543
- "solink_module",
2544
- description="SOLINK(module) $lib",
2545
- restat=True,
2546
- command=mtime_preserving_solink_base % {"suffix": "@$link_file_list"},
2547
- rspfile="$link_file_list",
2548
- rspfile_content="-Wl,--start-group $in $solibs $libs -Wl,--end-group",
2549
- pool="link_pool",
2550
- )
2551
- master_ninja.rule(
2552
- "link",
2553
- description="LINK $out",
2554
- command=(
2555
- "$ld $ldflags -o $out "
2556
- "-Wl,--start-group $in $solibs $libs -Wl,--end-group"
2557
- ),
2558
- pool="link_pool",
2559
- )
2560
- elif flavor == "win":
2561
- master_ninja.rule(
2562
- "alink",
2563
- description="LIB $out",
2564
- command=(
2565
- "%s gyp-win-tool link-wrapper $arch False "
2566
- "$ar /nologo /ignore:4221 /OUT:$out @$out.rsp" % sys.executable
2567
- ),
2568
- rspfile="$out.rsp",
2569
- rspfile_content="$in_newline $libflags",
2570
- )
2571
- _AddWinLinkRules(master_ninja, embed_manifest=True)
2572
- _AddWinLinkRules(master_ninja, embed_manifest=False)
2573
- else:
2574
- master_ninja.rule(
2575
- "objc",
2576
- description="OBJC $out",
2577
- command=(
2578
- "$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc "
2579
- "$cflags_pch_objc -c $in -o $out"
2580
- ),
2581
- depfile="$out.d",
2582
- deps=deps,
2583
- )
2584
- master_ninja.rule(
2585
- "objcxx",
2586
- description="OBJCXX $out",
2587
- command=(
2588
- "$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_objcc "
2589
- "$cflags_pch_objcc -c $in -o $out"
2590
- ),
2591
- depfile="$out.d",
2592
- deps=deps,
2593
- )
2594
- master_ninja.rule(
2595
- "alink",
2596
- description="LIBTOOL-STATIC $out, POSTBUILDS",
2597
- command="rm -f $out && "
2598
- "./gyp-mac-tool filter-libtool libtool $libtool_flags "
2599
- "-static -o $out $in"
2600
- "$postbuilds",
2601
- )
2602
- master_ninja.rule(
2603
- "lipo",
2604
- description="LIPO $out, POSTBUILDS",
2605
- command="rm -f $out && lipo -create $in -output $out$postbuilds",
2606
- )
2607
- master_ninja.rule(
2608
- "solipo",
2609
- description="SOLIPO $out, POSTBUILDS",
2610
- command=(
2611
- "rm -f $lib $lib.TOC && lipo -create $in -output $lib$postbuilds &&"
2612
- "%(extract_toc)s > $lib.TOC"
2613
- % {
2614
- "extract_toc": "{ otool -l $lib | grep LC_ID_DYLIB -A 5; "
2615
- "nm -gP $lib | cut -f1-2 -d' ' | grep -v U$$; true; }"
2616
- }
2617
- ),
2618
- )
2619
-
2620
- # Record the public interface of $lib in $lib.TOC. See the corresponding
2621
- # comment in the posix section above for details.
2622
- solink_base = "$ld %(type)s $ldflags -o $lib %(suffix)s"
2623
- mtime_preserving_solink_base = (
2624
- "if [ ! -e $lib -o ! -e $lib.TOC ] || "
2625
- # Always force dependent targets to relink if this library
2626
- # reexports something. Handling this correctly would require
2627
- # recursive TOC dumping but this is rare in practice, so punt.
2628
- "otool -l $lib | grep -q LC_REEXPORT_DYLIB ; then "
2629
- "%(solink)s && %(extract_toc)s > $lib.TOC; "
2630
- "else "
2631
- "%(solink)s && %(extract_toc)s > $lib.tmp && "
2632
- "if ! cmp -s $lib.tmp $lib.TOC; then "
2633
- "mv $lib.tmp $lib.TOC ; "
2634
- "fi; "
2635
- "fi"
2636
- % {
2637
- "solink": solink_base,
2638
- "extract_toc": "{ otool -l $lib | grep LC_ID_DYLIB -A 5; "
2639
- "nm -gP $lib | cut -f1-2 -d' ' | grep -v U$$; true; }",
2640
- }
2641
- )
2642
-
2643
- solink_suffix = "@$link_file_list$postbuilds"
2644
- master_ninja.rule(
2645
- "solink",
2646
- description="SOLINK $lib, POSTBUILDS",
2647
- restat=True,
2648
- command=mtime_preserving_solink_base
2649
- % {"suffix": solink_suffix, "type": "-shared"},
2650
- rspfile="$link_file_list",
2651
- rspfile_content="$in $solibs $libs",
2652
- pool="link_pool",
2653
- )
2654
- master_ninja.rule(
2655
- "solink_notoc",
2656
- description="SOLINK $lib, POSTBUILDS",
2657
- restat=True,
2658
- command=solink_base % {"suffix": solink_suffix, "type": "-shared"},
2659
- rspfile="$link_file_list",
2660
- rspfile_content="$in $solibs $libs",
2661
- pool="link_pool",
2662
- )
2663
-
2664
- master_ninja.rule(
2665
- "solink_module",
2666
- description="SOLINK(module) $lib, POSTBUILDS",
2667
- restat=True,
2668
- command=mtime_preserving_solink_base
2669
- % {"suffix": solink_suffix, "type": "-bundle"},
2670
- rspfile="$link_file_list",
2671
- rspfile_content="$in $solibs $libs",
2672
- pool="link_pool",
2673
- )
2674
- master_ninja.rule(
2675
- "solink_module_notoc",
2676
- description="SOLINK(module) $lib, POSTBUILDS",
2677
- restat=True,
2678
- command=solink_base % {"suffix": solink_suffix, "type": "-bundle"},
2679
- rspfile="$link_file_list",
2680
- rspfile_content="$in $solibs $libs",
2681
- pool="link_pool",
2682
- )
2683
-
2684
- master_ninja.rule(
2685
- "link",
2686
- description="LINK $out, POSTBUILDS",
2687
- command=("$ld $ldflags -o $out " "$in $solibs $libs$postbuilds"),
2688
- pool="link_pool",
2689
- )
2690
- master_ninja.rule(
2691
- "preprocess_infoplist",
2692
- description="PREPROCESS INFOPLIST $out",
2693
- command=(
2694
- "$cc -E -P -Wno-trigraphs -x c $defines $in -o $out && "
2695
- "plutil -convert xml1 $out $out"
2696
- ),
2697
- )
2698
- master_ninja.rule(
2699
- "copy_infoplist",
2700
- description="COPY INFOPLIST $in",
2701
- command="$env ./gyp-mac-tool copy-info-plist $in $out $binary $keys",
2702
- )
2703
- master_ninja.rule(
2704
- "merge_infoplist",
2705
- description="MERGE INFOPLISTS $in",
2706
- command="$env ./gyp-mac-tool merge-info-plist $out $in",
2707
- )
2708
- master_ninja.rule(
2709
- "compile_xcassets",
2710
- description="COMPILE XCASSETS $in",
2711
- command="$env ./gyp-mac-tool compile-xcassets $keys $in",
2712
- )
2713
- master_ninja.rule(
2714
- "compile_ios_framework_headers",
2715
- description="COMPILE HEADER MAPS AND COPY FRAMEWORK HEADERS $in",
2716
- command="$env ./gyp-mac-tool compile-ios-framework-header-map $out "
2717
- "$framework $in && $env ./gyp-mac-tool "
2718
- "copy-ios-framework-headers $framework $copy_headers",
2719
- )
2720
- master_ninja.rule(
2721
- "mac_tool",
2722
- description="MACTOOL $mactool_cmd $in",
2723
- command="$env ./gyp-mac-tool $mactool_cmd $in $out $binary",
2724
- )
2725
- master_ninja.rule(
2726
- "package_framework",
2727
- description="PACKAGE FRAMEWORK $out, POSTBUILDS",
2728
- command="./gyp-mac-tool package-framework $out $version$postbuilds "
2729
- "&& touch $out",
2730
- )
2731
- master_ninja.rule(
2732
- "package_ios_framework",
2733
- description="PACKAGE IOS FRAMEWORK $out, POSTBUILDS",
2734
- command="./gyp-mac-tool package-ios-framework $out $postbuilds "
2735
- "&& touch $out",
2736
- )
2737
- if flavor == "win":
2738
- master_ninja.rule(
2739
- "stamp",
2740
- description="STAMP $out",
2741
- command="%s gyp-win-tool stamp $out" % sys.executable,
2742
- )
2743
- else:
2744
- master_ninja.rule(
2745
- "stamp", description="STAMP $out", command="${postbuilds}touch $out"
2746
- )
2747
- if flavor == "win":
2748
- master_ninja.rule(
2749
- "copy",
2750
- description="COPY $in $out",
2751
- command="%s gyp-win-tool recursive-mirror $in $out" % sys.executable,
2752
- )
2753
- elif flavor == "zos":
2754
- master_ninja.rule(
2755
- "copy",
2756
- description="COPY $in $out",
2757
- command="rm -rf $out && cp -fRP $in $out",
2758
- )
2759
- else:
2760
- master_ninja.rule(
2761
- "copy",
2762
- description="COPY $in $out",
2763
- command="ln -f $in $out 2>/dev/null || (rm -rf $out && cp -af $in $out)",
2764
- )
2765
- master_ninja.newline()
2766
-
2767
- all_targets = set()
2768
- for build_file in params["build_files"]:
2769
- for target in gyp.common.AllTargets(
2770
- target_list, target_dicts, os.path.normpath(build_file)
2771
- ):
2772
- all_targets.add(target)
2773
- all_outputs = set()
2774
-
2775
- # target_outputs is a map from qualified target name to a Target object.
2776
- target_outputs = {}
2777
- # target_short_names is a map from target short name to a list of Target
2778
- # objects.
2779
- target_short_names = {}
2780
-
2781
- # short name of targets that were skipped because they didn't contain anything
2782
- # interesting.
2783
- # NOTE: there may be overlap between this an non_empty_target_names.
2784
- empty_target_names = set()
2785
-
2786
- # Set of non-empty short target names.
2787
- # NOTE: there may be overlap between this an empty_target_names.
2788
- non_empty_target_names = set()
2789
-
2790
- for qualified_target in target_list:
2791
- # qualified_target is like: third_party/icu/icu.gyp:icui18n#target
2792
- build_file, name, toolset = gyp.common.ParseQualifiedTarget(qualified_target)
2793
-
2794
- this_make_global_settings = data[build_file].get("make_global_settings", [])
2795
- assert make_global_settings == this_make_global_settings, (
2796
- "make_global_settings needs to be the same for all targets. "
2797
- f"{this_make_global_settings} vs. {make_global_settings}"
2798
- )
2799
-
2800
- spec = target_dicts[qualified_target]
2801
- if flavor == "mac":
2802
- gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec)
2803
-
2804
- # If build_file is a symlink, we must not follow it because there's a chance
2805
- # it could point to a path above toplevel_dir, and we cannot correctly deal
2806
- # with that case at the moment.
2807
- build_file = gyp.common.RelativePath(build_file, options.toplevel_dir, False)
2808
-
2809
- qualified_target_for_hash = gyp.common.QualifiedTarget(
2810
- build_file, name, toolset
2811
- )
2812
- qualified_target_for_hash = qualified_target_for_hash.encode("utf-8")
2813
- hash_for_rules = hashlib.md5(qualified_target_for_hash).hexdigest()
2814
-
2815
- base_path = os.path.dirname(build_file)
2816
- obj = "obj"
2817
- if toolset != "target":
2818
- obj += "." + toolset
2819
- output_file = os.path.join(obj, base_path, name + ".ninja")
2820
-
2821
- ninja_output = StringIO()
2822
- writer = NinjaWriter(
2823
- hash_for_rules,
2824
- target_outputs,
2825
- base_path,
2826
- build_dir,
2827
- ninja_output,
2828
- toplevel_build,
2829
- output_file,
2830
- flavor,
2831
- toplevel_dir=options.toplevel_dir,
2832
- )
2833
-
2834
- target = writer.WriteSpec(spec, config_name, generator_flags)
2835
-
2836
- if ninja_output.tell() > 0:
2837
- # Only create files for ninja files that actually have contents.
2838
- with OpenOutput(os.path.join(toplevel_build, output_file)) as ninja_file:
2839
- ninja_file.write(ninja_output.getvalue())
2840
- ninja_output.close()
2841
- master_ninja.subninja(output_file)
2842
-
2843
- if target:
2844
- if name != target.FinalOutput() and spec["toolset"] == "target":
2845
- target_short_names.setdefault(name, []).append(target)
2846
- target_outputs[qualified_target] = target
2847
- if qualified_target in all_targets:
2848
- all_outputs.add(target.FinalOutput())
2849
- non_empty_target_names.add(name)
2850
- else:
2851
- empty_target_names.add(name)
2852
-
2853
- if target_short_names:
2854
- # Write a short name to build this target. This benefits both the
2855
- # "build chrome" case as well as the gyp tests, which expect to be
2856
- # able to run actions and build libraries by their short name.
2857
- master_ninja.newline()
2858
- master_ninja.comment("Short names for targets.")
2859
- for short_name in sorted(target_short_names):
2860
- master_ninja.build(
2861
- short_name,
2862
- "phony",
2863
- [x.FinalOutput() for x in target_short_names[short_name]],
2864
- )
2865
-
2866
- # Write phony targets for any empty targets that weren't written yet. As
2867
- # short names are not necessarily unique only do this for short names that
2868
- # haven't already been output for another target.
2869
- empty_target_names = empty_target_names - non_empty_target_names
2870
- if empty_target_names:
2871
- master_ninja.newline()
2872
- master_ninja.comment("Empty targets (output for completeness).")
2873
- for name in sorted(empty_target_names):
2874
- master_ninja.build(name, "phony")
2875
-
2876
- if all_outputs:
2877
- master_ninja.newline()
2878
- master_ninja.build("all", "phony", sorted(all_outputs))
2879
- master_ninja.default(generator_flags.get("default_target", "all"))
2880
-
2881
- master_ninja_file.close()
2882
-
2883
- if generate_compile_commands:
2884
- compile_db = GenerateCompileDBWithNinja(toplevel_build)
2885
- compile_db_file = OpenOutput(
2886
- os.path.join(toplevel_build, "compile_commands.json")
2887
- )
2888
- compile_db_file.write(json.dumps(compile_db, indent=2))
2889
- compile_db_file.close()
2890
-
2891
-
2892
- def GenerateCompileDBWithNinja(path, targets=["all"]):
2893
- """Generates a compile database using ninja.
2894
-
2895
- Args:
2896
- path: The build directory to generate a compile database for.
2897
- targets: Additional targets to pass to ninja.
2898
-
2899
- Returns:
2900
- List of the contents of the compile database.
2901
- """
2902
- ninja_path = shutil.which("ninja")
2903
- if ninja_path is None:
2904
- raise Exception("ninja not found in PATH")
2905
- json_compile_db = subprocess.check_output(
2906
- [ninja_path, "-C", path]
2907
- + targets
2908
- + ["-t", "compdb", "cc", "cxx", "objc", "objcxx"]
2909
- )
2910
- return json.loads(json_compile_db)
2911
-
2912
-
2913
- def PerformBuild(data, configurations, params):
2914
- options = params["options"]
2915
- for config in configurations:
2916
- builddir = os.path.join(options.toplevel_dir, "out", config)
2917
- arguments = ["ninja", "-C", builddir]
2918
- print(f"Building [{config}]: {arguments}")
2919
- subprocess.check_call(arguments)
2920
-
2921
-
2922
- def CallGenerateOutputForConfig(arglist):
2923
- # Ignore the interrupt signal so that the parent process catches it and
2924
- # kills all multiprocessing children.
2925
- signal.signal(signal.SIGINT, signal.SIG_IGN)
2926
-
2927
- (target_list, target_dicts, data, params, config_name) = arglist
2928
- GenerateOutputForConfig(target_list, target_dicts, data, params, config_name)
2929
-
2930
-
2931
- def GenerateOutput(target_list, target_dicts, data, params):
2932
- # Update target_dicts for iOS device builds.
2933
- target_dicts = gyp.xcode_emulation.CloneConfigurationForDeviceAndEmulator(
2934
- target_dicts
2935
- )
2936
-
2937
- user_config = params.get("generator_flags", {}).get("config", None)
2938
- if gyp.common.GetFlavor(params) == "win":
2939
- target_list, target_dicts = MSVSUtil.ShardTargets(target_list, target_dicts)
2940
- target_list, target_dicts = MSVSUtil.InsertLargePdbShims(
2941
- target_list, target_dicts, generator_default_variables
2942
- )
2943
-
2944
- if user_config:
2945
- GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
2946
- else:
2947
- config_names = target_dicts[target_list[0]]["configurations"]
2948
- if params["parallel"]:
2949
- try:
2950
- pool = multiprocessing.Pool(len(config_names))
2951
- arglists = []
2952
- for config_name in config_names:
2953
- arglists.append(
2954
- (target_list, target_dicts, data, params, config_name)
2955
- )
2956
- pool.map(CallGenerateOutputForConfig, arglists)
2957
- except KeyboardInterrupt as e:
2958
- pool.terminate()
2959
- raise e
2960
- else:
2961
- for config_name in config_names:
2962
- GenerateOutputForConfig(
2963
- target_list, target_dicts, data, params, config_name
2964
- )