@btc-vision/bitcoin 6.4.10 → 6.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/.babelrc +4 -4
  2. package/.mocharc.json +13 -13
  3. package/.prettierrc.json +12 -12
  4. package/CHANGELOG.md +403 -403
  5. package/CONTRIBUTING.md +83 -83
  6. package/LICENSE +21 -21
  7. package/README.md +201 -201
  8. package/cjs/package.json +3 -3
  9. package/gulpfile.js +42 -42
  10. package/package.json +150 -150
  11. package/src/bip66.ts +107 -107
  12. package/src/block.ts +233 -233
  13. package/src/bufferutils.ts +188 -188
  14. package/src/crypto.ts +108 -108
  15. package/src/ecc_lib.ts +94 -94
  16. package/src/hooks/AdvancedSignatureManager.ts +104 -104
  17. package/src/hooks/SignatureManager.ts +84 -84
  18. package/src/index.ts +105 -105
  19. package/src/merkle.ts +31 -31
  20. package/src/opcodes.ts +280 -280
  21. package/src/payments/bip341.ts +140 -140
  22. package/src/payments/embed.ts +61 -61
  23. package/src/payments/index.ts +172 -172
  24. package/src/payments/lazy.ts +28 -28
  25. package/src/payments/p2ms.ts +156 -156
  26. package/src/payments/p2op.ts +195 -195
  27. package/src/payments/p2pk.ts +93 -93
  28. package/src/payments/p2pkh.ts +214 -214
  29. package/src/payments/p2tr.ts +309 -309
  30. package/src/psbt/bip371.ts +441 -441
  31. package/src/push_data.ts +97 -97
  32. package/src/script.ts +247 -247
  33. package/src/script_number.ts +72 -72
  34. package/src/script_signature.ts +91 -91
  35. package/src/transaction.ts +656 -656
  36. package/test/address.spec.ts +155 -155
  37. package/test/bitcoin.core.spec.ts +212 -212
  38. package/test/block.spec.ts +171 -171
  39. package/test/bufferutils.spec.ts +450 -450
  40. package/test/crypto.spec.ts +49 -49
  41. package/test/fixtures/address.json +329 -329
  42. package/test/fixtures/block.json +148 -148
  43. package/test/fixtures/bufferutils.json +102 -102
  44. package/test/fixtures/core/README.md +26 -26
  45. package/test/fixtures/core/base58_encode_decode.json +50 -50
  46. package/test/fixtures/core/base58_keys_invalid.json +152 -152
  47. package/test/fixtures/core/base58_keys_valid.json +452 -452
  48. package/test/fixtures/core/blocks.json +27 -27
  49. package/test/fixtures/core/sig_canonical.json +7 -7
  50. package/test/fixtures/core/sig_noncanonical.json +33 -33
  51. package/test/fixtures/core/sighash.json +3505 -3505
  52. package/test/fixtures/core/tx_valid.json +2023 -2023
  53. package/test/fixtures/crypto.json +43 -43
  54. package/test/fixtures/ecdsa.json +217 -217
  55. package/test/fixtures/ecpair.json +141 -141
  56. package/test/fixtures/embed.json +108 -108
  57. package/test/fixtures/p2ms.json +434 -434
  58. package/test/fixtures/p2pk.json +179 -179
  59. package/test/fixtures/p2pkh.json +276 -276
  60. package/test/fixtures/p2sh.json +508 -508
  61. package/test/fixtures/p2tr.json +1198 -1198
  62. package/test/fixtures/p2wpkh.json +290 -290
  63. package/test/fixtures/p2wsh.json +489 -489
  64. package/test/fixtures/psbt.json +924 -924
  65. package/test/fixtures/script.json +465 -465
  66. package/test/fixtures/script_number.json +225 -225
  67. package/test/fixtures/signature.json +140 -140
  68. package/test/fixtures/transaction.json +916 -916
  69. package/test/integration/_regtest.ts +6 -6
  70. package/test/integration/addresses.spec.ts +142 -142
  71. package/test/integration/bip32.spec.ts +130 -130
  72. package/test/integration/blocks.spec.ts +28 -28
  73. package/test/integration/cltv.spec.ts +241 -241
  74. package/test/integration/csv.spec.ts +452 -452
  75. package/test/integration/payments.spec.ts +110 -110
  76. package/test/integration/taproot.spec.ts +663 -663
  77. package/test/integration/transactions.spec.ts +668 -668
  78. package/test/payments.spec.ts +114 -114
  79. package/test/payments.utils.ts +165 -165
  80. package/test/psbt.spec.ts +1285 -1285
  81. package/test/script.spec.ts +186 -186
  82. package/test/script_number.spec.ts +26 -26
  83. package/test/script_signature.spec.ts +66 -66
  84. package/test/transaction.spec.ts +337 -337
  85. package/test/ts-node-register.js +7 -7
  86. package/test/tsconfig.json +48 -48
  87. package/test/types.spec.ts +53 -53
  88. package/tsconfig.base.json +27 -27
  89. package/tsconfig.json +19 -19
  90. package/tsconfig.webpack.json +18 -18
  91. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.ready +0 -0
  92. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.release-please-manifest.json +0 -3
  93. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CHANGELOG.md +0 -962
  94. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CONTRIBUTING.md +0 -34
  95. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/LICENSE +0 -24
  96. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/README.md +0 -273
  97. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/SECURITY.md +0 -2
  98. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/addon.gypi +0 -204
  99. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/bin/node-gyp.js +0 -138
  100. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/.release-please-manifest.json +0 -3
  101. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/LICENSE +0 -28
  102. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/ninja/build.ninja +0 -4
  103. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +0 -12
  104. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/GypVsCMake.md +0 -116
  105. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Hacking.md +0 -46
  106. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/InputFormatReference.md +0 -1080
  107. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/LanguageSpecification.md +0 -430
  108. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/README.md +0 -27
  109. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Testing.md +0 -450
  110. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/UserDocumentation.md +0 -965
  111. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp +0 -8
  112. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp.bat +0 -5
  113. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp_main.py +0 -45
  114. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +0 -365
  115. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +0 -206
  116. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +0 -1272
  117. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +0 -1547
  118. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +0 -59
  119. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +0 -153
  120. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +0 -271
  121. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +0 -574
  122. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +0 -692
  123. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common.py +0 -711
  124. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +0 -171
  125. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +0 -169
  126. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +0 -113
  127. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +0 -55
  128. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  129. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +0 -804
  130. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +0 -1173
  131. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +0 -1318
  132. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +0 -127
  133. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +0 -103
  134. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +0 -461
  135. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +0 -89
  136. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +0 -57
  137. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +0 -2745
  138. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +0 -3976
  139. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +0 -44
  140. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +0 -2964
  141. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +0 -67
  142. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +0 -1391
  143. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +0 -25
  144. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input.py +0 -3115
  145. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +0 -98
  146. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +0 -771
  147. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +0 -1260
  148. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +0 -174
  149. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +0 -61
  150. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +0 -373
  151. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +0 -1938
  152. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +0 -53
  153. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +0 -302
  154. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +0 -3198
  155. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +0 -65
  156. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +0 -3
  157. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +0 -177
  158. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +0 -23
  159. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +0 -15
  160. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +0 -108
  161. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +0 -252
  162. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +0 -83
  163. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +0 -359
  164. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +0 -61
  165. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +0 -192
  166. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/markers.py +0 -252
  167. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +0 -825
  168. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  169. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +0 -90
  170. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +0 -1030
  171. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/tags.py +0 -553
  172. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/utils.py +0 -172
  173. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/version.py +0 -563
  174. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pyproject.toml +0 -120
  175. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/release-please-config.json +0 -11
  176. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/test_gyp.py +0 -261
  177. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/Find-VisualStudio.cs +0 -250
  178. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/build.js +0 -227
  179. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/clean.js +0 -15
  180. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/configure.js +0 -328
  181. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/create-config-gypi.js +0 -150
  182. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/download.js +0 -39
  183. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-node-directory.js +0 -63
  184. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-python.js +0 -310
  185. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-visualstudio.js +0 -590
  186. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/install.js +0 -415
  187. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/list.js +0 -26
  188. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/log.js +0 -168
  189. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/node-gyp.js +0 -188
  190. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/process-release.js +0 -146
  191. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/rebuild.js +0 -12
  192. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/remove.js +0 -43
  193. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/util.js +0 -81
  194. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/macOS_Catalina_acid_test.sh +0 -21
  195. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/package.json +0 -51
  196. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/release-please-config.json +0 -40
  197. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/src/win_delay_load_hook.cc +0 -39
  198. package/browser/ops.d.ts +0 -126
  199. package/build/ops.d.ts +0 -126
  200. package/build/ops.js +0 -127
  201. package/coverage/tmp/coverage-31752-1735543485354-0.json +0 -1
  202. package/coverage/tmp/coverage-59920-1735543484555-0.json +0 -1
  203. package/coverage/tmp/coverage-66252-1735543483919-0.json +0 -1
  204. package/coverage/tmp/coverage-68440-1735543485236-0.json +0 -1
  205. package/coverage/tmp/coverage-70588-1735543484426-0.json +0 -1
  206. package/coverage/tmp/coverage-79292-1735543485296-0.json +0 -1
  207. package/coverage/tmp/coverage-80212-1735543483980-0.json +0 -1
