@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,771 +0,0 @@
1
- #!/usr/bin/env python3
2
- # Copyright (c) 2012 Google Inc. All rights reserved.
3
- # Use of this source code is governed by a BSD-style license that can be
4
- # found in the LICENSE file.
5
-
6
- """Utility functions to perform Xcode-style build steps.
7
-
8
- These functions are executed via gyp-mac-tool when using the Makefile generator.
9
- """
10
-
11
-
12
- import fcntl
13
- import fnmatch
14
- import glob
15
- import json
16
- import os
17
- import plistlib
18
- import re
19
- import shutil
20
- import struct
21
- import subprocess
22
- import sys
23
- import tempfile
24
-
25
-
26
- def main(args):
27
- executor = MacTool()
28
- exit_code = executor.Dispatch(args)
29
- if exit_code is not None:
30
- sys.exit(exit_code)
31
-
32
-
33
- class MacTool:
34
- """This class performs all the Mac tooling steps. The methods can either be
35
- executed directly, or dispatched from an argument list."""
36
-
37
- def Dispatch(self, args):
38
- """Dispatches a string command to a method."""
39
- if len(args) < 1:
40
- raise Exception("Not enough arguments")
41
-
42
- method = "Exec%s" % self._CommandifyName(args[0])
43
- return getattr(self, method)(*args[1:])
44
-
45
- def _CommandifyName(self, name_string):
46
- """Transforms a tool name like copy-info-plist to CopyInfoPlist"""
47
- return name_string.title().replace("-", "")
48
-
49
- def ExecCopyBundleResource(self, source, dest, convert_to_binary):
50
- """Copies a resource file to the bundle/Resources directory, performing any
51
- necessary compilation on each resource."""
52
- convert_to_binary = convert_to_binary == "True"
53
- extension = os.path.splitext(source)[1].lower()
54
- if os.path.isdir(source):
55
- # Copy tree.
56
- # TODO(thakis): This copies file attributes like mtime, while the
57
- # single-file branch below doesn't. This should probably be changed to
58
- # be consistent with the single-file branch.
59
- if os.path.exists(dest):
60
- shutil.rmtree(dest)
61
- shutil.copytree(source, dest)
62
- elif extension == ".xib":
63
- return self._CopyXIBFile(source, dest)
64
- elif extension == ".storyboard":
65
- return self._CopyXIBFile(source, dest)
66
- elif extension == ".strings" and not convert_to_binary:
67
- self._CopyStringsFile(source, dest)
68
- else:
69
- if os.path.exists(dest):
70
- os.unlink(dest)
71
- shutil.copy(source, dest)
72
-
73
- if convert_to_binary and extension in (".plist", ".strings"):
74
- self._ConvertToBinary(dest)
75
-
76
- def _CopyXIBFile(self, source, dest):
77
- """Compiles a XIB file with ibtool into a binary plist in the bundle."""
78
-
79
- # ibtool sometimes crashes with relative paths. See crbug.com/314728.
80
- base = os.path.dirname(os.path.realpath(__file__))
81
- if os.path.relpath(source):
82
- source = os.path.join(base, source)
83
- if os.path.relpath(dest):
84
- dest = os.path.join(base, dest)
85
-
86
- args = ["xcrun", "ibtool", "--errors", "--warnings", "--notices"]
87
-
88
- if os.environ["XCODE_VERSION_ACTUAL"] > "0700":
89
- args.extend(["--auto-activate-custom-fonts"])
90
- if "IPHONEOS_DEPLOYMENT_TARGET" in os.environ:
91
- args.extend(
92
- [
93
- "--target-device",
94
- "iphone",
95
- "--target-device",
96
- "ipad",
97
- "--minimum-deployment-target",
98
- os.environ["IPHONEOS_DEPLOYMENT_TARGET"],
99
- ]
100
- )
101
- else:
102
- args.extend(
103
- [
104
- "--target-device",
105
- "mac",
106
- "--minimum-deployment-target",
107
- os.environ["MACOSX_DEPLOYMENT_TARGET"],
108
- ]
109
- )
110
-
111
- args.extend(
112
- ["--output-format", "human-readable-text", "--compile", dest, source]
113
- )
114
-
115
- ibtool_section_re = re.compile(r"/\*.*\*/")
116
- ibtool_re = re.compile(r".*note:.*is clipping its content")
117
- try:
118
- stdout = subprocess.check_output(args)
119
- except subprocess.CalledProcessError as e:
120
- print(e.output)
121
- raise
122
- current_section_header = None
123
- for line in stdout.splitlines():
124
- if ibtool_section_re.match(line):
125
- current_section_header = line
126
- elif not ibtool_re.match(line):
127
- if current_section_header:
128
- print(current_section_header)
129
- current_section_header = None
130
- print(line)
131
- return 0
132
-
133
- def _ConvertToBinary(self, dest):
134
- subprocess.check_call(
135
- ["xcrun", "plutil", "-convert", "binary1", "-o", dest, dest]
136
- )
137
-
138
- def _CopyStringsFile(self, source, dest):
139
- """Copies a .strings file using iconv to reconvert the input into UTF-16."""
140
- input_code = self._DetectInputEncoding(source) or "UTF-8"
141
-
142
- # Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call
143
- # CFPropertyListCreateFromXMLData() behind the scenes; at least it prints
144
- # CFPropertyListCreateFromXMLData(): Old-style plist parser: missing
145
- # semicolon in dictionary.
146
- # on invalid files. Do the same kind of validation.
147
- import CoreFoundation
148
-
149
- with open(source, "rb") as in_file:
150
- s = in_file.read()
151
- d = CoreFoundation.CFDataCreate(None, s, len(s))
152
- _, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None)
153
- if error:
154
- return
155
-
156
- with open(dest, "wb") as fp:
157
- fp.write(s.decode(input_code).encode("UTF-16"))
158
-
159
- def _DetectInputEncoding(self, file_name):
160
- """Reads the first few bytes from file_name and tries to guess the text
161
- encoding. Returns None as a guess if it can't detect it."""
162
- with open(file_name, "rb") as fp:
163
- try:
164
- header = fp.read(3)
165
- except Exception:
166
- return None
167
- if header.startswith(b"\xFE\xFF"):
168
- return "UTF-16"
169
- elif header.startswith(b"\xFF\xFE"):
170
- return "UTF-16"
171
- elif header.startswith(b"\xEF\xBB\xBF"):
172
- return "UTF-8"
173
- else:
174
- return None
175
-
176
- def ExecCopyInfoPlist(self, source, dest, convert_to_binary, *keys):
177
- """Copies the |source| Info.plist to the destination directory |dest|."""
178
- # Read the source Info.plist into memory.
179
- with open(source) as fd:
180
- lines = fd.read()
181
-
182
- # Insert synthesized key/value pairs (e.g. BuildMachineOSBuild).
183
- plist = plistlib.readPlistFromString(lines)
184
- if keys:
185
- plist.update(json.loads(keys[0]))
186
- lines = plistlib.writePlistToString(plist)
187
-
188
- # Go through all the environment variables and replace them as variables in
189
- # the file.
190
- IDENT_RE = re.compile(r"[_/\s]")
191
- for key in os.environ:
192
- if key.startswith("_"):
193
- continue
194
- evar = "${%s}" % key
195
- evalue = os.environ[key]
196
- lines = lines.replace(lines, evar, evalue)
197
-
198
- # Xcode supports various suffices on environment variables, which are
199
- # all undocumented. :rfc1034identifier is used in the standard project
200
- # template these days, and :identifier was used earlier. They are used to
201
- # convert non-url characters into things that look like valid urls --
202
- # except that the replacement character for :identifier, '_' isn't valid
203
- # in a URL either -- oops, hence :rfc1034identifier was born.
204
- evar = "${%s:identifier}" % key
205
- evalue = IDENT_RE.sub("_", os.environ[key])
206
- lines = lines.replace(lines, evar, evalue)
207
-
208
- evar = "${%s:rfc1034identifier}" % key
209
- evalue = IDENT_RE.sub("-", os.environ[key])
210
- lines = lines.replace(lines, evar, evalue)
211
-
212
- # Remove any keys with values that haven't been replaced.
213
- lines = lines.splitlines()
214
- for i in range(len(lines)):
215
- if lines[i].strip().startswith("<string>${"):
216
- lines[i] = None
217
- lines[i - 1] = None
218
- lines = "\n".join(line for line in lines if line is not None)
219
-
220
- # Write out the file with variables replaced.
221
- with open(dest, "w") as fd:
222
- fd.write(lines)
223
-
224
- # Now write out PkgInfo file now that the Info.plist file has been
225
- # "compiled".
226
- self._WritePkgInfo(dest)
227
-
228
- if convert_to_binary == "True":
229
- self._ConvertToBinary(dest)
230
-
231
- def _WritePkgInfo(self, info_plist):
232
- """This writes the PkgInfo file from the data stored in Info.plist."""
233
- plist = plistlib.readPlist(info_plist)
234
- if not plist:
235
- return
236
-
237
- # Only create PkgInfo for executable types.
238
- package_type = plist["CFBundlePackageType"]
239
- if package_type != "APPL":
240
- return
241
-
242
- # The format of PkgInfo is eight characters, representing the bundle type
243
- # and bundle signature, each four characters. If that is missing, four
244
- # '?' characters are used instead.
245
- signature_code = plist.get("CFBundleSignature", "????")
246
- if len(signature_code) != 4: # Wrong length resets everything, too.
247
- signature_code = "?" * 4
248
-
249
- dest = os.path.join(os.path.dirname(info_plist), "PkgInfo")
250
- with open(dest, "w") as fp:
251
- fp.write(f"{package_type}{signature_code}")
252
-
253
- def ExecFlock(self, lockfile, *cmd_list):
254
- """Emulates the most basic behavior of Linux's flock(1)."""
255
- # Rely on exception handling to report errors.
256
- fd = os.open(lockfile, os.O_RDONLY | os.O_NOCTTY | os.O_CREAT, 0o666)
257
- fcntl.flock(fd, fcntl.LOCK_EX)
258
- return subprocess.call(cmd_list)
259
-
260
- def ExecFilterLibtool(self, *cmd_list):
261
- """Calls libtool and filters out '/path/to/libtool: file: foo.o has no
262
- symbols'."""
263
- libtool_re = re.compile(
264
- r"^.*libtool: (?:for architecture: \S* )?" r"file: .* has no symbols$"
265
- )
266
- libtool_re5 = re.compile(
267
- r"^.*libtool: warning for library: "
268
- + r".* the table of contents is empty "
269
- + r"\(no object file members in the library define global symbols\)$"
270
- )
271
- env = os.environ.copy()
272
- # Ref:
273
- # http://www.opensource.apple.com/source/cctools/cctools-809/misc/libtool.c
274
- # The problem with this flag is that it resets the file mtime on the file to
275
- # epoch=0, e.g. 1970-1-1 or 1969-12-31 depending on timezone.
276
- env["ZERO_AR_DATE"] = "1"
277
- libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env)
278
- err = libtoolout.communicate()[1].decode("utf-8")
279
- for line in err.splitlines():
280
- if not libtool_re.match(line) and not libtool_re5.match(line):
281
- print(line, file=sys.stderr)
282
- # Unconditionally touch the output .a file on the command line if present
283
- # and the command succeeded. A bit hacky.
284
- if not libtoolout.returncode:
285
- for i in range(len(cmd_list) - 1):
286
- if cmd_list[i] == "-o" and cmd_list[i + 1].endswith(".a"):
287
- os.utime(cmd_list[i + 1], None)
288
- break
289
- return libtoolout.returncode
290
-
291
- def ExecPackageIosFramework(self, framework):
292
- # Find the name of the binary based on the part before the ".framework".
293
- binary = os.path.basename(framework).split(".")[0]
294
- module_path = os.path.join(framework, "Modules")
295
- if not os.path.exists(module_path):
296
- os.mkdir(module_path)
297
- module_template = (
298
- "framework module %s {\n"
299
- ' umbrella header "%s.h"\n'
300
- "\n"
301
- " export *\n"
302
- " module * { export * }\n"
303
- "}\n" % (binary, binary)
304
- )
305
-
306
- with open(os.path.join(module_path, "module.modulemap"), "w") as module_file:
307
- module_file.write(module_template)
308
-
309
- def ExecPackageFramework(self, framework, version):
310
- """Takes a path to Something.framework and the Current version of that and
311
- sets up all the symlinks."""
312
- # Find the name of the binary based on the part before the ".framework".
313
- binary = os.path.basename(framework).split(".")[0]
314
-
315
- CURRENT = "Current"
316
- RESOURCES = "Resources"
317
- VERSIONS = "Versions"
318
-
319
- if not os.path.exists(os.path.join(framework, VERSIONS, version, binary)):
320
- # Binary-less frameworks don't seem to contain symlinks (see e.g.
321
- # chromium's out/Debug/org.chromium.Chromium.manifest/ bundle).
322
- return
323
-
324
- # Move into the framework directory to set the symlinks correctly.
325
- pwd = os.getcwd()
326
- os.chdir(framework)
327
-
328
- # Set up the Current version.
329
- self._Relink(version, os.path.join(VERSIONS, CURRENT))
330
-
331
- # Set up the root symlinks.
332
- self._Relink(os.path.join(VERSIONS, CURRENT, binary), binary)
333
- self._Relink(os.path.join(VERSIONS, CURRENT, RESOURCES), RESOURCES)
334
-
335
- # Back to where we were before!
336
- os.chdir(pwd)
337
-
338
- def _Relink(self, dest, link):
339
- """Creates a symlink to |dest| named |link|. If |link| already exists,
340
- it is overwritten."""
341
- if os.path.lexists(link):
342
- os.remove(link)
343
- os.symlink(dest, link)
344
-
345
- def ExecCompileIosFrameworkHeaderMap(self, out, framework, *all_headers):
346
- framework_name = os.path.basename(framework).split(".")[0]
347
- all_headers = [os.path.abspath(header) for header in all_headers]
348
- filelist = {}
349
- for header in all_headers:
350
- filename = os.path.basename(header)
351
- filelist[filename] = header
352
- filelist[os.path.join(framework_name, filename)] = header
353
- WriteHmap(out, filelist)
354
-
355
- def ExecCopyIosFrameworkHeaders(self, framework, *copy_headers):
356
- header_path = os.path.join(framework, "Headers")
357
- if not os.path.exists(header_path):
358
- os.makedirs(header_path)
359
- for header in copy_headers:
360
- shutil.copy(header, os.path.join(header_path, os.path.basename(header)))
361
-
362
- def ExecCompileXcassets(self, keys, *inputs):
363
- """Compiles multiple .xcassets files into a single .car file.
364
-
365
- This invokes 'actool' to compile all the inputs .xcassets files. The
366
- |keys| arguments is a json-encoded dictionary of extra arguments to
367
- pass to 'actool' when the asset catalogs contains an application icon
368
- or a launch image.
369
-
370
- Note that 'actool' does not create the Assets.car file if the asset
371
- catalogs does not contains imageset.
372
- """
373
- command_line = [
374
- "xcrun",
375
- "actool",
376
- "--output-format",
377
- "human-readable-text",
378
- "--compress-pngs",
379
- "--notices",
380
- "--warnings",
381
- "--errors",
382
- ]
383
- is_iphone_target = "IPHONEOS_DEPLOYMENT_TARGET" in os.environ
384
- if is_iphone_target:
385
- platform = os.environ["CONFIGURATION"].split("-")[-1]
386
- if platform not in ("iphoneos", "iphonesimulator"):
387
- platform = "iphonesimulator"
388
- command_line.extend(
389
- [
390
- "--platform",
391
- platform,
392
- "--target-device",
393
- "iphone",
394
- "--target-device",
395
- "ipad",
396
- "--minimum-deployment-target",
397
- os.environ["IPHONEOS_DEPLOYMENT_TARGET"],
398
- "--compile",
399
- os.path.abspath(os.environ["CONTENTS_FOLDER_PATH"]),
400
- ]
401
- )
402
- else:
403
- command_line.extend(
404
- [
405
- "--platform",
406
- "macosx",
407
- "--target-device",
408
- "mac",
409
- "--minimum-deployment-target",
410
- os.environ["MACOSX_DEPLOYMENT_TARGET"],
411
- "--compile",
412
- os.path.abspath(os.environ["UNLOCALIZED_RESOURCES_FOLDER_PATH"]),
413
- ]
414
- )
415
- if keys:
416
- keys = json.loads(keys)
417
- for key, value in keys.items():
418
- arg_name = "--" + key
419
- if isinstance(value, bool):
420
- if value:
421
- command_line.append(arg_name)
422
- elif isinstance(value, list):
423
- for v in value:
424
- command_line.append(arg_name)
425
- command_line.append(str(v))
426
- else:
427
- command_line.append(arg_name)
428
- command_line.append(str(value))
429
- # Note: actool crashes if inputs path are relative, so use os.path.abspath
430
- # to get absolute path name for inputs.
431
- command_line.extend(map(os.path.abspath, inputs))
432
- subprocess.check_call(command_line)
433
-
434
- def ExecMergeInfoPlist(self, output, *inputs):
435
- """Merge multiple .plist files into a single .plist file."""
436
- merged_plist = {}
437
- for path in inputs:
438
- plist = self._LoadPlistMaybeBinary(path)
439
- self._MergePlist(merged_plist, plist)
440
- plistlib.writePlist(merged_plist, output)
441
-
442
- def ExecCodeSignBundle(self, key, entitlements, provisioning, path, preserve):
443
- """Code sign a bundle.
444
-
445
- This function tries to code sign an iOS bundle, following the same
446
- algorithm as Xcode:
447
- 1. pick the provisioning profile that best match the bundle identifier,
448
- and copy it into the bundle as embedded.mobileprovision,
449
- 2. copy Entitlements.plist from user or SDK next to the bundle,
450
- 3. code sign the bundle.
451
- """
452
- substitutions, overrides = self._InstallProvisioningProfile(
453
- provisioning, self._GetCFBundleIdentifier()
454
- )
455
- entitlements_path = self._InstallEntitlements(
456
- entitlements, substitutions, overrides
457
- )
458
-
459
- args = ["codesign", "--force", "--sign", key]
460
- if preserve == "True":
461
- args.extend(["--deep", "--preserve-metadata=identifier,entitlements"])
462
- else:
463
- args.extend(["--entitlements", entitlements_path])
464
- args.extend(["--timestamp=none", path])
465
- subprocess.check_call(args)
466
-
467
- def _InstallProvisioningProfile(self, profile, bundle_identifier):
468
- """Installs embedded.mobileprovision into the bundle.
469
-
470
- Args:
471
- profile: string, optional, short name of the .mobileprovision file
472
- to use, if empty or the file is missing, the best file installed
473
- will be used
474
- bundle_identifier: string, value of CFBundleIdentifier from Info.plist
475
-
476
- Returns:
477
- A tuple containing two dictionary: variables substitutions and values
478
- to overrides when generating the entitlements file.
479
- """
480
- source_path, provisioning_data, team_id = self._FindProvisioningProfile(
481
- profile, bundle_identifier
482
- )
483
- target_path = os.path.join(
484
- os.environ["BUILT_PRODUCTS_DIR"],
485
- os.environ["CONTENTS_FOLDER_PATH"],
486
- "embedded.mobileprovision",
487
- )
488
- shutil.copy2(source_path, target_path)
489
- substitutions = self._GetSubstitutions(bundle_identifier, team_id + ".")
490
- return substitutions, provisioning_data["Entitlements"]
491
-
492
- def _FindProvisioningProfile(self, profile, bundle_identifier):
493
- """Finds the .mobileprovision file to use for signing the bundle.
494
-
495
- Checks all the installed provisioning profiles (or if the user specified
496
- the PROVISIONING_PROFILE variable, only consult it) and select the most
497
- specific that correspond to the bundle identifier.
498
-
499
- Args:
500
- profile: string, optional, short name of the .mobileprovision file
501
- to use, if empty or the file is missing, the best file installed
502
- will be used
503
- bundle_identifier: string, value of CFBundleIdentifier from Info.plist
504
-
505
- Returns:
506
- A tuple of the path to the selected provisioning profile, the data of
507
- the embedded plist in the provisioning profile and the team identifier
508
- to use for code signing.
509
-
510
- Raises:
511
- SystemExit: if no .mobileprovision can be used to sign the bundle.
512
- """
513
- profiles_dir = os.path.join(
514
- os.environ["HOME"], "Library", "MobileDevice", "Provisioning Profiles"
515
- )
516
- if not os.path.isdir(profiles_dir):
517
- print(
518
- "cannot find mobile provisioning for %s" % (bundle_identifier),
519
- file=sys.stderr,
520
- )
521
- sys.exit(1)
522
- provisioning_profiles = None
523
- if profile:
524
- profile_path = os.path.join(profiles_dir, profile + ".mobileprovision")
525
- if os.path.exists(profile_path):
526
- provisioning_profiles = [profile_path]
527
- if not provisioning_profiles:
528
- provisioning_profiles = glob.glob(
529
- os.path.join(profiles_dir, "*.mobileprovision")
530
- )
531
- valid_provisioning_profiles = {}
532
- for profile_path in provisioning_profiles:
533
- profile_data = self._LoadProvisioningProfile(profile_path)
534
- app_id_pattern = profile_data.get("Entitlements", {}).get(
535
- "application-identifier", ""
536
- )
537
- for team_identifier in profile_data.get("TeamIdentifier", []):
538
- app_id = f"{team_identifier}.{bundle_identifier}"
539
- if fnmatch.fnmatch(app_id, app_id_pattern):
540
- valid_provisioning_profiles[app_id_pattern] = (
541
- profile_path,
542
- profile_data,
543
- team_identifier,
544
- )
545
- if not valid_provisioning_profiles:
546
- print(
547
- "cannot find mobile provisioning for %s" % (bundle_identifier),
548
- file=sys.stderr,
549
- )
550
- sys.exit(1)
551
- # If the user has multiple provisioning profiles installed that can be
552
- # used for ${bundle_identifier}, pick the most specific one (ie. the
553
- # provisioning profile whose pattern is the longest).
554
- selected_key = max(valid_provisioning_profiles, key=lambda v: len(v))
555
- return valid_provisioning_profiles[selected_key]
556
-
557
- def _LoadProvisioningProfile(self, profile_path):
558
- """Extracts the plist embedded in a provisioning profile.
559
-
560
- Args:
561
- profile_path: string, path to the .mobileprovision file
562
-
563
- Returns:
564
- Content of the plist embedded in the provisioning profile as a dictionary.
565
- """
566
- with tempfile.NamedTemporaryFile() as temp:
567
- subprocess.check_call(
568
- ["security", "cms", "-D", "-i", profile_path, "-o", temp.name]
569
- )
570
- return self._LoadPlistMaybeBinary(temp.name)
571
-
572
- def _MergePlist(self, merged_plist, plist):
573
- """Merge |plist| into |merged_plist|."""
574
- for key, value in plist.items():
575
- if isinstance(value, dict):
576
- merged_value = merged_plist.get(key, {})
577
- if isinstance(merged_value, dict):
578
- self._MergePlist(merged_value, value)
579
- merged_plist[key] = merged_value
580
- else:
581
- merged_plist[key] = value
582
- else:
583
- merged_plist[key] = value
584
-
585
- def _LoadPlistMaybeBinary(self, plist_path):
586
- """Loads into a memory a plist possibly encoded in binary format.
587
-
588
- This is a wrapper around plistlib.readPlist that tries to convert the
589
- plist to the XML format if it can't be parsed (assuming that it is in
590
- the binary format).
591
-
592
- Args:
593
- plist_path: string, path to a plist file, in XML or binary format
594
-
595
- Returns:
596
- Content of the plist as a dictionary.
597
- """
598
- try:
599
- # First, try to read the file using plistlib that only supports XML,
600
- # and if an exception is raised, convert a temporary copy to XML and
601
- # load that copy.
602
- return plistlib.readPlist(plist_path)
603
- except Exception:
604
- pass
605
- with tempfile.NamedTemporaryFile() as temp:
606
- shutil.copy2(plist_path, temp.name)
607
- subprocess.check_call(["plutil", "-convert", "xml1", temp.name])
608
- return plistlib.readPlist(temp.name)
609
-
610
- def _GetSubstitutions(self, bundle_identifier, app_identifier_prefix):
611
- """Constructs a dictionary of variable substitutions for Entitlements.plist.
612
-
613
- Args:
614
- bundle_identifier: string, value of CFBundleIdentifier from Info.plist
615
- app_identifier_prefix: string, value for AppIdentifierPrefix
616
-
617
- Returns:
618
- Dictionary of substitutions to apply when generating Entitlements.plist.
619
- """
620
- return {
621
- "CFBundleIdentifier": bundle_identifier,
622
- "AppIdentifierPrefix": app_identifier_prefix,
623
- }
624
-
625
- def _GetCFBundleIdentifier(self):
626
- """Extracts CFBundleIdentifier value from Info.plist in the bundle.
627
-
628
- Returns:
629
- Value of CFBundleIdentifier in the Info.plist located in the bundle.
630
- """
631
- info_plist_path = os.path.join(
632
- os.environ["TARGET_BUILD_DIR"], os.environ["INFOPLIST_PATH"]
633
- )
634
- info_plist_data = self._LoadPlistMaybeBinary(info_plist_path)
635
- return info_plist_data["CFBundleIdentifier"]
636
-
637
- def _InstallEntitlements(self, entitlements, substitutions, overrides):
638
- """Generates and install the ${BundleName}.xcent entitlements file.
639
-
640
- Expands variables "$(variable)" pattern in the source entitlements file,
641
- add extra entitlements defined in the .mobileprovision file and the copy
642
- the generated plist to "${BundlePath}.xcent".
643
-
644
- Args:
645
- entitlements: string, optional, path to the Entitlements.plist template
646
- to use, defaults to "${SDKROOT}/Entitlements.plist"
647
- substitutions: dictionary, variable substitutions
648
- overrides: dictionary, values to add to the entitlements
649
-
650
- Returns:
651
- Path to the generated entitlements file.
652
- """
653
- source_path = entitlements
654
- target_path = os.path.join(
655
- os.environ["BUILT_PRODUCTS_DIR"], os.environ["PRODUCT_NAME"] + ".xcent"
656
- )
657
- if not source_path:
658
- source_path = os.path.join(os.environ["SDKROOT"], "Entitlements.plist")
659
- shutil.copy2(source_path, target_path)
660
- data = self._LoadPlistMaybeBinary(target_path)
661
- data = self._ExpandVariables(data, substitutions)
662
- if overrides:
663
- for key in overrides:
664
- if key not in data:
665
- data[key] = overrides[key]
666
- plistlib.writePlist(data, target_path)
667
- return target_path
668
-
669
- def _ExpandVariables(self, data, substitutions):
670
- """Expands variables "$(variable)" in data.
671
-
672
- Args:
673
- data: object, can be either string, list or dictionary
674
- substitutions: dictionary, variable substitutions to perform
675
-
676
- Returns:
677
- Copy of data where each references to "$(variable)" has been replaced
678
- by the corresponding value found in substitutions, or left intact if
679
- the key was not found.
680
- """
681
- if isinstance(data, str):
682
- for key, value in substitutions.items():
683
- data = data.replace("$(%s)" % key, value)
684
- return data
685
- if isinstance(data, list):
686
- return [self._ExpandVariables(v, substitutions) for v in data]
687
- if isinstance(data, dict):
688
- return {k: self._ExpandVariables(data[k], substitutions) for k in data}
689
- return data
690
-
691
-
692
- def NextGreaterPowerOf2(x):
693
- return 2 ** (x).bit_length()
694
-
695
-
696
- def WriteHmap(output_name, filelist):
697
- """Generates a header map based on |filelist|.
698
-
699
- Per Mark Mentovai:
700
- A header map is structured essentially as a hash table, keyed by names used
701
- in #includes, and providing pathnames to the actual files.
702
-
703
- The implementation below and the comment above comes from inspecting:
704
- http://www.opensource.apple.com/source/distcc/distcc-2503/distcc_dist/include_server/headermap.py?txt
705
- while also looking at the implementation in clang in:
706
- https://llvm.org/svn/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp
707
- """
708
- magic = 1751998832
709
- version = 1
710
- _reserved = 0
711
- count = len(filelist)
712
- capacity = NextGreaterPowerOf2(count)
713
- strings_offset = 24 + (12 * capacity)
714
- max_value_length = max(len(value) for value in filelist.values())
715
-
716
- out = open(output_name, "wb")
717
- out.write(
718
- struct.pack(
719
- "<LHHLLLL",
720
- magic,
721
- version,
722
- _reserved,
723
- strings_offset,
724
- count,
725
- capacity,
726
- max_value_length,
727
- )
728
- )
729
-
730
- # Create empty hashmap buckets.
731
- buckets = [None] * capacity
732
- for file, path in filelist.items():
733
- key = 0
734
- for c in file:
735
- key += ord(c.lower()) * 13
736
-
737
- # Fill next empty bucket.
738
- while buckets[key & capacity - 1] is not None:
739
- key = key + 1
740
- buckets[key & capacity - 1] = (file, path)
741
-
742
- next_offset = 1
743
- for bucket in buckets:
744
- if bucket is None:
745
- out.write(struct.pack("<LLL", 0, 0, 0))
746
- else:
747
- (file, path) = bucket
748
- key_offset = next_offset
749
- prefix_offset = key_offset + len(file) + 1
750
- suffix_offset = prefix_offset + len(os.path.dirname(path) + os.sep) + 1
751
- next_offset = suffix_offset + len(os.path.basename(path)) + 1
752
- out.write(struct.pack("<LLL", key_offset, prefix_offset, suffix_offset))
753
-
754
- # Pad byte since next offset starts at 1.
755
- out.write(struct.pack("<x"))
756
-
757
- for bucket in buckets:
758
- if bucket is not None:
759
- (file, path) = bucket
760
- out.write(struct.pack("<%ds" % len(file), file))
761
- out.write(struct.pack("<s", "\0"))
762
- base = os.path.dirname(path) + os.sep
763
- out.write(struct.pack("<%ds" % len(base), base))
764
- out.write(struct.pack("<s", "\0"))
765
- path = os.path.basename(path)
766
- out.write(struct.pack("<%ds" % len(path), path))
767
- out.write(struct.pack("<s", "\0"))
768
-
769
-
770
- if __name__ == "__main__":
771
- sys.exit(main(sys.argv[1:]))