@btc-vision/bitcoin 6.4.10 → 6.5.1

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 (220) hide show
  1. package/.babelrc +13 -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/chunks/crypto-C6FlKKmp.js +2006 -0
  9. package/browser/chunks/payments-BE4vwHhV.js +1045 -0
  10. package/browser/chunks/psbt-Dlosf9CT.js +3853 -0
  11. package/browser/chunks/script-COWGdiOo.js +318 -0
  12. package/browser/chunks/transaction-BiXwH2v4.js +421 -0
  13. package/browser/chunks/utils-BKmkTzNZ.js +759 -0
  14. package/browser/crypto/crypto.d.ts +1 -1
  15. package/browser/index.d.ts +7 -27
  16. package/browser/index.js +92 -2
  17. package/build/index.d.ts +7 -27
  18. package/build/index.js +2 -2
  19. package/cjs/package.json +3 -3
  20. package/gulpfile.js +42 -42
  21. package/package.json +153 -150
  22. package/src/bip66.ts +107 -107
  23. package/src/block.ts +233 -233
  24. package/src/bufferutils.ts +188 -188
  25. package/src/crypto.ts +108 -108
  26. package/src/ecc_lib.ts +94 -94
  27. package/src/hooks/AdvancedSignatureManager.ts +104 -104
  28. package/src/hooks/SignatureManager.ts +84 -84
  29. package/src/index.ts +83 -105
  30. package/src/merkle.ts +31 -31
  31. package/src/opcodes.ts +280 -280
  32. package/src/payments/bip341.ts +140 -140
  33. package/src/payments/embed.ts +61 -61
  34. package/src/payments/index.ts +172 -172
  35. package/src/payments/lazy.ts +28 -28
  36. package/src/payments/p2ms.ts +156 -156
  37. package/src/payments/p2op.ts +195 -195
  38. package/src/payments/p2pk.ts +93 -93
  39. package/src/payments/p2pkh.ts +214 -214
  40. package/src/payments/p2tr.ts +309 -309
  41. package/src/psbt/bip371.ts +441 -441
  42. package/src/push_data.ts +97 -97
  43. package/src/script.ts +247 -247
  44. package/src/script_number.ts +72 -72
  45. package/src/script_signature.ts +91 -91
  46. package/src/transaction.ts +656 -656
  47. package/test/address.spec.ts +155 -155
  48. package/test/bitcoin.core.spec.ts +212 -212
  49. package/test/block.spec.ts +171 -171
  50. package/test/bufferutils.spec.ts +450 -450
  51. package/test/crypto.spec.ts +49 -49
  52. package/test/fixtures/address.json +329 -329
  53. package/test/fixtures/block.json +148 -148
  54. package/test/fixtures/bufferutils.json +102 -102
  55. package/test/fixtures/core/README.md +26 -26
  56. package/test/fixtures/core/base58_encode_decode.json +50 -50
  57. package/test/fixtures/core/base58_keys_invalid.json +152 -152
  58. package/test/fixtures/core/base58_keys_valid.json +452 -452
  59. package/test/fixtures/core/blocks.json +27 -27
  60. package/test/fixtures/core/sig_canonical.json +7 -7
  61. package/test/fixtures/core/sig_noncanonical.json +33 -33
  62. package/test/fixtures/core/sighash.json +3505 -3505
  63. package/test/fixtures/core/tx_valid.json +2023 -2023
  64. package/test/fixtures/crypto.json +43 -43
  65. package/test/fixtures/ecdsa.json +217 -217
  66. package/test/fixtures/ecpair.json +141 -141
  67. package/test/fixtures/embed.json +108 -108
  68. package/test/fixtures/p2ms.json +434 -434
  69. package/test/fixtures/p2pk.json +179 -179
  70. package/test/fixtures/p2pkh.json +276 -276
  71. package/test/fixtures/p2sh.json +508 -508
  72. package/test/fixtures/p2tr.json +1198 -1198
  73. package/test/fixtures/p2wpkh.json +290 -290
  74. package/test/fixtures/p2wsh.json +489 -489
  75. package/test/fixtures/psbt.json +924 -924
  76. package/test/fixtures/script.json +465 -465
  77. package/test/fixtures/script_number.json +225 -225
  78. package/test/fixtures/signature.json +140 -140
  79. package/test/fixtures/transaction.json +916 -916
  80. package/test/integration/_regtest.ts +6 -6
  81. package/test/integration/addresses.spec.ts +142 -142
  82. package/test/integration/bip32.spec.ts +130 -130
  83. package/test/integration/blocks.spec.ts +28 -28
  84. package/test/integration/cltv.spec.ts +241 -241
  85. package/test/integration/csv.spec.ts +452 -452
  86. package/test/integration/payments.spec.ts +110 -110
  87. package/test/integration/taproot.spec.ts +663 -663
  88. package/test/integration/transactions.spec.ts +668 -668
  89. package/test/payments.spec.ts +114 -114
  90. package/test/payments.utils.ts +165 -165
  91. package/test/psbt.spec.ts +1285 -1285
  92. package/test/script.spec.ts +186 -186
  93. package/test/script_number.spec.ts +26 -26
  94. package/test/script_signature.spec.ts +66 -66
  95. package/test/transaction.spec.ts +337 -337
  96. package/test/ts-node-register.js +7 -7
  97. package/test/tsconfig.json +48 -48
  98. package/test/types.spec.ts +53 -53
  99. package/tsconfig.base.json +27 -27
  100. package/tsconfig.json +19 -19
  101. package/tsconfig.webpack.json +18 -18
  102. package/vite.config.browser.ts +93 -0
  103. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.ready +0 -0
  104. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.release-please-manifest.json +0 -3
  105. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CHANGELOG.md +0 -962
  106. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CONTRIBUTING.md +0 -34
  107. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/LICENSE +0 -24
  108. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/README.md +0 -273
  109. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/SECURITY.md +0 -2
  110. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/addon.gypi +0 -204
  111. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/bin/node-gyp.js +0 -138
  112. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/.release-please-manifest.json +0 -3
  113. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/LICENSE +0 -28
  114. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/ninja/build.ninja +0 -4
  115. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +0 -12
  116. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/GypVsCMake.md +0 -116
  117. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Hacking.md +0 -46
  118. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/InputFormatReference.md +0 -1080
  119. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/LanguageSpecification.md +0 -430
  120. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/README.md +0 -27
  121. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Testing.md +0 -450
  122. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/UserDocumentation.md +0 -965
  123. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp +0 -8
  124. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp.bat +0 -5
  125. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp_main.py +0 -45
  126. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +0 -365
  127. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +0 -206
  128. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +0 -1272
  129. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +0 -1547
  130. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +0 -59
  131. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +0 -153
  132. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +0 -271
  133. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +0 -574
  134. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +0 -692
  135. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common.py +0 -711
  136. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +0 -171
  137. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +0 -169
  138. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +0 -113
  139. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +0 -55
  140. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  141. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +0 -804
  142. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +0 -1173
  143. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +0 -1318
  144. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +0 -127
  145. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +0 -103
  146. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +0 -461
  147. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +0 -89
  148. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +0 -57
  149. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +0 -2745
  150. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +0 -3976
  151. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +0 -44
  152. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +0 -2964
  153. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +0 -67
  154. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +0 -1391
  155. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +0 -25
  156. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input.py +0 -3115
  157. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +0 -98
  158. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +0 -771
  159. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +0 -1260
  160. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +0 -174
  161. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +0 -61
  162. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +0 -373
  163. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +0 -1938
  164. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +0 -53
  165. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +0 -302
  166. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +0 -3198
  167. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +0 -65
  168. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +0 -3
  169. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +0 -177
  170. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +0 -23
  171. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +0 -15
  172. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +0 -108
  173. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +0 -252
  174. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +0 -83
  175. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +0 -359
  176. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +0 -61
  177. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +0 -192
  178. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/markers.py +0 -252
  179. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +0 -825
  180. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  181. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +0 -90
  182. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +0 -1030
  183. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/tags.py +0 -553
  184. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/utils.py +0 -172
  185. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/version.py +0 -563
  186. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pyproject.toml +0 -120
  187. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/release-please-config.json +0 -11
  188. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/test_gyp.py +0 -261
  189. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/Find-VisualStudio.cs +0 -250
  190. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/build.js +0 -227
  191. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/clean.js +0 -15
  192. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/configure.js +0 -328
  193. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/create-config-gypi.js +0 -150
  194. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/download.js +0 -39
  195. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-node-directory.js +0 -63
  196. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-python.js +0 -310
  197. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-visualstudio.js +0 -590
  198. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/install.js +0 -415
  199. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/list.js +0 -26
  200. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/log.js +0 -168
  201. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/node-gyp.js +0 -188
  202. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/process-release.js +0 -146
  203. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/rebuild.js +0 -12
  204. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/remove.js +0 -43
  205. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/util.js +0 -81
  206. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/macOS_Catalina_acid_test.sh +0 -21
  207. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/package.json +0 -51
  208. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/release-please-config.json +0 -40
  209. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/src/win_delay_load_hook.cc +0 -39
  210. package/browser/index.js.LICENSE.txt +0 -14
  211. package/browser/ops.d.ts +0 -126
  212. package/build/ops.d.ts +0 -126
  213. package/build/ops.js +0 -127
  214. package/coverage/tmp/coverage-31752-1735543485354-0.json +0 -1
  215. package/coverage/tmp/coverage-59920-1735543484555-0.json +0 -1
  216. package/coverage/tmp/coverage-66252-1735543483919-0.json +0 -1
  217. package/coverage/tmp/coverage-68440-1735543485236-0.json +0 -1
  218. package/coverage/tmp/coverage-70588-1735543484426-0.json +0 -1
  219. package/coverage/tmp/coverage-79292-1735543485296-0.json +0 -1
  220. package/coverage/tmp/coverage-80212-1735543483980-0.json +0 -1