@@ -1,711 +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
- import errno
6
- import filecmp
7
- import os.path
8
- import re
9
- import tempfile
10
- import sys
11
- import subprocess
12
- import shlex
13
-
14
- from collections.abc import MutableSet
15
-
16
-
17
- # A minimal memoizing decorator. It'll blow up if the args aren't immutable,
18
- # among other "problems".
19
- class memoize:
20
- def __init__(self, func):
21
- self.func = func
22
- self.cache = {}
23
-
24
- def __call__(self, *args):
25
- try:
26
- return self.cache[args]
27
- except KeyError:
28
- result = self.func(*args)
29
- self.cache[args] = result
30
- return result
31
-
32
-
33
- class GypError(Exception):
34
- """Error class representing an error, which is to be presented
35
- to the user. The main entry point will catch and display this.
36
- """
37
-
38
- pass
39
-
40
-
41
- def ExceptionAppend(e, msg):
42
- """Append a message to the given exception's message."""
43
- if not e.args:
44
- e.args = (msg,)
45
- elif len(e.args) == 1:
46
- e.args = (str(e.args[0]) + " " + msg,)
47
- else:
48
- e.args = (str(e.args[0]) + " " + msg,) + e.args[1:]
49
-
50
-
51
- def FindQualifiedTargets(target, qualified_list):
52
- """
53
- Given a list of qualified targets, return the qualified targets for the
54
- specified |target|.
55
- """
56
- return [t for t in qualified_list if ParseQualifiedTarget(t)[1] == target]
57
-
58
-
59
- def ParseQualifiedTarget(target):
60
- # Splits a qualified target into a build file, target name and toolset.
61
-
62
- # NOTE: rsplit is used to disambiguate the Windows drive letter separator.
63
- target_split = target.rsplit(":", 1)
64
- if len(target_split) == 2:
65
- [build_file, target] = target_split
66
- else:
67
- build_file = None
68
-
69
- target_split = target.rsplit("#", 1)
70
- if len(target_split) == 2:
71
- [target, toolset] = target_split
72
- else:
73
- toolset = None
74
-
75
- return [build_file, target, toolset]
76
-
77
-
78
- def ResolveTarget(build_file, target, toolset):
79
- # This function resolves a target into a canonical form:
80
- # - a fully defined build file, either absolute or relative to the current
81
- # directory
82
- # - a target name
83
- # - a toolset
84
- #
85
- # build_file is the file relative to which 'target' is defined.
86
- # target is the qualified target.
87
- # toolset is the default toolset for that target.
88
- [parsed_build_file, target, parsed_toolset] = ParseQualifiedTarget(target)
89
-
90
- if parsed_build_file:
91
- if build_file:
92
- # If a relative path, parsed_build_file is relative to the directory
93
- # containing build_file. If build_file is not in the current directory,
94
- # parsed_build_file is not a usable path as-is. Resolve it by
95
- # interpreting it as relative to build_file. If parsed_build_file is
96
- # absolute, it is usable as a path regardless of the current directory,
97
- # and os.path.join will return it as-is.
98
- build_file = os.path.normpath(
99
- os.path.join(os.path.dirname(build_file), parsed_build_file)
100
- )
101
- # Further (to handle cases like ../cwd), make it relative to cwd)
102
- if not os.path.isabs(build_file):
103
- build_file = RelativePath(build_file, ".")
104
- else:
105
- build_file = parsed_build_file
106
-
107
- if parsed_toolset:
108
- toolset = parsed_toolset
109
-
110
- return [build_file, target, toolset]
111
-
112
-
113
- def BuildFile(fully_qualified_target):
114
- # Extracts the build file from the fully qualified target.
115
- return ParseQualifiedTarget(fully_qualified_target)[0]
116
-
117
-
118
- def GetEnvironFallback(var_list, default):
119
- """Look up a key in the environment, with fallback to secondary keys
120
- and finally falling back to a default value."""
121
- for var in var_list:
122
- if var in os.environ:
123
- return os.environ[var]
124
- return default
125
-
126
-
127
- def QualifiedTarget(build_file, target, toolset):
128
- # "Qualified" means the file that a target was defined in and the target
129
- # name, separated by a colon, suffixed by a # and the toolset name:
130
- # /path/to/file.gyp:target_name#toolset
131
- fully_qualified = build_file + ":" + target
132
- if toolset:
133
- fully_qualified = fully_qualified + "#" + toolset
134
- return fully_qualified
135
-
136
-
137
- @memoize
138
- def RelativePath(path, relative_to, follow_path_symlink=True):
139
- # Assuming both |path| and |relative_to| are relative to the current
140
- # directory, returns a relative path that identifies path relative to
141
- # relative_to.
142
- # If |follow_symlink_path| is true (default) and |path| is a symlink, then
143
- # this method returns a path to the real file represented by |path|. If it is
144
- # false, this method returns a path to the symlink. If |path| is not a
145
- # symlink, this option has no effect.
146
-
147
- # Convert to normalized (and therefore absolute paths).
148
- path = os.path.realpath(path) if follow_path_symlink else os.path.abspath(path)
149
- relative_to = os.path.realpath(relative_to)
150
-
151
- # On Windows, we can't create a relative path to a different drive, so just
152
- # use the absolute path.
153
- if sys.platform == "win32" and (
154
- os.path.splitdrive(path)[0].lower()
155
- != os.path.splitdrive(relative_to)[0].lower()
156
- ):
157
- return path
158
-
159
- # Split the paths into components.
160
- path_split = path.split(os.path.sep)
161
- relative_to_split = relative_to.split(os.path.sep)
162
-
163
- # Determine how much of the prefix the two paths share.
164
- prefix_len = len(os.path.commonprefix([path_split, relative_to_split]))
165
-
166
- # Put enough ".." components to back up out of relative_to to the common
167
- # prefix, and then append the part of path_split after the common prefix.
168
- relative_split = [os.path.pardir] * (
169
- len(relative_to_split) - prefix_len
170
- ) + path_split[prefix_len:]
171
-
172
- if len(relative_split) == 0:
173
- # The paths were the same.
174
- return ""
175
-
176
- # Turn it back into a string and we're done.
177
- return os.path.join(*relative_split)
178
-
179
-
180
- @memoize
181
- def InvertRelativePath(path, toplevel_dir=None):
182
- """Given a path like foo/bar that is relative to toplevel_dir, return
183
- the inverse relative path back to the toplevel_dir.
184
-
185
- E.g. os.path.normpath(os.path.join(path, InvertRelativePath(path)))
186
- should always produce the empty string, unless the path contains symlinks.
187
- """
188
- if not path:
189
- return path
190
- toplevel_dir = "." if toplevel_dir is None else toplevel_dir
191
- return RelativePath(toplevel_dir, os.path.join(toplevel_dir, path))
192
-
193
-
194
- def FixIfRelativePath(path, relative_to):
195
- # Like RelativePath but returns |path| unchanged if it is absolute.
196
- if os.path.isabs(path):
197
- return path
198
- return RelativePath(path, relative_to)
199
-
200
-
201
- def UnrelativePath(path, relative_to):
202
- # Assuming that |relative_to| is relative to the current directory, and |path|
203
- # is a path relative to the dirname of |relative_to|, returns a path that
204
- # identifies |path| relative to the current directory.
205
- rel_dir = os.path.dirname(relative_to)
206
- return os.path.normpath(os.path.join(rel_dir, path))
207
-
208
-
209
- # re objects used by EncodePOSIXShellArgument. See IEEE 1003.1 XCU.2.2 at
210
- # http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02
211
- # and the documentation for various shells.
212
-
213
- # _quote is a pattern that should match any argument that needs to be quoted
214
- # with double-quotes by EncodePOSIXShellArgument. It matches the following
215
- # characters appearing anywhere in an argument:
216
- # \t, \n, space parameter separators
217
- # # comments
218
- # $ expansions (quoted to always expand within one argument)
219
- # % called out by IEEE 1003.1 XCU.2.2
220
- # & job control
221
- # ' quoting
222
- # (, ) subshell execution
223
- # *, ?, [ pathname expansion
224
- # ; command delimiter
225
- # <, >, | redirection
226
- # = assignment
227
- # {, } brace expansion (bash)
228
- # ~ tilde expansion
229
- # It also matches the empty string, because "" (or '') is the only way to
230
- # represent an empty string literal argument to a POSIX shell.
231
- #
232
- # This does not match the characters in _escape, because those need to be
233
- # backslash-escaped regardless of whether they appear in a double-quoted
234
- # string.
235
- _quote = re.compile("[\t\n #$%&'()*;<=>?[{|}~]|^$")
236
-
237
- # _escape is a pattern that should match any character that needs to be
238
- # escaped with a backslash, whether or not the argument matched the _quote
239
- # pattern. _escape is used with re.sub to backslash anything in _escape's
240
- # first match group, hence the (parentheses) in the regular expression.
241
- #
242
- # _escape matches the following characters appearing anywhere in an argument:
243
- # " to prevent POSIX shells from interpreting this character for quoting
244
- # \ to prevent POSIX shells from interpreting this character for escaping
245
- # ` to prevent POSIX shells from interpreting this character for command
246
- # substitution
247
- # Missing from this list is $, because the desired behavior of
248
- # EncodePOSIXShellArgument is to permit parameter (variable) expansion.
249
- #
250
- # Also missing from this list is !, which bash will interpret as the history
251
- # expansion character when history is enabled. bash does not enable history
252
- # by default in non-interactive shells, so this is not thought to be a problem.
253
- # ! was omitted from this list because bash interprets "\!" as a literal string
254
- # including the backslash character (avoiding history expansion but retaining
255
- # the backslash), which would not be correct for argument encoding. Handling
256
- # this case properly would also be problematic because bash allows the history
257
- # character to be changed with the histchars shell variable. Fortunately,
258
- # as history is not enabled in non-interactive shells and
259
- # EncodePOSIXShellArgument is only expected to encode for non-interactive
260
- # shells, there is no room for error here by ignoring !.
261
- _escape = re.compile(r'(["\\`])')
262
-
263
-
264
- def EncodePOSIXShellArgument(argument):
265
- """Encodes |argument| suitably for consumption by POSIX shells.
266
-
267
- argument may be quoted and escaped as necessary to ensure that POSIX shells
268
- treat the returned value as a literal representing the argument passed to
269
- this function. Parameter (variable) expansions beginning with $ are allowed
270
- to remain intact without escaping the $, to allow the argument to contain
271
- references to variables to be expanded by the shell.
272
- """
273
-
274
- if not isinstance(argument, str):
275
- argument = str(argument)
276
-
277
- quote = '"' if _quote.search(argument) else ""
278
-
279
- encoded = quote + re.sub(_escape, r"\\\1", argument) + quote
280
-
281
- return encoded
282
-
283
-
284
- def EncodePOSIXShellList(list):
285
- """Encodes |list| suitably for consumption by POSIX shells.
286
-
287
- Returns EncodePOSIXShellArgument for each item in list, and joins them
288
- together using the space character as an argument separator.
289
- """
290
-
291
- encoded_arguments = []
292
- for argument in list:
293
- encoded_arguments.append(EncodePOSIXShellArgument(argument))
294
- return " ".join(encoded_arguments)
295
-
296
-
297
- def DeepDependencyTargets(target_dicts, roots):
298
- """Returns the recursive list of target dependencies."""
299
- dependencies = set()
300
- pending = set(roots)
301
- while pending:
302
- # Pluck out one.
303
- r = pending.pop()
304
- # Skip if visited already.
305
- if r in dependencies:
306
- continue
307
- # Add it.
308
- dependencies.add(r)
309
- # Add its children.
310
- spec = target_dicts[r]
311
- pending.update(set(spec.get("dependencies", [])))
312
- pending.update(set(spec.get("dependencies_original", [])))
313
- return list(dependencies - set(roots))
314
-
315
-
316
- def BuildFileTargets(target_list, build_file):
317
- """From a target_list, returns the subset from the specified build_file.
318
- """
319
- return [p for p in target_list if BuildFile(p) == build_file]
320
-
321
-
322
- def AllTargets(target_list, target_dicts, build_file):
323
- """Returns all targets (direct and dependencies) for the specified build_file.
324
- """
325
- bftargets = BuildFileTargets(target_list, build_file)
326
- deptargets = DeepDependencyTargets(target_dicts, bftargets)
327
- return bftargets + deptargets
328
-
329
-
330
- def WriteOnDiff(filename):
331
- """Write to a file only if the new contents differ.
332
-
333
- Arguments:
334
- filename: name of the file to potentially write to.
335
- Returns:
336
- A file like object which will write to temporary file and only overwrite
337
- the target if it differs (on close).
338
- """
339
-
340
- class Writer:
341
- """Wrapper around file which only covers the target if it differs."""
342
-
343
- def __init__(self):
344
- # On Cygwin remove the "dir" argument
345
- # `C:` prefixed paths are treated as relative,
346
- # consequently ending up with current dir "/cygdrive/c/..."
347
- # being prefixed to those, which was
348
- # obviously a non-existent path,
349
- # for example: "/cygdrive/c/<some folder>/C:\<my win style abs path>".
350
- # For more details see:
351
- # https://docs.python.org/2/library/tempfile.html#tempfile.mkstemp
352
- base_temp_dir = "" if IsCygwin() else os.path.dirname(filename)
353
- # Pick temporary file.
354
- tmp_fd, self.tmp_path = tempfile.mkstemp(
355
- suffix=".tmp",
356
- prefix=os.path.split(filename)[1] + ".gyp.",
357
- dir=base_temp_dir,
358
- )
359
- try:
360
- self.tmp_file = os.fdopen(tmp_fd, "wb")
361
- except Exception:
362
- # Don't leave turds behind.
363
- os.unlink(self.tmp_path)
364
- raise
365
-
366
- def __getattr__(self, attrname):
367
- # Delegate everything else to self.tmp_file
368
- return getattr(self.tmp_file, attrname)
369
-
370
- def close(self):
371
- try:
372
- # Close tmp file.
373
- self.tmp_file.close()
374
- # Determine if different.
375
- same = False
376
- try:
377
- same = filecmp.cmp(self.tmp_path, filename, False)
378
- except OSError as e:
379
- if e.errno != errno.ENOENT:
380
- raise
381
-
382
- if same:
383
- # The new file is identical to the old one, just get rid of the new
384
- # one.
385
- os.unlink(self.tmp_path)
386
- else:
387
- # The new file is different from the old one,
388
- # or there is no old one.
389
- # Rename the new file to the permanent name.
390
- #
391
- # tempfile.mkstemp uses an overly restrictive mode, resulting in a
392
- # file that can only be read by the owner, regardless of the umask.
393
- # There's no reason to not respect the umask here,
394
- # which means that an extra hoop is required
395
- # to fetch it and reset the new file's mode.
396
- #
397
- # No way to get the umask without setting a new one? Set a safe one
398
- # and then set it back to the old value.
399
- umask = os.umask(0o77)
400
- os.umask(umask)
401
- os.chmod(self.tmp_path, 0o666 & ~umask)
402
- if sys.platform == "win32" and os.path.exists(filename):
403
- # NOTE: on windows (but not cygwin) rename will not replace an
404
- # existing file, so it must be preceded with a remove.
405
- # Sadly there is no way to make the switch atomic.
406
- os.remove(filename)
407
- os.rename(self.tmp_path, filename)
408
- except Exception:
409
- # Don't leave turds behind.
410
- os.unlink(self.tmp_path)
411
- raise
412
-
413
- def write(self, s):
414
- self.tmp_file.write(s.encode("utf-8"))
415
-
416
- return Writer()
417
-
418
-
419
- def EnsureDirExists(path):
420
- """Make sure the directory for |path| exists."""
421
- try:
422
- os.makedirs(os.path.dirname(path))
423
- except OSError:
424
- pass
425
-
426
- def GetCrossCompilerPredefines(): # -> dict
427
- cmd = []
428
-
429
- # shlex.split() will eat '\' in posix mode, but
430
- # setting posix=False will preserve extra '"' cause CreateProcess fail on Windows
431
- # this makes '\' in %CC_target% and %CFLAGS% work
432
- def replace_sep(s):
433
- return s.replace(os.sep, "/") if os.sep != "/" else s
434
-
435
- if CC := os.environ.get("CC_target") or os.environ.get("CC"):
436
- cmd += shlex.split(replace_sep(CC))
437
- if CFLAGS := os.environ.get("CFLAGS"):
438
- cmd += shlex.split(replace_sep(CFLAGS))
439
- elif CXX := os.environ.get("CXX_target") or os.environ.get("CXX"):
440
- cmd += shlex.split(replace_sep(CXX))
441
- if CXXFLAGS := os.environ.get("CXXFLAGS"):
442
- cmd += shlex.split(replace_sep(CXXFLAGS))
443
- else:
444
- return {}
445
-
446
- if sys.platform == "win32":
447
- fd, input = tempfile.mkstemp(suffix=".c")
448
- real_cmd = [*cmd, "-dM", "-E", "-x", "c", input]
449
- try:
450
- os.close(fd)
451
- stdout = subprocess.run(
452
- real_cmd, shell=True,
453
- capture_output=True, check=True
454
- ).stdout
455
- finally:
456
- os.unlink(input)
457
- else:
458
- input = "/dev/null"
459
- real_cmd = [*cmd, "-dM", "-E", "-x", "c", input]
460
- stdout = subprocess.run(
461
- real_cmd, shell=False,
462
- capture_output=True, check=True
463
- ).stdout
464
-
465
- defines = {}
466
- lines = stdout.decode("utf-8").replace("\r\n", "\n").split("\n")
467
- for line in lines:
468
- if (line or "").startswith("#define "):
469
- _, key, *value = line.split(" ")
470
- defines[key] = " ".join(value)
471
- return defines
472
-
473
- def GetFlavorByPlatform():
474
- """Returns |params.flavor| if it's set, the system's default flavor else."""
475
- flavors = {
476
- "cygwin": "win",
477
- "win32": "win",
478
- "darwin": "mac",
479
- }
480
-
481
- if sys.platform in flavors:
482
- return flavors[sys.platform]
483
- if sys.platform.startswith("sunos"):
484
- return "solaris"
485
- if sys.platform.startswith(("dragonfly", "freebsd")):
486
- return "freebsd"
487
- if sys.platform.startswith("openbsd"):
488
- return "openbsd"
489
- if sys.platform.startswith("netbsd"):
490
- return "netbsd"
491
- if sys.platform.startswith("aix"):
492
- return "aix"
493
- if sys.platform.startswith(("os390", "zos")):
494
- return "zos"
495
- if sys.platform == "os400":
496
- return "os400"
497
-
498
- return "linux"
499
-
500
- def GetFlavor(params):
501
- if "flavor" in params:
502
- return params["flavor"]
503
-
504
- defines = GetCrossCompilerPredefines()
505
- if "__EMSCRIPTEN__" in defines:
506
- return "emscripten"
507
- if "__wasm__" in defines:
508
- return "wasi" if "__wasi__" in defines else "wasm"
509
-
510
- return GetFlavorByPlatform()
511
-
512
-
513
- def CopyTool(flavor, out_path, generator_flags={}):
514
- """Finds (flock|mac|win)_tool.gyp in the gyp directory and copies it
515
- to |out_path|."""
516
- # aix and solaris just need flock emulation. mac and win use more complicated
517
- # support scripts.
518
- prefix = {
519
- "aix": "flock",
520
- "os400": "flock",
521
- "solaris": "flock",
522
- "mac": "mac",
523
- "ios": "mac",
524
- "win": "win",
525
- }.get(flavor, None)
526
- if not prefix:
527
- return
528
-
529
- # Slurp input file.
530
- source_path = os.path.join(
531
- os.path.dirname(os.path.abspath(__file__)), "%s_tool.py" % prefix
532
- )
533
- with open(source_path) as source_file:
534
- source = source_file.readlines()
535
-
536
- # Set custom header flags.
537
- header = "# Generated by gyp. Do not edit.\n"
538
- mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
539
- if flavor == "mac" and mac_toolchain_dir:
540
- header += "import os;\nos.environ['DEVELOPER_DIR']='%s'\n" % mac_toolchain_dir
541
-
542
- # Add header and write it out.
543
- tool_path = os.path.join(out_path, "gyp-%s-tool" % prefix)
544
- with open(tool_path, "w") as tool_file:
545
- tool_file.write("".join([source[0], header] + source[1:]))
546
-
547
- # Make file executable.
548
- os.chmod(tool_path, 0o755)
549
-
550
-
551
- # From Alex Martelli,
552
- # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
553
- # ASPN: Python Cookbook: Remove duplicates from a sequence
554
- # First comment, dated 2001/10/13.
555
- # (Also in the printed Python Cookbook.)
556
-
557
-
558
- def uniquer(seq, idfun=lambda x: x):
559
- seen = {}
560
- result = []
561
- for item in seq:
562
- marker = idfun(item)
563
- if marker in seen:
564
- continue
565
- seen[marker] = 1
566
- result.append(item)
567
- return result
568
-
569
-
570
- # Based on http://code.activestate.com/recipes/576694/.
571
- class OrderedSet(MutableSet):
572
- def __init__(self, iterable=None):
573
- self.end = end = []
574
- end += [None, end, end] # sentinel node for doubly linked list
575
- self.map = {} # key --> [key, prev, next]
576
- if iterable is not None:
577
- self |= iterable
578
-
579
- def __len__(self):
580
- return len(self.map)
581
-
582
- def __contains__(self, key):
583
- return key in self.map
584
-
585
- def add(self, key):
586
- if key not in self.map:
587
- end = self.end
588
- curr = end[1]
589
- curr[2] = end[1] = self.map[key] = [key, curr, end]
590
-
591
- def discard(self, key):
592
- if key in self.map:
593
- key, prev_item, next_item = self.map.pop(key)
594
- prev_item[2] = next_item
595
- next_item[1] = prev_item
596
-
597
- def __iter__(self):
598
- end = self.end
599
- curr = end[2]
600
- while curr is not end:
601
- yield curr[0]
602
- curr = curr[2]
603
-
604
- def __reversed__(self):
605
- end = self.end
606
- curr = end[1]
607
- while curr is not end:
608
- yield curr[0]
609
- curr = curr[1]
610
-
611
- # The second argument is an addition that causes a pylint warning.
612
- def pop(self, last=True): # pylint: disable=W0221
613
- if not self:
614
- raise KeyError("set is empty")
615
- key = self.end[1][0] if last else self.end[2][0]
616
- self.discard(key)
617
- return key
618
-
619
- def __repr__(self):
620
- if not self:
621
- return f"{self.__class__.__name__}()"
622
- return f"{self.__class__.__name__}({list(self)!r})"
623
-
624
- def __eq__(self, other):
625
- if isinstance(other, OrderedSet):
626
- return len(self) == len(other) and list(self) == list(other)
627
- return set(self) == set(other)
628
-
629
- # Extensions to the recipe.
630
- def update(self, iterable):
631
- for i in iterable:
632
- if i not in self:
633
- self.add(i)
634
-
635
-
636
- class CycleError(Exception):
637
- """An exception raised when an unexpected cycle is detected."""
638
-
639
- def __init__(self, nodes):
640
- self.nodes = nodes
641
-
642
- def __str__(self):
643
- return "CycleError: cycle involving: " + str(self.nodes)
644
-
645
-
646
- def TopologicallySorted(graph, get_edges):
647
- r"""Topologically sort based on a user provided edge definition.
648
-
649
- Args:
650
- graph: A list of node names.
651
- get_edges: A function mapping from node name to a hashable collection
652
- of node names which this node has outgoing edges to.
653
- Returns:
654
- A list containing all of the node in graph in topological order.
655
- It is assumed that calling get_edges once for each node and caching is
656
- cheaper than repeatedly calling get_edges.
657
- Raises:
658
- CycleError in the event of a cycle.
659
- Example:
660
- graph = {'a': '$(b) $(c)', 'b': 'hi', 'c': '$(b)'}
661
- def GetEdges(node):
662
- return re.findall(r'\$\(([^))]\)', graph[node])
663
- print TopologicallySorted(graph.keys(), GetEdges)
664
- ==>
665
- ['a', 'c', b']
666
- """
667
- get_edges = memoize(get_edges)
668
- visited = set()
669
- visiting = set()
670
- ordered_nodes = []
671
-
672
- def Visit(node):
673
- if node in visiting:
674
- raise CycleError(visiting)
675
- if node in visited:
676
- return
677
- visited.add(node)
678
- visiting.add(node)
679
- for neighbor in get_edges(node):
680
- Visit(neighbor)
681
- visiting.remove(node)
682
- ordered_nodes.insert(0, node)
683
-
684
- for node in sorted(graph):
685
- Visit(node)
686
- return ordered_nodes
687
-
688
-
689
- def CrossCompileRequested():
690
- # TODO: figure out how to not build extra host objects in the
691
- # non-cross-compile case when this is enabled, and enable unconditionally.
692
- return (
693
- os.environ.get("GYP_CROSSCOMPILE")
694
- or os.environ.get("AR_host")
695
- or os.environ.get("CC_host")
696
- or os.environ.get("CXX_host")
697
- or os.environ.get("AR_target")
698
- or os.environ.get("CC_target")
699
- or os.environ.get("CXX_target")
700
- )
701
-
702
-
703
- def IsCygwin():
704
- try:
705
- out = subprocess.Popen(
706
- "uname", stdout=subprocess.PIPE, stderr=subprocess.STDOUT
707
- )
708
- stdout = out.communicate()[0].decode("utf-8")
709
- return "CYGWIN" in str(stdout)
710
- except Exception:
711
- return False