@@ -1,1938 +0,0 @@
1
- # Copyright (c) 2012 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
- This module contains classes that help to emulate xcodebuild behavior on top of
7
- other build systems, such as make and ninja.
8
- """
9
-
10
-
11
- import copy
12
- import gyp.common
13
- import os
14
- import os.path
15
- import re
16
- import shlex
17
- import subprocess
18
- import sys
19
- from gyp.common import GypError
20
-
21
- # Populated lazily by XcodeVersion, for efficiency, and to fix an issue when
22
- # "xcodebuild" is called too quickly (it has been found to return incorrect
23
- # version number).
24
- XCODE_VERSION_CACHE = None
25
-
26
- # Populated lazily by GetXcodeArchsDefault, to an |XcodeArchsDefault| instance
27
- # corresponding to the installed version of Xcode.
28
- XCODE_ARCHS_DEFAULT_CACHE = None
29
-
30
-
31
- def XcodeArchsVariableMapping(archs, archs_including_64_bit=None):
32
- """Constructs a dictionary with expansion for $(ARCHS_STANDARD) variable,
33
- and optionally for $(ARCHS_STANDARD_INCLUDING_64_BIT)."""
34
- mapping = {"$(ARCHS_STANDARD)": archs}
35
- if archs_including_64_bit:
36
- mapping["$(ARCHS_STANDARD_INCLUDING_64_BIT)"] = archs_including_64_bit
37
- return mapping
38
-
39
-
40
- class XcodeArchsDefault:
41
- """A class to resolve ARCHS variable from xcode_settings, resolving Xcode
42
- macros and implementing filtering by VALID_ARCHS. The expansion of macros
43
- depends on the SDKROOT used ("macosx", "iphoneos", "iphonesimulator") and
44
- on the version of Xcode.
45
- """
46
-
47
- # Match variable like $(ARCHS_STANDARD).
48
- variable_pattern = re.compile(r"\$\([a-zA-Z_][a-zA-Z0-9_]*\)$")
49
-
50
- def __init__(self, default, mac, iphonesimulator, iphoneos):
51
- self._default = (default,)
52
- self._archs = {"mac": mac, "ios": iphoneos, "iossim": iphonesimulator}
53
-
54
- def _VariableMapping(self, sdkroot):
55
- """Returns the dictionary of variable mapping depending on the SDKROOT."""
56
- sdkroot = sdkroot.lower()
57
- if "iphoneos" in sdkroot:
58
- return self._archs["ios"]
59
- elif "iphonesimulator" in sdkroot:
60
- return self._archs["iossim"]
61
- else:
62
- return self._archs["mac"]
63
-
64
- def _ExpandArchs(self, archs, sdkroot):
65
- """Expands variables references in ARCHS, and remove duplicates."""
66
- variable_mapping = self._VariableMapping(sdkroot)
67
- expanded_archs = []
68
- for arch in archs:
69
- if self.variable_pattern.match(arch):
70
- variable = arch
71
- try:
72
- variable_expansion = variable_mapping[variable]
73
- for arch in variable_expansion:
74
- if arch not in expanded_archs:
75
- expanded_archs.append(arch)
76
- except KeyError:
77
- print('Warning: Ignoring unsupported variable "%s".' % variable)
78
- elif arch not in expanded_archs:
79
- expanded_archs.append(arch)
80
- return expanded_archs
81
-
82
- def ActiveArchs(self, archs, valid_archs, sdkroot):
83
- """Expands variables references in ARCHS, and filter by VALID_ARCHS if it
84
- is defined (if not set, Xcode accept any value in ARCHS, otherwise, only
85
- values present in VALID_ARCHS are kept)."""
86
- expanded_archs = self._ExpandArchs(archs or self._default, sdkroot or "")
87
- if valid_archs:
88
- filtered_archs = []
89
- for arch in expanded_archs:
90
- if arch in valid_archs:
91
- filtered_archs.append(arch)
92
- expanded_archs = filtered_archs
93
- return expanded_archs
94
-
95
-
96
- def GetXcodeArchsDefault():
97
- """Returns the |XcodeArchsDefault| object to use to expand ARCHS for the
98
- installed version of Xcode. The default values used by Xcode for ARCHS
99
- and the expansion of the variables depends on the version of Xcode used.
100
-
101
- For all version anterior to Xcode 5.0 or posterior to Xcode 5.1 included
102
- uses $(ARCHS_STANDARD) if ARCHS is unset, while Xcode 5.0 to 5.0.2 uses
103
- $(ARCHS_STANDARD_INCLUDING_64_BIT). This variable was added to Xcode 5.0
104
- and deprecated with Xcode 5.1.
105
-
106
- For "macosx" SDKROOT, all version starting with Xcode 5.0 includes 64-bit
107
- architecture as part of $(ARCHS_STANDARD) and default to only building it.
108
-
109
- For "iphoneos" and "iphonesimulator" SDKROOT, 64-bit architectures are part
110
- of $(ARCHS_STANDARD_INCLUDING_64_BIT) from Xcode 5.0. From Xcode 5.1, they
111
- are also part of $(ARCHS_STANDARD).
112
-
113
- All these rules are coded in the construction of the |XcodeArchsDefault|
114
- object to use depending on the version of Xcode detected. The object is
115
- for performance reason."""
116
- global XCODE_ARCHS_DEFAULT_CACHE
117
- if XCODE_ARCHS_DEFAULT_CACHE:
118
- return XCODE_ARCHS_DEFAULT_CACHE
119
- xcode_version, _ = XcodeVersion()
120
- if xcode_version < "0500":
121
- XCODE_ARCHS_DEFAULT_CACHE = XcodeArchsDefault(
122
- "$(ARCHS_STANDARD)",
123
- XcodeArchsVariableMapping(["i386"]),
124
- XcodeArchsVariableMapping(["i386"]),
125
- XcodeArchsVariableMapping(["armv7"]),
126
- )
127
- elif xcode_version < "0510":
128
- XCODE_ARCHS_DEFAULT_CACHE = XcodeArchsDefault(
129
- "$(ARCHS_STANDARD_INCLUDING_64_BIT)",
130
- XcodeArchsVariableMapping(["x86_64"], ["x86_64"]),
131
- XcodeArchsVariableMapping(["i386"], ["i386", "x86_64"]),
132
- XcodeArchsVariableMapping(
133
- ["armv7", "armv7s"], ["armv7", "armv7s", "arm64"]
134
- ),
135
- )
136
- else:
137
- XCODE_ARCHS_DEFAULT_CACHE = XcodeArchsDefault(
138
- "$(ARCHS_STANDARD)",
139
- XcodeArchsVariableMapping(["x86_64"], ["x86_64"]),
140
- XcodeArchsVariableMapping(["i386", "x86_64"], ["i386", "x86_64"]),
141
- XcodeArchsVariableMapping(
142
- ["armv7", "armv7s", "arm64"], ["armv7", "armv7s", "arm64"]
143
- ),
144
- )
145
- return XCODE_ARCHS_DEFAULT_CACHE
146
-
147
-
148
- class XcodeSettings:
149
- """A class that understands the gyp 'xcode_settings' object."""
150
-
151
- # Populated lazily by _SdkPath(). Shared by all XcodeSettings, so cached
152
- # at class-level for efficiency.
153
- _sdk_path_cache = {}
154
- _platform_path_cache = {}
155
- _sdk_root_cache = {}
156
-
157
- # Populated lazily by GetExtraPlistItems(). Shared by all XcodeSettings, so
158
- # cached at class-level for efficiency.
159
- _plist_cache = {}
160
-
161
- # Populated lazily by GetIOSPostbuilds. Shared by all XcodeSettings, so
162
- # cached at class-level for efficiency.
163
- _codesigning_key_cache = {}
164
-
165
- def __init__(self, spec):
166
- self.spec = spec
167
-
168
- self.isIOS = False
169
- self.mac_toolchain_dir = None
170
- self.header_map_path = None
171
-
172
- # Per-target 'xcode_settings' are pushed down into configs earlier by gyp.
173
- # This means self.xcode_settings[config] always contains all settings
174
- # for that config -- the per-target settings as well. Settings that are
175
- # the same for all configs are implicitly per-target settings.
176
- self.xcode_settings = {}
177
- configs = spec["configurations"]
178
- for configname, config in configs.items():
179
- self.xcode_settings[configname] = config.get("xcode_settings", {})
180
- self._ConvertConditionalKeys(configname)
181
- if self.xcode_settings[configname].get("IPHONEOS_DEPLOYMENT_TARGET", None):
182
- self.isIOS = True
183
-
184
- # This is only non-None temporarily during the execution of some methods.
185
- self.configname = None
186
-
187
- # Used by _AdjustLibrary to match .a and .dylib entries in libraries.
188
- self.library_re = re.compile(r"^lib([^/]+)\.(a|dylib)$")
189
-
190
- def _ConvertConditionalKeys(self, configname):
191
- """Converts or warns on conditional keys. Xcode supports conditional keys,
192
- such as CODE_SIGN_IDENTITY[sdk=iphoneos*]. This is a partial implementation
193
- with some keys converted while the rest force a warning."""
194
- settings = self.xcode_settings[configname]
195
- conditional_keys = [key for key in settings if key.endswith("]")]
196
- for key in conditional_keys:
197
- # If you need more, speak up at http://crbug.com/122592
198
- if key.endswith("[sdk=iphoneos*]"):
199
- if configname.endswith("iphoneos"):
200
- new_key = key.split("[")[0]
201
- settings[new_key] = settings[key]
202
- else:
203
- print(
204
- "Warning: Conditional keys not implemented, ignoring:",
205
- " ".join(conditional_keys),
206
- )
207
- del settings[key]
208
-
209
- def _Settings(self):
210
- assert self.configname
211
- return self.xcode_settings[self.configname]
212
-
213
- def _Test(self, test_key, cond_key, default):
214
- return self._Settings().get(test_key, default) == cond_key
215
-
216
- def _Appendf(self, lst, test_key, format_str, default=None):
217
- if test_key in self._Settings():
218
- lst.append(format_str % str(self._Settings()[test_key]))
219
- elif default:
220
- lst.append(format_str % str(default))
221
-
222
- def _WarnUnimplemented(self, test_key):
223
- if test_key in self._Settings():
224
- print('Warning: Ignoring not yet implemented key "%s".' % test_key)
225
-
226
- def IsBinaryOutputFormat(self, configname):
227
- default = "binary" if self.isIOS else "xml"
228
- format = self.xcode_settings[configname].get("INFOPLIST_OUTPUT_FORMAT", default)
229
- return format == "binary"
230
-
231
- def IsIosFramework(self):
232
- return self.spec["type"] == "shared_library" and self._IsBundle() and self.isIOS
233
-
234
- def _IsBundle(self):
235
- return (
236
- int(self.spec.get("mac_bundle", 0)) != 0
237
- or self._IsXCTest()
238
- or self._IsXCUiTest()
239
- )
240
-
241
- def _IsXCTest(self):
242
- return int(self.spec.get("mac_xctest_bundle", 0)) != 0
243
-
244
- def _IsXCUiTest(self):
245
- return int(self.spec.get("mac_xcuitest_bundle", 0)) != 0
246
-
247
- def _IsIosAppExtension(self):
248
- return int(self.spec.get("ios_app_extension", 0)) != 0
249
-
250
- def _IsIosWatchKitExtension(self):
251
- return int(self.spec.get("ios_watchkit_extension", 0)) != 0
252
-
253
- def _IsIosWatchApp(self):
254
- return int(self.spec.get("ios_watch_app", 0)) != 0
255
-
256
- def GetFrameworkVersion(self):
257
- """Returns the framework version of the current target. Only valid for
258
- bundles."""
259
- assert self._IsBundle()
260
- return self.GetPerTargetSetting("FRAMEWORK_VERSION", default="A")
261
-
262
- def GetWrapperExtension(self):
263
- """Returns the bundle extension (.app, .framework, .plugin, etc). Only
264
- valid for bundles."""
265
- assert self._IsBundle()
266
- if self.spec["type"] in ("loadable_module", "shared_library"):
267
- default_wrapper_extension = {
268
- "loadable_module": "bundle",
269
- "shared_library": "framework",
270
- }[self.spec["type"]]
271
- wrapper_extension = self.GetPerTargetSetting(
272
- "WRAPPER_EXTENSION", default=default_wrapper_extension
273
- )
274
- return "." + self.spec.get("product_extension", wrapper_extension)
275
- elif self.spec["type"] == "executable":
276
- if self._IsIosAppExtension() or self._IsIosWatchKitExtension():
277
- return "." + self.spec.get("product_extension", "appex")
278
- else:
279
- return "." + self.spec.get("product_extension", "app")
280
- else:
281
- assert False, "Don't know extension for '{}', target '{}'".format(
282
- self.spec["type"],
283
- self.spec["target_name"],
284
- )
285
-
286
- def GetProductName(self):
287
- """Returns PRODUCT_NAME."""
288
- return self.spec.get("product_name", self.spec["target_name"])
289
-
290
- def GetFullProductName(self):
291
- """Returns FULL_PRODUCT_NAME."""
292
- if self._IsBundle():
293
- return self.GetWrapperName()
294
- else:
295
- return self._GetStandaloneBinaryPath()
296
-
297
- def GetWrapperName(self):
298
- """Returns the directory name of the bundle represented by this target.
299
- Only valid for bundles."""
300
- assert self._IsBundle()
301
- return self.GetProductName() + self.GetWrapperExtension()
302
-
303
- def GetBundleContentsFolderPath(self):
304
- """Returns the qualified path to the bundle's contents folder. E.g.
305
- Chromium.app/Contents or Foo.bundle/Versions/A. Only valid for bundles."""
306
- if self.isIOS:
307
- return self.GetWrapperName()
308
- assert self._IsBundle()
309
- if self.spec["type"] == "shared_library":
310
- return os.path.join(
311
- self.GetWrapperName(), "Versions", self.GetFrameworkVersion()
312
- )
313
- else:
314
- # loadable_modules have a 'Contents' folder like executables.
315
- return os.path.join(self.GetWrapperName(), "Contents")
316
-
317
- def GetBundleResourceFolder(self):
318
- """Returns the qualified path to the bundle's resource folder. E.g.
319
- Chromium.app/Contents/Resources. Only valid for bundles."""
320
- assert self._IsBundle()
321
- if self.isIOS:
322
- return self.GetBundleContentsFolderPath()
323
- return os.path.join(self.GetBundleContentsFolderPath(), "Resources")
324
-
325
- def GetBundleExecutableFolderPath(self):
326
- """Returns the qualified path to the bundle's executables folder. E.g.
327
- Chromium.app/Contents/MacOS. Only valid for bundles."""
328
- assert self._IsBundle()
329
- if self.spec["type"] in ("shared_library") or self.isIOS:
330
- return self.GetBundleContentsFolderPath()
331
- elif self.spec["type"] in ("executable", "loadable_module"):
332
- return os.path.join(self.GetBundleContentsFolderPath(), "MacOS")
333
-
334
- def GetBundleJavaFolderPath(self):
335
- """Returns the qualified path to the bundle's Java resource folder.
336
- E.g. Chromium.app/Contents/Resources/Java. Only valid for bundles."""
337
- assert self._IsBundle()
338
- return os.path.join(self.GetBundleResourceFolder(), "Java")
339
-
340
- def GetBundleFrameworksFolderPath(self):
341
- """Returns the qualified path to the bundle's frameworks folder. E.g,
342
- Chromium.app/Contents/Frameworks. Only valid for bundles."""
343
- assert self._IsBundle()
344
- return os.path.join(self.GetBundleContentsFolderPath(), "Frameworks")
345
-
346
- def GetBundleSharedFrameworksFolderPath(self):
347
- """Returns the qualified path to the bundle's frameworks folder. E.g,
348
- Chromium.app/Contents/SharedFrameworks. Only valid for bundles."""
349
- assert self._IsBundle()
350
- return os.path.join(self.GetBundleContentsFolderPath(), "SharedFrameworks")
351
-
352
- def GetBundleSharedSupportFolderPath(self):
353
- """Returns the qualified path to the bundle's shared support folder. E.g,
354
- Chromium.app/Contents/SharedSupport. Only valid for bundles."""
355
- assert self._IsBundle()
356
- if self.spec["type"] == "shared_library":
357
- return self.GetBundleResourceFolder()
358
- else:
359
- return os.path.join(self.GetBundleContentsFolderPath(), "SharedSupport")
360
-
361
- def GetBundlePlugInsFolderPath(self):
362
- """Returns the qualified path to the bundle's plugins folder. E.g,
363
- Chromium.app/Contents/PlugIns. Only valid for bundles."""
364
- assert self._IsBundle()
365
- return os.path.join(self.GetBundleContentsFolderPath(), "PlugIns")
366
-
367
- def GetBundleXPCServicesFolderPath(self):
368
- """Returns the qualified path to the bundle's XPC services folder. E.g,
369
- Chromium.app/Contents/XPCServices. Only valid for bundles."""
370
- assert self._IsBundle()
371
- return os.path.join(self.GetBundleContentsFolderPath(), "XPCServices")
372
-
373
- def GetBundlePlistPath(self):
374
- """Returns the qualified path to the bundle's plist file. E.g.
375
- Chromium.app/Contents/Info.plist. Only valid for bundles."""
376
- assert self._IsBundle()
377
- if (
378
- self.spec["type"] in ("executable", "loadable_module")
379
- or self.IsIosFramework()
380
- ):
381
- return os.path.join(self.GetBundleContentsFolderPath(), "Info.plist")
382
- else:
383
- return os.path.join(
384
- self.GetBundleContentsFolderPath(), "Resources", "Info.plist"
385
- )
386
-
387
- def GetProductType(self):
388
- """Returns the PRODUCT_TYPE of this target."""
389
- if self._IsIosAppExtension():
390
- assert self._IsBundle(), (
391
- "ios_app_extension flag requires mac_bundle "
392
- "(target %s)" % self.spec["target_name"]
393
- )
394
- return "com.apple.product-type.app-extension"
395
- if self._IsIosWatchKitExtension():
396
- assert self._IsBundle(), (
397
- "ios_watchkit_extension flag requires "
398
- "mac_bundle (target %s)" % self.spec["target_name"]
399
- )
400
- return "com.apple.product-type.watchkit-extension"
401
- if self._IsIosWatchApp():
402
- assert self._IsBundle(), (
403
- "ios_watch_app flag requires mac_bundle "
404
- "(target %s)" % self.spec["target_name"]
405
- )
406
- return "com.apple.product-type.application.watchapp"
407
- if self._IsXCUiTest():
408
- assert self._IsBundle(), (
409
- "mac_xcuitest_bundle flag requires mac_bundle "
410
- "(target %s)" % self.spec["target_name"]
411
- )
412
- return "com.apple.product-type.bundle.ui-testing"
413
- if self._IsBundle():
414
- return {
415
- "executable": "com.apple.product-type.application",
416
- "loadable_module": "com.apple.product-type.bundle",
417
- "shared_library": "com.apple.product-type.framework",
418
- }[self.spec["type"]]
419
- else:
420
- return {
421
- "executable": "com.apple.product-type.tool",
422
- "loadable_module": "com.apple.product-type.library.dynamic",
423
- "shared_library": "com.apple.product-type.library.dynamic",
424
- "static_library": "com.apple.product-type.library.static",
425
- }[self.spec["type"]]
426
-
427
- def GetMachOType(self):
428
- """Returns the MACH_O_TYPE of this target."""
429
- # Weird, but matches Xcode.
430
- if not self._IsBundle() and self.spec["type"] == "executable":
431
- return ""
432
- return {
433
- "executable": "mh_execute",
434
- "static_library": "staticlib",
435
- "shared_library": "mh_dylib",
436
- "loadable_module": "mh_bundle",
437
- }[self.spec["type"]]
438
-
439
- def _GetBundleBinaryPath(self):
440
- """Returns the name of the bundle binary of by this target.
441
- E.g. Chromium.app/Contents/MacOS/Chromium. Only valid for bundles."""
442
- assert self._IsBundle()
443
- return os.path.join(
444
- self.GetBundleExecutableFolderPath(), self.GetExecutableName()
445
- )
446
-
447
- def _GetStandaloneExecutableSuffix(self):
448
- if "product_extension" in self.spec:
449
- return "." + self.spec["product_extension"]
450
- return {
451
- "executable": "",
452
- "static_library": ".a",
453
- "shared_library": ".dylib",
454
- "loadable_module": ".so",
455
- }[self.spec["type"]]
456
-
457
- def _GetStandaloneExecutablePrefix(self):
458
- return self.spec.get(
459
- "product_prefix",
460
- {
461
- "executable": "",
462
- "static_library": "lib",
463
- "shared_library": "lib",
464
- # Non-bundled loadable_modules are called foo.so for some reason
465
- # (that is, .so and no prefix) with the xcode build -- match that.
466
- "loadable_module": "",
467
- }[self.spec["type"]],
468
- )
469
-
470
- def _GetStandaloneBinaryPath(self):
471
- """Returns the name of the non-bundle binary represented by this target.
472
- E.g. hello_world. Only valid for non-bundles."""
473
- assert not self._IsBundle()
474
- assert self.spec["type"] in (
475
- "executable",
476
- "shared_library",
477
- "static_library",
478
- "loadable_module",
479
- ), ("Unexpected type %s" % self.spec["type"])
480
- target = self.spec["target_name"]
481
- if self.spec["type"] == "static_library":
482
- if target[:3] == "lib":
483
- target = target[3:]
484
- elif self.spec["type"] in ("loadable_module", "shared_library"):
485
- if target[:3] == "lib":
486
- target = target[3:]
487
-
488
- target_prefix = self._GetStandaloneExecutablePrefix()
489
- target = self.spec.get("product_name", target)
490
- target_ext = self._GetStandaloneExecutableSuffix()
491
- return target_prefix + target + target_ext
492
-
493
- def GetExecutableName(self):
494
- """Returns the executable name of the bundle represented by this target.
495
- E.g. Chromium."""
496
- if self._IsBundle():
497
- return self.spec.get("product_name", self.spec["target_name"])
498
- else:
499
- return self._GetStandaloneBinaryPath()
500
-
501
- def GetExecutablePath(self):
502
- """Returns the qualified path to the primary executable of the bundle
503
- represented by this target. E.g. Chromium.app/Contents/MacOS/Chromium."""
504
- if self._IsBundle():
505
- return self._GetBundleBinaryPath()
506
- else:
507
- return self._GetStandaloneBinaryPath()
508
-
509
- def GetActiveArchs(self, configname):
510
- """Returns the architectures this target should be built for."""
511
- config_settings = self.xcode_settings[configname]
512
- xcode_archs_default = GetXcodeArchsDefault()
513
- return xcode_archs_default.ActiveArchs(
514
- config_settings.get("ARCHS"),
515
- config_settings.get("VALID_ARCHS"),
516
- config_settings.get("SDKROOT"),
517
- )
518
-
519
- def _GetSdkVersionInfoItem(self, sdk, infoitem):
520
- # xcodebuild requires Xcode and can't run on Command Line Tools-only
521
- # systems from 10.7 onward.
522
- # Since the CLT has no SDK paths anyway, returning None is the
523
- # most sensible route and should still do the right thing.
524
- try:
525
- return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem])
526
- except GypError:
527
- pass
528
-
529
- def _SdkRoot(self, configname):
530
- if configname is None:
531
- configname = self.configname
532
- return self.GetPerConfigSetting("SDKROOT", configname, default="")
533
-
534
- def _XcodePlatformPath(self, configname=None):
535
- sdk_root = self._SdkRoot(configname)
536
- if sdk_root not in XcodeSettings._platform_path_cache:
537
- platform_path = self._GetSdkVersionInfoItem(
538
- sdk_root, "--show-sdk-platform-path"
539
- )
540
- XcodeSettings._platform_path_cache[sdk_root] = platform_path
541
- return XcodeSettings._platform_path_cache[sdk_root]
542
-
543
- def _SdkPath(self, configname=None):
544
- sdk_root = self._SdkRoot(configname)
545
- if sdk_root.startswith("/"):
546
- return sdk_root
547
- return self._XcodeSdkPath(sdk_root)
548
-
549
- def _XcodeSdkPath(self, sdk_root):
550
- if sdk_root not in XcodeSettings._sdk_path_cache:
551
- sdk_path = self._GetSdkVersionInfoItem(sdk_root, "--show-sdk-path")
552
- XcodeSettings._sdk_path_cache[sdk_root] = sdk_path
553
- if sdk_root:
554
- XcodeSettings._sdk_root_cache[sdk_path] = sdk_root
555
- return XcodeSettings._sdk_path_cache[sdk_root]
556
-
557
- def _AppendPlatformVersionMinFlags(self, lst):
558
- self._Appendf(lst, "MACOSX_DEPLOYMENT_TARGET", "-mmacosx-version-min=%s")
559
- if "IPHONEOS_DEPLOYMENT_TARGET" in self._Settings():
560
- # TODO: Implement this better?
561
- sdk_path_basename = os.path.basename(self._SdkPath())
562
- if sdk_path_basename.lower().startswith("iphonesimulator"):
563
- self._Appendf(
564
- lst, "IPHONEOS_DEPLOYMENT_TARGET", "-mios-simulator-version-min=%s"
565
- )
566
- else:
567
- self._Appendf(
568
- lst, "IPHONEOS_DEPLOYMENT_TARGET", "-miphoneos-version-min=%s"
569
- )
570
-
571
- def GetCflags(self, configname, arch=None):
572
- """Returns flags that need to be added to .c, .cc, .m, and .mm
573
- compilations."""
574
- # This functions (and the similar ones below) do not offer complete
575
- # emulation of all xcode_settings keys. They're implemented on demand.
576
-
577
- self.configname = configname
578
- cflags = []
579
-
580
- sdk_root = self._SdkPath()
581
- if "SDKROOT" in self._Settings() and sdk_root:
582
- cflags.append("-isysroot")
583
- cflags.append(sdk_root)
584
-
585
- if self.header_map_path:
586
- cflags.append("-I%s" % self.header_map_path)
587
-
588
- if self._Test("CLANG_WARN_CONSTANT_CONVERSION", "YES", default="NO"):
589
- cflags.append("-Wconstant-conversion")
590
-
591
- if self._Test("GCC_CHAR_IS_UNSIGNED_CHAR", "YES", default="NO"):
592
- cflags.append("-funsigned-char")
593
-
594
- if self._Test("GCC_CW_ASM_SYNTAX", "YES", default="YES"):
595
- cflags.append("-fasm-blocks")
596
-
597
- if "GCC_DYNAMIC_NO_PIC" in self._Settings():
598
- if self._Settings()["GCC_DYNAMIC_NO_PIC"] == "YES":
599
- cflags.append("-mdynamic-no-pic")
600
- else:
601
- pass
602
- # TODO: In this case, it depends on the target. xcode passes
603
- # mdynamic-no-pic by default for executable and possibly static lib
604
- # according to mento
605
-
606
- if self._Test("GCC_ENABLE_PASCAL_STRINGS", "YES", default="YES"):
607
- cflags.append("-mpascal-strings")
608
-
609
- self._Appendf(cflags, "GCC_OPTIMIZATION_LEVEL", "-O%s", default="s")
610
-
611
- if self._Test("GCC_GENERATE_DEBUGGING_SYMBOLS", "YES", default="YES"):
612
- dbg_format = self._Settings().get("DEBUG_INFORMATION_FORMAT", "dwarf")
613
- if dbg_format == "dwarf":
614
- cflags.append("-gdwarf-2")
615
- elif dbg_format == "stabs":
616
- raise NotImplementedError("stabs debug format is not supported yet.")
617
- elif dbg_format == "dwarf-with-dsym":
618
- cflags.append("-gdwarf-2")
619
- else:
620
- raise NotImplementedError("Unknown debug format %s" % dbg_format)
621
-
622
- if self._Settings().get("GCC_STRICT_ALIASING") == "YES":
623
- cflags.append("-fstrict-aliasing")
624
- elif self._Settings().get("GCC_STRICT_ALIASING") == "NO":
625
- cflags.append("-fno-strict-aliasing")
626
-
627
- if self._Test("GCC_SYMBOLS_PRIVATE_EXTERN", "YES", default="NO"):
628
- cflags.append("-fvisibility=hidden")
629
-
630
- if self._Test("GCC_TREAT_WARNINGS_AS_ERRORS", "YES", default="NO"):
631
- cflags.append("-Werror")
632
-
633
- if self._Test("GCC_WARN_ABOUT_MISSING_NEWLINE", "YES", default="NO"):
634
- cflags.append("-Wnewline-eof")
635
-
636
- # In Xcode, this is only activated when GCC_COMPILER_VERSION is clang or
637
- # llvm-gcc. It also requires a fairly recent libtool, and
638
- # if the system clang isn't used, DYLD_LIBRARY_PATH needs to contain the
639
- # path to the libLTO.dylib that matches the used clang.
640
- if self._Test("LLVM_LTO", "YES", default="NO"):
641
- cflags.append("-flto")
642
-
643
- self._AppendPlatformVersionMinFlags(cflags)
644
-
645
- # TODO:
646
- if self._Test("COPY_PHASE_STRIP", "YES", default="NO"):
647
- self._WarnUnimplemented("COPY_PHASE_STRIP")
648
- self._WarnUnimplemented("GCC_DEBUGGING_SYMBOLS")
649
- self._WarnUnimplemented("GCC_ENABLE_OBJC_EXCEPTIONS")
650
-
651
- # TODO: This is exported correctly, but assigning to it is not supported.
652
- self._WarnUnimplemented("MACH_O_TYPE")
653
- self._WarnUnimplemented("PRODUCT_TYPE")
654
-
655
- # If GYP_CROSSCOMPILE (--cross-compiling), disable architecture-specific
656
- # additions and assume these will be provided as required via CC_host,
657
- # CXX_host, CC_target and CXX_target.
658
- if not gyp.common.CrossCompileRequested():
659
- if arch is not None:
660
- archs = [arch]
661
- else:
662
- assert self.configname
663
- archs = self.GetActiveArchs(self.configname)
664
- if len(archs) != 1:
665
- # TODO: Supporting fat binaries will be annoying.
666
- self._WarnUnimplemented("ARCHS")
667
- archs = ["i386"]
668
- cflags.append("-arch")
669
- cflags.append(archs[0])
670
-
671
- if archs[0] in ("i386", "x86_64"):
672
- if self._Test("GCC_ENABLE_SSE3_EXTENSIONS", "YES", default="NO"):
673
- cflags.append("-msse3")
674
- if self._Test(
675
- "GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS", "YES", default="NO"
676
- ):
677
- cflags.append("-mssse3") # Note 3rd 's'.
678
- if self._Test("GCC_ENABLE_SSE41_EXTENSIONS", "YES", default="NO"):
679
- cflags.append("-msse4.1")
680
- if self._Test("GCC_ENABLE_SSE42_EXTENSIONS", "YES", default="NO"):
681
- cflags.append("-msse4.2")
682
-
683
- cflags += self._Settings().get("WARNING_CFLAGS", [])
684
-
685
- if self._IsXCTest():
686
- platform_root = self._XcodePlatformPath(configname)
687
- if platform_root:
688
- cflags.append("-F" + platform_root + "/Developer/Library/Frameworks/")
689
-
690
- framework_root = sdk_root if sdk_root else ""
691
- config = self.spec["configurations"][self.configname]
692
- framework_dirs = config.get("mac_framework_dirs", [])
693
- for directory in framework_dirs:
694
- cflags.append("-F" + directory.replace("$(SDKROOT)", framework_root))
695
-
696
- self.configname = None
697
- return cflags
698
-
699
- def GetCflagsC(self, configname):
700
- """Returns flags that need to be added to .c, and .m compilations."""
701
- self.configname = configname
702
- cflags_c = []
703
- if self._Settings().get("GCC_C_LANGUAGE_STANDARD", "") == "ansi":
704
- cflags_c.append("-ansi")
705
- else:
706
- self._Appendf(cflags_c, "GCC_C_LANGUAGE_STANDARD", "-std=%s")
707
- cflags_c += self._Settings().get("OTHER_CFLAGS", [])
708
- self.configname = None
709
- return cflags_c
710
-
711
- def GetCflagsCC(self, configname):
712
- """Returns flags that need to be added to .cc, and .mm compilations."""
713
- self.configname = configname
714
- cflags_cc = []
715
-
716
- clang_cxx_language_standard = self._Settings().get(
717
- "CLANG_CXX_LANGUAGE_STANDARD"
718
- )
719
- # Note: Don't make c++0x to c++11 so that c++0x can be used with older
720
- # clangs that don't understand c++11 yet (like Xcode 4.2's).
721
- if clang_cxx_language_standard:
722
- cflags_cc.append("-std=%s" % clang_cxx_language_standard)
723
-
724
- self._Appendf(cflags_cc, "CLANG_CXX_LIBRARY", "-stdlib=%s")
725
-
726
- if self._Test("GCC_ENABLE_CPP_RTTI", "NO", default="YES"):
727
- cflags_cc.append("-fno-rtti")
728
- if self._Test("GCC_ENABLE_CPP_EXCEPTIONS", "NO", default="YES"):
729
- cflags_cc.append("-fno-exceptions")
730
- if self._Test("GCC_INLINES_ARE_PRIVATE_EXTERN", "YES", default="NO"):
731
- cflags_cc.append("-fvisibility-inlines-hidden")
732
- if self._Test("GCC_THREADSAFE_STATICS", "NO", default="YES"):
733
- cflags_cc.append("-fno-threadsafe-statics")
734
- # Note: This flag is a no-op for clang, it only has an effect for gcc.
735
- if self._Test("GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO", "NO", default="YES"):
736
- cflags_cc.append("-Wno-invalid-offsetof")
737
-
738
- other_ccflags = []
739
-
740
- for flag in self._Settings().get("OTHER_CPLUSPLUSFLAGS", ["$(inherited)"]):
741
- # TODO: More general variable expansion. Missing in many other places too.
742
- if flag in ("$inherited", "$(inherited)", "${inherited}"):
743
- flag = "$OTHER_CFLAGS"
744
- if flag in ("$OTHER_CFLAGS", "$(OTHER_CFLAGS)", "${OTHER_CFLAGS}"):
745
- other_ccflags += self._Settings().get("OTHER_CFLAGS", [])
746
- else:
747
- other_ccflags.append(flag)
748
- cflags_cc += other_ccflags
749
-
750
- self.configname = None
751
- return cflags_cc
752
-
753
- def _AddObjectiveCGarbageCollectionFlags(self, flags):
754
- gc_policy = self._Settings().get("GCC_ENABLE_OBJC_GC", "unsupported")
755
- if gc_policy == "supported":
756
- flags.append("-fobjc-gc")
757
- elif gc_policy == "required":
758
- flags.append("-fobjc-gc-only")
759
-
760
- def _AddObjectiveCARCFlags(self, flags):
761
- if self._Test("CLANG_ENABLE_OBJC_ARC", "YES", default="NO"):
762
- flags.append("-fobjc-arc")
763
-
764
- def _AddObjectiveCMissingPropertySynthesisFlags(self, flags):
765
- if self._Test(
766
- "CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS", "YES", default="NO"
767
- ):
768
- flags.append("-Wobjc-missing-property-synthesis")
769
-
770
- def GetCflagsObjC(self, configname):
771
- """Returns flags that need to be added to .m compilations."""
772
- self.configname = configname
773
- cflags_objc = []
774
- self._AddObjectiveCGarbageCollectionFlags(cflags_objc)
775
- self._AddObjectiveCARCFlags(cflags_objc)
776
- self._AddObjectiveCMissingPropertySynthesisFlags(cflags_objc)
777
- self.configname = None
778
- return cflags_objc
779
-
780
- def GetCflagsObjCC(self, configname):
781
- """Returns flags that need to be added to .mm compilations."""
782
- self.configname = configname
783
- cflags_objcc = []
784
- self._AddObjectiveCGarbageCollectionFlags(cflags_objcc)
785
- self._AddObjectiveCARCFlags(cflags_objcc)
786
- self._AddObjectiveCMissingPropertySynthesisFlags(cflags_objcc)
787
- if self._Test("GCC_OBJC_CALL_CXX_CDTORS", "YES", default="NO"):
788
- cflags_objcc.append("-fobjc-call-cxx-cdtors")
789
- self.configname = None
790
- return cflags_objcc
791
-
792
- def GetInstallNameBase(self):
793
- """Return DYLIB_INSTALL_NAME_BASE for this target."""
794
- # Xcode sets this for shared_libraries, and for nonbundled loadable_modules.
795
- if self.spec["type"] != "shared_library" and (
796
- self.spec["type"] != "loadable_module" or self._IsBundle()
797
- ):
798
- return None
799
- install_base = self.GetPerTargetSetting(
800
- "DYLIB_INSTALL_NAME_BASE",
801
- default="/Library/Frameworks" if self._IsBundle() else "/usr/local/lib",
802
- )
803
- return install_base
804
-
805
- def _StandardizePath(self, path):
806
- """Do :standardizepath processing for path."""
807
- # I'm not quite sure what :standardizepath does. Just call normpath(),
808
- # but don't let @executable_path/../foo collapse to foo.
809
- if "/" in path:
810
- prefix, rest = "", path
811
- if path.startswith("@"):
812
- prefix, rest = path.split("/", 1)
813
- rest = os.path.normpath(rest) # :standardizepath
814
- path = os.path.join(prefix, rest)
815
- return path
816
-
817
- def GetInstallName(self):
818
- """Return LD_DYLIB_INSTALL_NAME for this target."""
819
- # Xcode sets this for shared_libraries, and for nonbundled loadable_modules.
820
- if self.spec["type"] != "shared_library" and (
821
- self.spec["type"] != "loadable_module" or self._IsBundle()
822
- ):
823
- return None
824
-
825
- default_install_name = (
826
- "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)"
827
- )
828
- install_name = self.GetPerTargetSetting(
829
- "LD_DYLIB_INSTALL_NAME", default=default_install_name
830
- )
831
-
832
- # Hardcode support for the variables used in chromium for now, to
833
- # unblock people using the make build.
834
- if "$" in install_name:
835
- assert install_name in (
836
- "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/"
837
- "$(WRAPPER_NAME)/$(PRODUCT_NAME)",
838
- default_install_name,
839
- ), (
840
- "Variables in LD_DYLIB_INSTALL_NAME are not generally supported "
841
- "yet in target '%s' (got '%s')"
842
- % (self.spec["target_name"], install_name)
843
- )
844
-
845
- install_name = install_name.replace(
846
- "$(DYLIB_INSTALL_NAME_BASE:standardizepath)",
847
- self._StandardizePath(self.GetInstallNameBase()),
848
- )
849
- if self._IsBundle():
850
- # These are only valid for bundles, hence the |if|.
851
- install_name = install_name.replace(
852
- "$(WRAPPER_NAME)", self.GetWrapperName()
853
- )
854
- install_name = install_name.replace(
855
- "$(PRODUCT_NAME)", self.GetProductName()
856
- )
857
- else:
858
- assert "$(WRAPPER_NAME)" not in install_name
859
- assert "$(PRODUCT_NAME)" not in install_name
860
-
861
- install_name = install_name.replace(
862
- "$(EXECUTABLE_PATH)", self.GetExecutablePath()
863
- )
864
- return install_name
865
-
866
- def _MapLinkerFlagFilename(self, ldflag, gyp_to_build_path):
867
- """Checks if ldflag contains a filename and if so remaps it from
868
- gyp-directory-relative to build-directory-relative."""
869
- # This list is expanded on demand.
870
- # They get matched as:
871
- # -exported_symbols_list file
872
- # -Wl,exported_symbols_list file
873
- # -Wl,exported_symbols_list,file
874
- LINKER_FILE = r"(\S+)"
875
- WORD = r"\S+"
876
- linker_flags = [
877
- ["-exported_symbols_list", LINKER_FILE], # Needed for NaCl.
878
- ["-unexported_symbols_list", LINKER_FILE],
879
- ["-reexported_symbols_list", LINKER_FILE],
880
- ["-sectcreate", WORD, WORD, LINKER_FILE], # Needed for remoting.
881
- ]
882
- for flag_pattern in linker_flags:
883
- regex = re.compile("(?:-Wl,)?" + "[ ,]".join(flag_pattern))
884
- m = regex.match(ldflag)
885
- if m:
886
- ldflag = (
887
- ldflag[: m.start(1)]
888
- + gyp_to_build_path(m.group(1))
889
- + ldflag[m.end(1) :]
890
- )
891
- # Required for ffmpeg (no idea why they don't use LIBRARY_SEARCH_PATHS,
892
- # TODO(thakis): Update ffmpeg.gyp):
893
- if ldflag.startswith("-L"):
894
- ldflag = "-L" + gyp_to_build_path(ldflag[len("-L") :])
895
- return ldflag
896
-
897
- def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
898
- """Returns flags that need to be passed to the linker.
899
-
900
- Args:
901
- configname: The name of the configuration to get ld flags for.
902
- product_dir: The directory where products such static and dynamic
903
- libraries are placed. This is added to the library search path.
904
- gyp_to_build_path: A function that converts paths relative to the
905
- current gyp file to paths relative to the build directory.
906
- """
907
- self.configname = configname
908
- ldflags = []
909
-
910
- # The xcode build is relative to a gyp file's directory, and OTHER_LDFLAGS
911
- # can contain entries that depend on this. Explicitly absolutify these.
912
- for ldflag in self._Settings().get("OTHER_LDFLAGS", []):
913
- ldflags.append(self._MapLinkerFlagFilename(ldflag, gyp_to_build_path))
914
-
915
- if self._Test("DEAD_CODE_STRIPPING", "YES", default="NO"):
916
- ldflags.append("-Wl,-dead_strip")
917
-
918
- if self._Test("PREBINDING", "YES", default="NO"):
919
- ldflags.append("-Wl,-prebind")
920
-
921
- self._Appendf(
922
- ldflags, "DYLIB_COMPATIBILITY_VERSION", "-compatibility_version %s"
923
- )
924
- self._Appendf(ldflags, "DYLIB_CURRENT_VERSION", "-current_version %s")
925
-
926
- self._AppendPlatformVersionMinFlags(ldflags)
927
-
928
- if "SDKROOT" in self._Settings() and self._SdkPath():
929
- ldflags.append("-isysroot")
930
- ldflags.append(self._SdkPath())
931
-
932
- for library_path in self._Settings().get("LIBRARY_SEARCH_PATHS", []):
933
- ldflags.append("-L" + gyp_to_build_path(library_path))
934
-
935
- if "ORDER_FILE" in self._Settings():
936
- ldflags.append("-Wl,-order_file")
937
- ldflags.append("-Wl," + gyp_to_build_path(self._Settings()["ORDER_FILE"]))
938
-
939
- if not gyp.common.CrossCompileRequested():
940
- if arch is not None:
941
- archs = [arch]
942
- else:
943
- assert self.configname
944
- archs = self.GetActiveArchs(self.configname)
945
- if len(archs) != 1:
946
- # TODO: Supporting fat binaries will be annoying.
947
- self._WarnUnimplemented("ARCHS")
948
- archs = ["i386"]
949
- # Avoid quoting the space between -arch and the arch name
950
- ldflags.append("-arch")
951
- ldflags.append(archs[0])
952
-
953
- # Xcode adds the product directory by default.
954
- # Rewrite -L. to -L./ to work around http://www.openradar.me/25313838
955
- ldflags.append("-L" + (product_dir if product_dir != "." else "./"))
956
-
957
- install_name = self.GetInstallName()
958
- if install_name and self.spec["type"] != "loadable_module":
959
- ldflags.append("-install_name")
960
- ldflags.append(install_name.replace(" ", r"\ "))
961
-
962
- for rpath in self._Settings().get("LD_RUNPATH_SEARCH_PATHS", []):
963
- ldflags.append("-Wl,-rpath," + rpath)
964
-
965
- sdk_root = self._SdkPath()
966
- if not sdk_root:
967
- sdk_root = ""
968
- config = self.spec["configurations"][self.configname]
969
- framework_dirs = config.get("mac_framework_dirs", [])
970
- for directory in framework_dirs:
971
- ldflags.append("-F" + directory.replace("$(SDKROOT)", sdk_root))
972
-
973
- if self._IsXCTest():
974
- platform_root = self._XcodePlatformPath(configname)
975
- if sdk_root and platform_root:
976
- ldflags.append("-F" + platform_root + "/Developer/Library/Frameworks/")
977
- ldflags.append("-framework")
978
- ldflags.append("XCTest")
979
-
980
- is_extension = self._IsIosAppExtension() or self._IsIosWatchKitExtension()
981
- if sdk_root and is_extension:
982
- # Adds the link flags for extensions. These flags are common for all
983
- # extensions and provide loader and main function.
984
- # These flags reflect the compilation options used by xcode to compile
985
- # extensions.
986
- xcode_version, _ = XcodeVersion()
987
- if xcode_version < "0900":
988
- ldflags.append("-lpkstart")
989
- ldflags.append(
990
- sdk_root
991
- + "/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit"
992
- )
993
- else:
994
- ldflags.append("-e")
995
- ldflags.append("_NSExtensionMain")
996
- ldflags.append("-fapplication-extension")
997
-
998
- self._Appendf(ldflags, "CLANG_CXX_LIBRARY", "-stdlib=%s")
999
-
1000
- self.configname = None
1001
- return ldflags
1002
-
1003
- def GetLibtoolflags(self, configname):
1004
- """Returns flags that need to be passed to the static linker.
1005
-
1006
- Args:
1007
- configname: The name of the configuration to get ld flags for.
1008
- """
1009
- self.configname = configname
1010
- libtoolflags = []
1011
-
1012
- for libtoolflag in self._Settings().get("OTHER_LDFLAGS", []):
1013
- libtoolflags.append(libtoolflag)
1014
- # TODO(thakis): ARCHS?
1015
-
1016
- self.configname = None
1017
- return libtoolflags
1018
-
1019
- def GetPerTargetSettings(self):
1020
- """Gets a list of all the per-target settings. This will only fetch keys
1021
- whose values are the same across all configurations."""
1022
- first_pass = True
1023
- result = {}
1024
- for configname in sorted(self.xcode_settings.keys()):
1025
- if first_pass:
1026
- result = dict(self.xcode_settings[configname])
1027
- first_pass = False
1028
- else:
1029
- for key, value in self.xcode_settings[configname].items():
1030
- if key not in result:
1031
- continue
1032
- elif result[key] != value:
1033
- del result[key]
1034
- return result
1035
-
1036
- def GetPerConfigSetting(self, setting, configname, default=None):
1037
- if configname in self.xcode_settings:
1038
- return self.xcode_settings[configname].get(setting, default)
1039
- else:
1040
- return self.GetPerTargetSetting(setting, default)
1041
-
1042
- def GetPerTargetSetting(self, setting, default=None):
1043
- """Tries to get xcode_settings.setting from spec. Assumes that the setting
1044
- has the same value in all configurations and throws otherwise."""
1045
- is_first_pass = True
1046
- result = None
1047
- for configname in sorted(self.xcode_settings.keys()):
1048
- if is_first_pass:
1049
- result = self.xcode_settings[configname].get(setting, None)
1050
- is_first_pass = False
1051
- else:
1052
- assert result == self.xcode_settings[configname].get(setting, None), (
1053
- "Expected per-target setting for '%s', got per-config setting "
1054
- "(target %s)" % (setting, self.spec["target_name"])
1055
- )
1056
- if result is None:
1057
- return default
1058
- return result
1059
-
1060
- def _GetStripPostbuilds(self, configname, output_binary, quiet):
1061
- """Returns a list of shell commands that contain the shell commands
1062
- necessary to strip this target's binary. These should be run as postbuilds
1063
- before the actual postbuilds run."""
1064
- self.configname = configname
1065
-
1066
- result = []
1067
- if self._Test("DEPLOYMENT_POSTPROCESSING", "YES", default="NO") and self._Test(
1068
- "STRIP_INSTALLED_PRODUCT", "YES", default="NO"
1069
- ):
1070
-
1071
- default_strip_style = "debugging"
1072
- if (
1073
- self.spec["type"] == "loadable_module" or self._IsIosAppExtension()
1074
- ) and self._IsBundle():
1075
- default_strip_style = "non-global"
1076
- elif self.spec["type"] == "executable":
1077
- default_strip_style = "all"
1078
-
1079
- strip_style = self._Settings().get("STRIP_STYLE", default_strip_style)
1080
- strip_flags = {"all": "", "non-global": "-x", "debugging": "-S"}[
1081
- strip_style
1082
- ]
1083
-
1084
- explicit_strip_flags = self._Settings().get("STRIPFLAGS", "")
1085
- if explicit_strip_flags:
1086
- strip_flags += " " + _NormalizeEnvVarReferences(explicit_strip_flags)
1087
-
1088
- if not quiet:
1089
- result.append("echo STRIP\\(%s\\)" % self.spec["target_name"])
1090
- result.append(f"strip {strip_flags} {output_binary}")
1091
-
1092
- self.configname = None
1093
- return result
1094
-
1095
- def _GetDebugInfoPostbuilds(self, configname, output, output_binary, quiet):
1096
- """Returns a list of shell commands that contain the shell commands
1097
- necessary to massage this target's debug information. These should be run
1098
- as postbuilds before the actual postbuilds run."""
1099
- self.configname = configname
1100
-
1101
- # For static libraries, no dSYMs are created.
1102
- result = []
1103
- if (
1104
- self._Test("GCC_GENERATE_DEBUGGING_SYMBOLS", "YES", default="YES")
1105
- and self._Test(
1106
- "DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym", default="dwarf"
1107
- )
1108
- and self.spec["type"] != "static_library"
1109
- ):
1110
- if not quiet:
1111
- result.append("echo DSYMUTIL\\(%s\\)" % self.spec["target_name"])
1112
- result.append("dsymutil {} -o {}".format(output_binary, output + ".dSYM"))
1113
-
1114
- self.configname = None
1115
- return result
1116
-
1117
- def _GetTargetPostbuilds(self, configname, output, output_binary, quiet=False):
1118
- """Returns a list of shell commands that contain the shell commands
1119
- to run as postbuilds for this target, before the actual postbuilds."""
1120
- # dSYMs need to build before stripping happens.
1121
- return self._GetDebugInfoPostbuilds(
1122
- configname, output, output_binary, quiet
1123
- ) + self._GetStripPostbuilds(configname, output_binary, quiet)
1124
-
1125
- def _GetIOSPostbuilds(self, configname, output_binary):
1126
- """Return a shell command to codesign the iOS output binary so it can
1127
- be deployed to a device. This should be run as the very last step of the
1128
- build."""
1129
- if not (
1130
- self.isIOS
1131
- and (self.spec["type"] == "executable" or self._IsXCTest())
1132
- or self.IsIosFramework()
1133
- ):
1134
- return []
1135
-
1136
- postbuilds = []
1137
- product_name = self.GetFullProductName()
1138
- settings = self.xcode_settings[configname]
1139
-
1140
- # Xcode expects XCTests to be copied into the TEST_HOST dir.
1141
- if self._IsXCTest():
1142
- source = os.path.join("${BUILT_PRODUCTS_DIR}", product_name)
1143
- test_host = os.path.dirname(settings.get("TEST_HOST"))
1144
- xctest_destination = os.path.join(test_host, "PlugIns", product_name)
1145
- postbuilds.extend([f"ditto {source} {xctest_destination}"])
1146
-
1147
- key = self._GetIOSCodeSignIdentityKey(settings)
1148
- if not key:
1149
- return postbuilds
1150
-
1151
- # Warn for any unimplemented signing xcode keys.
1152
- unimpl = ["OTHER_CODE_SIGN_FLAGS"]
1153
- unimpl = set(unimpl) & set(self.xcode_settings[configname].keys())
1154
- if unimpl:
1155
- print(
1156
- "Warning: Some codesign keys not implemented, ignoring: %s"
1157
- % ", ".join(sorted(unimpl))
1158
- )
1159
-
1160
- if self._IsXCTest():
1161
- # For device xctests, Xcode copies two extra frameworks into $TEST_HOST.
1162
- test_host = os.path.dirname(settings.get("TEST_HOST"))
1163
- frameworks_dir = os.path.join(test_host, "Frameworks")
1164
- platform_root = self._XcodePlatformPath(configname)
1165
- frameworks = [
1166
- "Developer/Library/PrivateFrameworks/IDEBundleInjection.framework",
1167
- "Developer/Library/Frameworks/XCTest.framework",
1168
- ]
1169
- for framework in frameworks:
1170
- source = os.path.join(platform_root, framework)
1171
- destination = os.path.join(frameworks_dir, os.path.basename(framework))
1172
- postbuilds.extend([f"ditto {source} {destination}"])
1173
-
1174
- # Then re-sign everything with 'preserve=True'
1175
- postbuilds.extend(
1176
- [
1177
- '%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
1178
- % (
1179
- os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
1180
- key,
1181
- settings.get("CODE_SIGN_ENTITLEMENTS", ""),
1182
- settings.get("PROVISIONING_PROFILE", ""),
1183
- destination,
1184
- True,
1185
- )
1186
- ]
1187
- )
1188
- plugin_dir = os.path.join(test_host, "PlugIns")
1189
- targets = [os.path.join(plugin_dir, product_name), test_host]
1190
- for target in targets:
1191
- postbuilds.extend(
1192
- [
1193
- '%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
1194
- % (
1195
- os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
1196
- key,
1197
- settings.get("CODE_SIGN_ENTITLEMENTS", ""),
1198
- settings.get("PROVISIONING_PROFILE", ""),
1199
- target,
1200
- True,
1201
- )
1202
- ]
1203
- )
1204
-
1205
- postbuilds.extend(
1206
- [
1207
- '%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
1208
- % (
1209
- os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
1210
- key,
1211
- settings.get("CODE_SIGN_ENTITLEMENTS", ""),
1212
- settings.get("PROVISIONING_PROFILE", ""),
1213
- os.path.join("${BUILT_PRODUCTS_DIR}", product_name),
1214
- False,
1215
- )
1216
- ]
1217
- )
1218
- return postbuilds
1219
-
1220
- def _GetIOSCodeSignIdentityKey(self, settings):
1221
- identity = settings.get("CODE_SIGN_IDENTITY")
1222
- if not identity:
1223
- return None
1224
- if identity not in XcodeSettings._codesigning_key_cache:
1225
- output = subprocess.check_output(
1226
- ["security", "find-identity", "-p", "codesigning", "-v"]
1227
- )
1228
- for line in output.splitlines():
1229
- if identity in line:
1230
- fingerprint = line.split()[1]
1231
- cache = XcodeSettings._codesigning_key_cache
1232
- assert identity not in cache or fingerprint == cache[identity], (
1233
- "Multiple codesigning fingerprints for identity: %s" % identity
1234
- )
1235
- XcodeSettings._codesigning_key_cache[identity] = fingerprint
1236
- return XcodeSettings._codesigning_key_cache.get(identity, "")
1237
-
1238
- def AddImplicitPostbuilds(
1239
- self, configname, output, output_binary, postbuilds=[], quiet=False
1240
- ):
1241
- """Returns a list of shell commands that should run before and after
1242
- |postbuilds|."""
1243
- assert output_binary is not None
1244
- pre = self._GetTargetPostbuilds(configname, output, output_binary, quiet)
1245
- post = self._GetIOSPostbuilds(configname, output_binary)
1246
- return pre + postbuilds + post
1247
-
1248
- def _AdjustLibrary(self, library, config_name=None):
1249
- if library.endswith(".framework"):
1250
- l_flag = "-framework " + os.path.splitext(os.path.basename(library))[0]
1251
- else:
1252
- m = self.library_re.match(library)
1253
- l_flag = "-l" + m.group(1) if m else library
1254
-
1255
- sdk_root = self._SdkPath(config_name)
1256
- if not sdk_root:
1257
- sdk_root = ""
1258
- # Xcode 7 started shipping with ".tbd" (text based stubs) files instead of
1259
- # ".dylib" without providing a real support for them. What it does, for
1260
- # "/usr/lib" libraries, is do "-L/usr/lib -lname" which is dependent on the
1261
- # library order and cause collision when building Chrome.
1262
- #
1263
- # Instead substitute ".tbd" to ".dylib" in the generated project when the
1264
- # following conditions are both true:
1265
- # - library is referenced in the gyp file as "$(SDKROOT)/**/*.dylib",
1266
- # - the ".dylib" file does not exists but a ".tbd" file do.
1267
- library = l_flag.replace("$(SDKROOT)", sdk_root)
1268
- if l_flag.startswith("$(SDKROOT)"):
1269
- basename, ext = os.path.splitext(library)
1270
- if ext == ".dylib" and not os.path.exists(library):
1271
- tbd_library = basename + ".tbd"
1272
- if os.path.exists(tbd_library):
1273
- library = tbd_library
1274
- return library
1275
-
1276
- def AdjustLibraries(self, libraries, config_name=None):
1277
- """Transforms entries like 'Cocoa.framework' in libraries into entries like
1278
- '-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc.
1279
- """
1280
- libraries = [self._AdjustLibrary(library, config_name) for library in libraries]
1281
- return libraries
1282
-
1283
- def _BuildMachineOSBuild(self):
1284
- return GetStdout(["sw_vers", "-buildVersion"])
1285
-
1286
- def _XcodeIOSDeviceFamily(self, configname):
1287
- family = self.xcode_settings[configname].get("TARGETED_DEVICE_FAMILY", "1")
1288
- return [int(x) for x in family.split(",")]
1289
-
1290
- def GetExtraPlistItems(self, configname=None):
1291
- """Returns a dictionary with extra items to insert into Info.plist."""
1292
- if configname not in XcodeSettings._plist_cache:
1293
- cache = {}
1294
- cache["BuildMachineOSBuild"] = self._BuildMachineOSBuild()
1295
-
1296
- xcode_version, xcode_build = XcodeVersion()
1297
- cache["DTXcode"] = xcode_version
1298
- cache["DTXcodeBuild"] = xcode_build
1299
- compiler = self.xcode_settings[configname].get("GCC_VERSION")
1300
- if compiler is not None:
1301
- cache["DTCompiler"] = compiler
1302
-
1303
- sdk_root = self._SdkRoot(configname)
1304
- if not sdk_root:
1305
- sdk_root = self._DefaultSdkRoot()
1306
- sdk_version = self._GetSdkVersionInfoItem(sdk_root, "--show-sdk-version")
1307
- cache["DTSDKName"] = sdk_root + (sdk_version or "")
1308
- if xcode_version >= "0720":
1309
- cache["DTSDKBuild"] = self._GetSdkVersionInfoItem(
1310
- sdk_root, "--show-sdk-build-version"
1311
- )
1312
- elif xcode_version >= "0430":
1313
- cache["DTSDKBuild"] = sdk_version
1314
- else:
1315
- cache["DTSDKBuild"] = cache["BuildMachineOSBuild"]
1316
-
1317
- if self.isIOS:
1318
- cache["MinimumOSVersion"] = self.xcode_settings[configname].get(
1319
- "IPHONEOS_DEPLOYMENT_TARGET"
1320
- )
1321
- cache["DTPlatformName"] = sdk_root
1322
- cache["DTPlatformVersion"] = sdk_version
1323
-
1324
- if configname.endswith("iphoneos"):
1325
- cache["CFBundleSupportedPlatforms"] = ["iPhoneOS"]
1326
- cache["DTPlatformBuild"] = cache["DTSDKBuild"]
1327
- else:
1328
- cache["CFBundleSupportedPlatforms"] = ["iPhoneSimulator"]
1329
- # This is weird, but Xcode sets DTPlatformBuild to an empty field
1330
- # for simulator builds.
1331
- cache["DTPlatformBuild"] = ""
1332
- XcodeSettings._plist_cache[configname] = cache
1333
-
1334
- # Include extra plist items that are per-target, not per global
1335
- # XcodeSettings.
1336
- items = dict(XcodeSettings._plist_cache[configname])
1337
- if self.isIOS:
1338
- items["UIDeviceFamily"] = self._XcodeIOSDeviceFamily(configname)
1339
- return items
1340
-
1341
- def _DefaultSdkRoot(self):
1342
- """Returns the default SDKROOT to use.
1343
-
1344
- Prior to version 5.0.0, if SDKROOT was not explicitly set in the Xcode
1345
- project, then the environment variable was empty. Starting with this
1346
- version, Xcode uses the name of the newest SDK installed.
1347
- """
1348
- xcode_version, _ = XcodeVersion()
1349
- if xcode_version < "0500":
1350
- return ""
1351
- default_sdk_path = self._XcodeSdkPath("")
1352
- default_sdk_root = XcodeSettings._sdk_root_cache.get(default_sdk_path)
1353
- if default_sdk_root:
1354
- return default_sdk_root
1355
- try:
1356
- all_sdks = GetStdout(["xcodebuild", "-showsdks"])
1357
- except GypError:
1358
- # If xcodebuild fails, there will be no valid SDKs
1359
- return ""
1360
- for line in all_sdks.splitlines():
1361
- items = line.split()
1362
- if len(items) >= 3 and items[-2] == "-sdk":
1363
- sdk_root = items[-1]
1364
- sdk_path = self._XcodeSdkPath(sdk_root)
1365
- if sdk_path == default_sdk_path:
1366
- return sdk_root
1367
- return ""
1368
-
1369
-
1370
- class MacPrefixHeader:
1371
- """A class that helps with emulating Xcode's GCC_PREFIX_HEADER feature.
1372
-
1373
- This feature consists of several pieces:
1374
- * If GCC_PREFIX_HEADER is present, all compilations in that project get an
1375
- additional |-include path_to_prefix_header| cflag.
1376
- * If GCC_PRECOMPILE_PREFIX_HEADER is present too, then the prefix header is
1377
- instead compiled, and all other compilations in the project get an
1378
- additional |-include path_to_compiled_header| instead.
1379
- + Compiled prefix headers have the extension gch. There is one gch file for
1380
- every language used in the project (c, cc, m, mm), since gch files for
1381
- different languages aren't compatible.
1382
- + gch files themselves are built with the target's normal cflags, but they
1383
- obviously don't get the |-include| flag. Instead, they need a -x flag that
1384
- describes their language.
1385
- + All o files in the target need to depend on the gch file, to make sure
1386
- it's built before any o file is built.
1387
-
1388
- This class helps with some of these tasks, but it needs help from the build
1389
- system for writing dependencies to the gch files, for writing build commands
1390
- for the gch files, and for figuring out the location of the gch files.
1391
- """
1392
-
1393
- def __init__(
1394
- self, xcode_settings, gyp_path_to_build_path, gyp_path_to_build_output
1395
- ):
1396
- """If xcode_settings is None, all methods on this class are no-ops.
1397
-
1398
- Args:
1399
- gyp_path_to_build_path: A function that takes a gyp-relative path,
1400
- and returns a path relative to the build directory.
1401
- gyp_path_to_build_output: A function that takes a gyp-relative path and
1402
- a language code ('c', 'cc', 'm', or 'mm'), and that returns a path
1403
- to where the output of precompiling that path for that language
1404
- should be placed (without the trailing '.gch').
1405
- """
1406
- # This doesn't support per-configuration prefix headers. Good enough
1407
- # for now.
1408
- self.header = None
1409
- self.compile_headers = False
1410
- if xcode_settings:
1411
- self.header = xcode_settings.GetPerTargetSetting("GCC_PREFIX_HEADER")
1412
- self.compile_headers = (
1413
- xcode_settings.GetPerTargetSetting(
1414
- "GCC_PRECOMPILE_PREFIX_HEADER", default="NO"
1415
- )
1416
- != "NO"
1417
- )
1418
- self.compiled_headers = {}
1419
- if self.header:
1420
- if self.compile_headers:
1421
- for lang in ["c", "cc", "m", "mm"]:
1422
- self.compiled_headers[lang] = gyp_path_to_build_output(
1423
- self.header, lang
1424
- )
1425
- self.header = gyp_path_to_build_path(self.header)
1426
-
1427
- def _CompiledHeader(self, lang, arch):
1428
- assert self.compile_headers
1429
- h = self.compiled_headers[lang]
1430
- if arch:
1431
- h += "." + arch
1432
- return h
1433
-
1434
- def GetInclude(self, lang, arch=None):
1435
- """Gets the cflags to include the prefix header for language |lang|."""
1436
- if self.compile_headers and lang in self.compiled_headers:
1437
- return "-include %s" % self._CompiledHeader(lang, arch)
1438
- elif self.header:
1439
- return "-include %s" % self.header
1440
- else:
1441
- return ""
1442
-
1443
- def _Gch(self, lang, arch):
1444
- """Returns the actual file name of the prefix header for language |lang|."""
1445
- assert self.compile_headers
1446
- return self._CompiledHeader(lang, arch) + ".gch"
1447
-
1448
- def GetObjDependencies(self, sources, objs, arch=None):
1449
- """Given a list of source files and the corresponding object files, returns
1450
- a list of (source, object, gch) tuples, where |gch| is the build-directory
1451
- relative path to the gch file each object file depends on. |compilable[i]|
1452
- has to be the source file belonging to |objs[i]|."""
1453
- if not self.header or not self.compile_headers:
1454
- return []
1455
-
1456
- result = []
1457
- for source, obj in zip(sources, objs):
1458
- ext = os.path.splitext(source)[1]
1459
- lang = {
1460
- ".c": "c",
1461
- ".cpp": "cc",
1462
- ".cc": "cc",
1463
- ".cxx": "cc",
1464
- ".m": "m",
1465
- ".mm": "mm",
1466
- }.get(ext, None)
1467
- if lang:
1468
- result.append((source, obj, self._Gch(lang, arch)))
1469
- return result
1470
-
1471
- def GetPchBuildCommands(self, arch=None):
1472
- """Returns [(path_to_gch, language_flag, language, header)].
1473
- |path_to_gch| and |header| are relative to the build directory.
1474
- """
1475
- if not self.header or not self.compile_headers:
1476
- return []
1477
- return [
1478
- (self._Gch("c", arch), "-x c-header", "c", self.header),
1479
- (self._Gch("cc", arch), "-x c++-header", "cc", self.header),
1480
- (self._Gch("m", arch), "-x objective-c-header", "m", self.header),
1481
- (self._Gch("mm", arch), "-x objective-c++-header", "mm", self.header),
1482
- ]
1483
-
1484
-
1485
- def XcodeVersion():
1486
- """Returns a tuple of version and build version of installed Xcode."""
1487
- # `xcodebuild -version` output looks like
1488
- # Xcode 4.6.3
1489
- # Build version 4H1503
1490
- # or like
1491
- # Xcode 3.2.6
1492
- # Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
1493
- # BuildVersion: 10M2518
1494
- # Convert that to ('0463', '4H1503') or ('0326', '10M2518').
1495
- global XCODE_VERSION_CACHE
1496
- if XCODE_VERSION_CACHE:
1497
- return XCODE_VERSION_CACHE
1498
- version = ""
1499
- build = ""
1500
- try:
1501
- version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines()
1502
- # In some circumstances xcodebuild exits 0 but doesn't return
1503
- # the right results; for example, a user on 10.7 or 10.8 with
1504
- # a bogus path set via xcode-select
1505
- # In that case this may be a CLT-only install so fall back to
1506
- # checking that version.
1507
- if len(version_list) < 2:
1508
- raise GypError("xcodebuild returned unexpected results")
1509
- version = version_list[0].split()[-1] # Last word on first line
1510
- build = version_list[-1].split()[-1] # Last word on last line
1511
- except GypError: # Xcode not installed so look for XCode Command Line Tools
1512
- version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
1513
- if not version:
1514
- raise GypError("No Xcode or CLT version detected!")
1515
- # Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100":
1516
- version = version.split(".")[:3] # Just major, minor, micro
1517
- version[0] = version[0].zfill(2) # Add a leading zero if major is one digit
1518
- version = ("".join(version) + "00")[:4] # Limit to exactly four characters
1519
- XCODE_VERSION_CACHE = (version, build)
1520
- return XCODE_VERSION_CACHE
1521
-
1522
-
1523
- # This function ported from the logic in Homebrew's CLT version check
1524
- def CLTVersion():
1525
- """Returns the version of command-line tools from pkgutil."""
1526
- # pkgutil output looks like
1527
- # package-id: com.apple.pkg.CLTools_Executables
1528
- # version: 5.0.1.0.1.1382131676
1529
- # volume: /
1530
- # location: /
1531
- # install-time: 1382544035
1532
- # groups: com.apple.FindSystemFiles.pkg-group
1533
- # com.apple.DevToolsBoth.pkg-group
1534
- # com.apple.DevToolsNonRelocatableShared.pkg-group
1535
- STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo"
1536
- FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI"
1537
- MAVERICKS_PKG_ID = "com.apple.pkg.CLTools_Executables"
1538
-
1539
- regex = re.compile("version: (?P<version>.+)")
1540
- for key in [MAVERICKS_PKG_ID, STANDALONE_PKG_ID, FROM_XCODE_PKG_ID]:
1541
- try:
1542
- output = GetStdout(["/usr/sbin/pkgutil", "--pkg-info", key])
1543
- return re.search(regex, output).groupdict()["version"]
1544
- except GypError:
1545
- continue
1546
-
1547
- regex = re.compile(r"Command Line Tools for Xcode\s+(?P<version>\S+)")
1548
- try:
1549
- output = GetStdout(["/usr/sbin/softwareupdate", "--history"])
1550
- return re.search(regex, output).groupdict()["version"]
1551
- except GypError:
1552
- return None
1553
-
1554
-
1555
- def GetStdoutQuiet(cmdlist):
1556
- """Returns the content of standard output returned by invoking |cmdlist|.
1557
- Ignores the stderr.
1558
- Raises |GypError| if the command return with a non-zero return code."""
1559
- job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
1560
- out = job.communicate()[0].decode("utf-8")
1561
- if job.returncode != 0:
1562
- raise GypError("Error %d running %s" % (job.returncode, cmdlist[0]))
1563
- return out.rstrip("\n")
1564
-
1565
-
1566
- def GetStdout(cmdlist):
1567
- """Returns the content of standard output returned by invoking |cmdlist|.
1568
- Raises |GypError| if the command return with a non-zero return code."""
1569
- job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE)
1570
- out = job.communicate()[0].decode("utf-8")
1571
- if job.returncode != 0:
1572
- sys.stderr.write(out + "\n")
1573
- raise GypError("Error %d running %s" % (job.returncode, cmdlist[0]))
1574
- return out.rstrip("\n")
1575
-
1576
-
1577
- def MergeGlobalXcodeSettingsToSpec(global_dict, spec):
1578
- """Merges the global xcode_settings dictionary into each configuration of the
1579
- target represented by spec. For keys that are both in the global and the local
1580
- xcode_settings dict, the local key gets precedence.
1581
- """
1582
- # The xcode generator special-cases global xcode_settings and does something
1583
- # that amounts to merging in the global xcode_settings into each local
1584
- # xcode_settings dict.
1585
- global_xcode_settings = global_dict.get("xcode_settings", {})
1586
- for config in spec["configurations"].values():
1587
- if "xcode_settings" in config:
1588
- new_settings = global_xcode_settings.copy()
1589
- new_settings.update(config["xcode_settings"])
1590
- config["xcode_settings"] = new_settings
1591
-
1592
-
1593
- def IsMacBundle(flavor, spec):
1594
- """Returns if |spec| should be treated as a bundle.
1595
-
1596
- Bundles are directories with a certain subdirectory structure, instead of
1597
- just a single file. Bundle rules do not produce a binary but also package
1598
- resources into that directory."""
1599
- is_mac_bundle = (
1600
- int(spec.get("mac_xctest_bundle", 0)) != 0
1601
- or int(spec.get("mac_xcuitest_bundle", 0)) != 0
1602
- or (int(spec.get("mac_bundle", 0)) != 0 and flavor == "mac")
1603
- )
1604
-
1605
- if is_mac_bundle:
1606
- assert spec["type"] != "none", (
1607
- 'mac_bundle targets cannot have type none (target "%s")'
1608
- % spec["target_name"]
1609
- )
1610
- return is_mac_bundle
1611
-
1612
-
1613
- def GetMacBundleResources(product_dir, xcode_settings, resources):
1614
- """Yields (output, resource) pairs for every resource in |resources|.
1615
- Only call this for mac bundle targets.
1616
-
1617
- Args:
1618
- product_dir: Path to the directory containing the output bundle,
1619
- relative to the build directory.
1620
- xcode_settings: The XcodeSettings of the current target.
1621
- resources: A list of bundle resources, relative to the build directory.
1622
- """
1623
- dest = os.path.join(product_dir, xcode_settings.GetBundleResourceFolder())
1624
- for res in resources:
1625
- output = dest
1626
-
1627
- # The make generator doesn't support it, so forbid it everywhere
1628
- # to keep the generators more interchangeable.
1629
- assert " " not in res, "Spaces in resource filenames not supported (%s)" % res
1630
-
1631
- # Split into (path,file).
1632
- res_parts = os.path.split(res)
1633
-
1634
- # Now split the path into (prefix,maybe.lproj).
1635
- lproj_parts = os.path.split(res_parts[0])
1636
- # If the resource lives in a .lproj bundle, add that to the destination.
1637
- if lproj_parts[1].endswith(".lproj"):
1638
- output = os.path.join(output, lproj_parts[1])
1639
-
1640
- output = os.path.join(output, res_parts[1])
1641
- # Compiled XIB files are referred to by .nib.
1642
- if output.endswith(".xib"):
1643
- output = os.path.splitext(output)[0] + ".nib"
1644
- # Compiled storyboard files are referred to by .storyboardc.
1645
- if output.endswith(".storyboard"):
1646
- output = os.path.splitext(output)[0] + ".storyboardc"
1647
-
1648
- yield output, res
1649
-
1650
-
1651
- def GetMacInfoPlist(product_dir, xcode_settings, gyp_path_to_build_path):
1652
- """Returns (info_plist, dest_plist, defines, extra_env), where:
1653
- * |info_plist| is the source plist path, relative to the
1654
- build directory,
1655
- * |dest_plist| is the destination plist path, relative to the
1656
- build directory,
1657
- * |defines| is a list of preprocessor defines (empty if the plist
1658
- shouldn't be preprocessed,
1659
- * |extra_env| is a dict of env variables that should be exported when
1660
- invoking |mac_tool copy-info-plist|.
1661
-
1662
- Only call this for mac bundle targets.
1663
-
1664
- Args:
1665
- product_dir: Path to the directory containing the output bundle,
1666
- relative to the build directory.
1667
- xcode_settings: The XcodeSettings of the current target.
1668
- gyp_to_build_path: A function that converts paths relative to the
1669
- current gyp file to paths relative to the build directory.
1670
- """
1671
- info_plist = xcode_settings.GetPerTargetSetting("INFOPLIST_FILE")
1672
- if not info_plist:
1673
- return None, None, [], {}
1674
-
1675
- # The make generator doesn't support it, so forbid it everywhere
1676
- # to keep the generators more interchangeable.
1677
- assert " " not in info_plist, (
1678
- "Spaces in Info.plist filenames not supported (%s)" % info_plist
1679
- )
1680
-
1681
- info_plist = gyp_path_to_build_path(info_plist)
1682
-
1683
- # If explicitly set to preprocess the plist, invoke the C preprocessor and
1684
- # specify any defines as -D flags.
1685
- if (
1686
- xcode_settings.GetPerTargetSetting("INFOPLIST_PREPROCESS", default="NO")
1687
- == "YES"
1688
- ):
1689
- # Create an intermediate file based on the path.
1690
- defines = shlex.split(
1691
- xcode_settings.GetPerTargetSetting(
1692
- "INFOPLIST_PREPROCESSOR_DEFINITIONS", default=""
1693
- )
1694
- )
1695
- else:
1696
- defines = []
1697
-
1698
- dest_plist = os.path.join(product_dir, xcode_settings.GetBundlePlistPath())
1699
- extra_env = xcode_settings.GetPerTargetSettings()
1700
-
1701
- return info_plist, dest_plist, defines, extra_env
1702
-
1703
-
1704
- def _GetXcodeEnv(
1705
- xcode_settings, built_products_dir, srcroot, configuration, additional_settings=None
1706
- ):
1707
- """Return the environment variables that Xcode would set. See
1708
- http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW153
1709
- for a full list.
1710
-
1711
- Args:
1712
- xcode_settings: An XcodeSettings object. If this is None, this function
1713
- returns an empty dict.
1714
- built_products_dir: Absolute path to the built products dir.
1715
- srcroot: Absolute path to the source root.
1716
- configuration: The build configuration name.
1717
- additional_settings: An optional dict with more values to add to the
1718
- result.
1719
- """
1720
-
1721
- if not xcode_settings:
1722
- return {}
1723
-
1724
- # This function is considered a friend of XcodeSettings, so let it reach into
1725
- # its implementation details.
1726
- spec = xcode_settings.spec
1727
-
1728
- # These are filled in on an as-needed basis.
1729
- env = {
1730
- "BUILT_FRAMEWORKS_DIR": built_products_dir,
1731
- "BUILT_PRODUCTS_DIR": built_products_dir,
1732
- "CONFIGURATION": configuration,
1733
- "PRODUCT_NAME": xcode_settings.GetProductName(),
1734
- # For FULL_PRODUCT_NAME see:
1735
- # /Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX\ Product\ Types.xcspec # noqa: E501
1736
- "SRCROOT": srcroot,
1737
- "SOURCE_ROOT": "${SRCROOT}",
1738
- # This is not true for static libraries, but currently the env is only
1739
- # written for bundles:
1740
- "TARGET_BUILD_DIR": built_products_dir,
1741
- "TEMP_DIR": "${TMPDIR}",
1742
- "XCODE_VERSION_ACTUAL": XcodeVersion()[0],
1743
- }
1744
- if xcode_settings.GetPerConfigSetting("SDKROOT", configuration):
1745
- env["SDKROOT"] = xcode_settings._SdkPath(configuration)
1746
- else:
1747
- env["SDKROOT"] = ""
1748
-
1749
- if xcode_settings.mac_toolchain_dir:
1750
- env["DEVELOPER_DIR"] = xcode_settings.mac_toolchain_dir
1751
-
1752
- if spec["type"] in (
1753
- "executable",
1754
- "static_library",
1755
- "shared_library",
1756
- "loadable_module",
1757
- ):
1758
- env["EXECUTABLE_NAME"] = xcode_settings.GetExecutableName()
1759
- env["EXECUTABLE_PATH"] = xcode_settings.GetExecutablePath()
1760
- env["FULL_PRODUCT_NAME"] = xcode_settings.GetFullProductName()
1761
- mach_o_type = xcode_settings.GetMachOType()
1762
- if mach_o_type:
1763
- env["MACH_O_TYPE"] = mach_o_type
1764
- env["PRODUCT_TYPE"] = xcode_settings.GetProductType()
1765
- if xcode_settings._IsBundle():
1766
- # xcodeproj_file.py sets the same Xcode subfolder value for this as for
1767
- # FRAMEWORKS_FOLDER_PATH so Xcode builds will actually use FFP's value.
1768
- env["BUILT_FRAMEWORKS_DIR"] = os.path.join(
1769
- built_products_dir + os.sep + xcode_settings.GetBundleFrameworksFolderPath()
1770
- )
1771
- env["CONTENTS_FOLDER_PATH"] = xcode_settings.GetBundleContentsFolderPath()
1772
- env["EXECUTABLE_FOLDER_PATH"] = xcode_settings.GetBundleExecutableFolderPath()
1773
- env[
1774
- "UNLOCALIZED_RESOURCES_FOLDER_PATH"
1775
- ] = xcode_settings.GetBundleResourceFolder()
1776
- env["JAVA_FOLDER_PATH"] = xcode_settings.GetBundleJavaFolderPath()
1777
- env["FRAMEWORKS_FOLDER_PATH"] = xcode_settings.GetBundleFrameworksFolderPath()
1778
- env[
1779
- "SHARED_FRAMEWORKS_FOLDER_PATH"
1780
- ] = xcode_settings.GetBundleSharedFrameworksFolderPath()
1781
- env[
1782
- "SHARED_SUPPORT_FOLDER_PATH"
1783
- ] = xcode_settings.GetBundleSharedSupportFolderPath()
1784
- env["PLUGINS_FOLDER_PATH"] = xcode_settings.GetBundlePlugInsFolderPath()
1785
- env["XPCSERVICES_FOLDER_PATH"] = xcode_settings.GetBundleXPCServicesFolderPath()
1786
- env["INFOPLIST_PATH"] = xcode_settings.GetBundlePlistPath()
1787
- env["WRAPPER_NAME"] = xcode_settings.GetWrapperName()
1788
-
1789
- install_name = xcode_settings.GetInstallName()
1790
- if install_name:
1791
- env["LD_DYLIB_INSTALL_NAME"] = install_name
1792
- install_name_base = xcode_settings.GetInstallNameBase()
1793
- if install_name_base:
1794
- env["DYLIB_INSTALL_NAME_BASE"] = install_name_base
1795
- xcode_version, _ = XcodeVersion()
1796
- if xcode_version >= "0500" and not env.get("SDKROOT"):
1797
- sdk_root = xcode_settings._SdkRoot(configuration)
1798
- if not sdk_root:
1799
- sdk_root = xcode_settings._XcodeSdkPath("")
1800
- if sdk_root is None:
1801
- sdk_root = ""
1802
- env["SDKROOT"] = sdk_root
1803
-
1804
- if not additional_settings:
1805
- additional_settings = {}
1806
- else:
1807
- # Flatten lists to strings.
1808
- for k in additional_settings:
1809
- if not isinstance(additional_settings[k], str):
1810
- additional_settings[k] = " ".join(additional_settings[k])
1811
- additional_settings.update(env)
1812
-
1813
- for k in additional_settings:
1814
- additional_settings[k] = _NormalizeEnvVarReferences(additional_settings[k])
1815
-
1816
- return additional_settings
1817
-
1818
-
1819
- def _NormalizeEnvVarReferences(str):
1820
- """Takes a string containing variable references in the form ${FOO}, $(FOO),
1821
- or $FOO, and returns a string with all variable references in the form ${FOO}.
1822
- """
1823
- # $FOO -> ${FOO}
1824
- str = re.sub(r"\$([a-zA-Z_][a-zA-Z0-9_]*)", r"${\1}", str)
1825
-
1826
- # $(FOO) -> ${FOO}
1827
- matches = re.findall(r"(\$\(([a-zA-Z0-9\-_]+)\))", str)
1828
- for match in matches:
1829
- to_replace, variable = match
1830
- assert "$(" not in match, "$($(FOO)) variables not supported: " + match
1831
- str = str.replace(to_replace, "${" + variable + "}")
1832
-
1833
- return str
1834
-
1835
-
1836
- def ExpandEnvVars(string, expansions):
1837
- """Expands ${VARIABLES}, $(VARIABLES), and $VARIABLES in string per the
1838
- expansions list. If the variable expands to something that references
1839
- another variable, this variable is expanded as well if it's in env --
1840
- until no variables present in env are left."""
1841
- for k, v in reversed(expansions):
1842
- string = string.replace("${" + k + "}", v)
1843
- string = string.replace("$(" + k + ")", v)
1844
- string = string.replace("$" + k, v)
1845
- return string
1846
-
1847
-
1848
- def _TopologicallySortedEnvVarKeys(env):
1849
- """Takes a dict |env| whose values are strings that can refer to other keys,
1850
- for example env['foo'] = '$(bar) and $(baz)'. Returns a list L of all keys of
1851
- env such that key2 is after key1 in L if env[key2] refers to env[key1].
1852
-
1853
- Throws an Exception in case of dependency cycles.
1854
- """
1855
- # Since environment variables can refer to other variables, the evaluation
1856
- # order is important. Below is the logic to compute the dependency graph
1857
- # and sort it.
1858
- regex = re.compile(r"\$\{([a-zA-Z0-9\-_]+)\}")
1859
-
1860
- def GetEdges(node):
1861
- # Use a definition of edges such that user_of_variable -> used_varible.
1862
- # This happens to be easier in this case, since a variable's
1863
- # definition contains all variables it references in a single string.
1864
- # We can then reverse the result of the topological sort at the end.
1865
- # Since: reverse(topsort(DAG)) = topsort(reverse_edges(DAG))
1866
- matches = {v for v in regex.findall(env[node]) if v in env}
1867
- for dependee in matches:
1868
- assert "${" not in dependee, "Nested variables not supported: " + dependee
1869
- return matches
1870
-
1871
- try:
1872
- # Topologically sort, and then reverse, because we used an edge definition
1873
- # that's inverted from the expected result of this function (see comment
1874
- # above).
1875
- order = gyp.common.TopologicallySorted(env.keys(), GetEdges)
1876
- order.reverse()
1877
- return order
1878
- except gyp.common.CycleError as e:
1879
- raise GypError(
1880
- "Xcode environment variables are cyclically dependent: " + str(e.nodes)
1881
- )
1882
-
1883
-
1884
- def GetSortedXcodeEnv(
1885
- xcode_settings, built_products_dir, srcroot, configuration, additional_settings=None
1886
- ):
1887
- env = _GetXcodeEnv(
1888
- xcode_settings, built_products_dir, srcroot, configuration, additional_settings
1889
- )
1890
- return [(key, env[key]) for key in _TopologicallySortedEnvVarKeys(env)]
1891
-
1892
-
1893
- def GetSpecPostbuildCommands(spec, quiet=False):
1894
- """Returns the list of postbuilds explicitly defined on |spec|, in a form
1895
- executable by a shell."""
1896
- postbuilds = []
1897
- for postbuild in spec.get("postbuilds", []):
1898
- if not quiet:
1899
- postbuilds.append(
1900
- "echo POSTBUILD\\(%s\\) %s"
1901
- % (spec["target_name"], postbuild["postbuild_name"])
1902
- )
1903
- postbuilds.append(gyp.common.EncodePOSIXShellList(postbuild["action"]))
1904
- return postbuilds
1905
-
1906
-
1907
- def _HasIOSTarget(targets):
1908
- """Returns true if any target contains the iOS specific key
1909
- IPHONEOS_DEPLOYMENT_TARGET."""
1910
- for target_dict in targets.values():
1911
- for config in target_dict["configurations"].values():
1912
- if config.get("xcode_settings", {}).get("IPHONEOS_DEPLOYMENT_TARGET"):
1913
- return True
1914
- return False
1915
-
1916
-
1917
- def _AddIOSDeviceConfigurations(targets):
1918
- """Clone all targets and append -iphoneos to the name. Configure these targets
1919
- to build for iOS devices and use correct architectures for those builds."""
1920
- for target_dict in targets.values():
1921
- toolset = target_dict["toolset"]
1922
- configs = target_dict["configurations"]
1923
- for config_name, simulator_config_dict in dict(configs).items():
1924
- iphoneos_config_dict = copy.deepcopy(simulator_config_dict)
1925
- configs[config_name + "-iphoneos"] = iphoneos_config_dict
1926
- configs[config_name + "-iphonesimulator"] = simulator_config_dict
1927
- if toolset == "target":
1928
- simulator_config_dict["xcode_settings"]["SDKROOT"] = "iphonesimulator"
1929
- iphoneos_config_dict["xcode_settings"]["SDKROOT"] = "iphoneos"
1930
- return targets
1931
-
1932
-
1933
- def CloneConfigurationForDeviceAndEmulator(target_dicts):
1934
- """If |target_dicts| contains any iOS targets, automatically create -iphoneos
1935
- targets for iOS device builds."""
1936
- if _HasIOSTarget(target_dicts):
1937
- return _AddIOSDeviceConfigurations(target_dicts)
1938
- return target_dicts