@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,171 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- # Copyright (c) 2012 Google Inc. All rights reserved.
4
- # Use of this source code is governed by a BSD-style license that can be
5
- # found in the LICENSE file.
6
-
7
- """Unit tests for the common.py file."""
8
-
9
- import gyp.common
10
- import unittest
11
- import sys
12
- import os
13
- from unittest.mock import patch, MagicMock
14
-
15
- class TestTopologicallySorted(unittest.TestCase):
16
- def test_Valid(self):
17
- """Test that sorting works on a valid graph with one possible order."""
18
- graph = {
19
- "a": ["b", "c"],
20
- "b": [],
21
- "c": ["d"],
22
- "d": ["b"],
23
- }
24
-
25
- def GetEdge(node):
26
- return tuple(graph[node])
27
-
28
- assert gyp.common.TopologicallySorted(
29
- graph.keys(), GetEdge) == ["a", "c", "d", "b"]
30
-
31
- def test_Cycle(self):
32
- """Test that an exception is thrown on a cyclic graph."""
33
- graph = {
34
- "a": ["b"],
35
- "b": ["c"],
36
- "c": ["d"],
37
- "d": ["a"],
38
- }
39
-
40
- def GetEdge(node):
41
- return tuple(graph[node])
42
-
43
- self.assertRaises(
44
- gyp.common.CycleError, gyp.common.TopologicallySorted, graph.keys(), GetEdge
45
- )
46
-
47
-
48
- class TestGetFlavor(unittest.TestCase):
49
- """Test that gyp.common.GetFlavor works as intended"""
50
-
51
- original_platform = ""
52
-
53
- def setUp(self):
54
- self.original_platform = sys.platform
55
-
56
- def tearDown(self):
57
- sys.platform = self.original_platform
58
-
59
- def assertFlavor(self, expected, argument, param):
60
- sys.platform = argument
61
- assert expected == gyp.common.GetFlavor(param)
62
-
63
- def test_platform_default(self):
64
- self.assertFlavor("freebsd", "freebsd9", {})
65
- self.assertFlavor("freebsd", "freebsd10", {})
66
- self.assertFlavor("openbsd", "openbsd5", {})
67
- self.assertFlavor("solaris", "sunos5", {})
68
- self.assertFlavor("solaris", "sunos", {})
69
- self.assertFlavor("linux", "linux2", {})
70
- self.assertFlavor("linux", "linux3", {})
71
- self.assertFlavor("linux", "linux", {})
72
-
73
- def test_param(self):
74
- self.assertFlavor("foobar", "linux2", {"flavor": "foobar"})
75
-
76
- class MockCommunicate:
77
- def __init__(self, stdout):
78
- self.stdout = stdout
79
-
80
- def decode(self, encoding):
81
- return self.stdout
82
-
83
- @patch("os.close")
84
- @patch("os.unlink")
85
- @patch("tempfile.mkstemp")
86
- def test_GetCrossCompilerPredefines(self, mock_mkstemp, mock_unlink, mock_close):
87
- mock_close.return_value = None
88
- mock_unlink.return_value = None
89
- mock_mkstemp.return_value = (0, "temp.c")
90
-
91
- def mock_run(env, defines_stdout, expected_cmd):
92
- with patch("subprocess.run") as mock_run:
93
- mock_process = MagicMock()
94
- mock_process.returncode = 0
95
- mock_process.stdout = TestGetFlavor.MockCommunicate(defines_stdout)
96
- mock_run.return_value = mock_process
97
- expected_input = "temp.c" if sys.platform == "win32" else "/dev/null"
98
- with patch.dict(os.environ, env):
99
- defines = gyp.common.GetCrossCompilerPredefines()
100
- flavor = gyp.common.GetFlavor({})
101
- if env.get("CC_target"):
102
- mock_run.assert_called_with(
103
- [
104
- *expected_cmd,
105
- "-dM", "-E", "-x", "c", expected_input
106
- ],
107
- shell=sys.platform == "win32",
108
- capture_output=True, check=True)
109
- return [defines, flavor]
110
-
111
- [defines1, _] = mock_run({}, "", [])
112
- assert {} == defines1
113
-
114
- [defines2, flavor2] = mock_run(
115
- { "CC_target": "/opt/wasi-sdk/bin/clang" },
116
- "#define __wasm__ 1\n#define __wasi__ 1\n",
117
- ["/opt/wasi-sdk/bin/clang"]
118
- )
119
- assert { "__wasm__": "1", "__wasi__": "1" } == defines2
120
- assert flavor2 == "wasi"
121
-
122
- [defines3, flavor3] = mock_run(
123
- { "CC_target": "/opt/wasi-sdk/bin/clang --target=wasm32" },
124
- "#define __wasm__ 1\n",
125
- ["/opt/wasi-sdk/bin/clang", "--target=wasm32"]
126
- )
127
- assert { "__wasm__": "1" } == defines3
128
- assert flavor3 == "wasm"
129
-
130
- [defines4, flavor4] = mock_run(
131
- { "CC_target": "/emsdk/upstream/emscripten/emcc" },
132
- "#define __EMSCRIPTEN__ 1\n",
133
- ["/emsdk/upstream/emscripten/emcc"]
134
- )
135
- assert { "__EMSCRIPTEN__": "1" } == defines4
136
- assert flavor4 == "emscripten"
137
-
138
- # Test path which include white space
139
- [defines5, flavor5] = mock_run(
140
- {
141
- "CC_target": "\"/Users/Toyo Li/wasi-sdk/bin/clang\" -O3",
142
- "CFLAGS": "--target=wasm32-wasi-threads -pthread"
143
- },
144
- "#define __wasm__ 1\n#define __wasi__ 1\n#define _REENTRANT 1\n",
145
- [
146
- "/Users/Toyo Li/wasi-sdk/bin/clang",
147
- "-O3",
148
- "--target=wasm32-wasi-threads",
149
- "-pthread"
150
- ]
151
- )
152
- assert {
153
- "__wasm__": "1",
154
- "__wasi__": "1",
155
- "_REENTRANT": "1"
156
- } == defines5
157
- assert flavor5 == "wasi"
158
-
159
- original_sep = os.sep
160
- os.sep = "\\"
161
- [defines6, flavor6] = mock_run(
162
- { "CC_target": "\"C:\\Program Files\\wasi-sdk\\clang.exe\"" },
163
- "#define __wasm__ 1\n#define __wasi__ 1\n",
164
- ["C:/Program Files/wasi-sdk/clang.exe"]
165
- )
166
- os.sep = original_sep
167
- assert { "__wasm__": "1", "__wasi__": "1" } == defines6
168
- assert flavor6 == "wasi"
169
-
170
- if __name__ == "__main__":
171
- unittest.main()
@@ -1,169 +0,0 @@
1
- # Copyright (c) 2011 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 sys
6
- import re
7
- import os
8
- import locale
9
- from functools import reduce
10
-
11
-
12
- def XmlToString(content, encoding="utf-8", pretty=False):
13
- """ Writes the XML content to disk, touching the file only if it has changed.
14
-
15
- Visual Studio files have a lot of pre-defined structures. This function makes
16
- it easy to represent these structures as Python data structures, instead of
17
- having to create a lot of function calls.
18
-
19
- Each XML element of the content is represented as a list composed of:
20
- 1. The name of the element, a string,
21
- 2. The attributes of the element, a dictionary (optional), and
22
- 3+. The content of the element, if any. Strings are simple text nodes and
23
- lists are child elements.
24
-
25
- Example 1:
26
- <test/>
27
- becomes
28
- ['test']
29
-
30
- Example 2:
31
- <myelement a='value1' b='value2'>
32
- <childtype>This is</childtype>
33
- <childtype>it!</childtype>
34
- </myelement>
35
-
36
- becomes
37
- ['myelement', {'a':'value1', 'b':'value2'},
38
- ['childtype', 'This is'],
39
- ['childtype', 'it!'],
40
- ]
41
-
42
- Args:
43
- content: The structured content to be converted.
44
- encoding: The encoding to report on the first XML line.
45
- pretty: True if we want pretty printing with indents and new lines.
46
-
47
- Returns:
48
- The XML content as a string.
49
- """
50
- # We create a huge list of all the elements of the file.
51
- xml_parts = ['<?xml version="1.0" encoding="%s"?>' % encoding]
52
- if pretty:
53
- xml_parts.append("\n")
54
- _ConstructContentList(xml_parts, content, pretty)
55
-
56
- # Convert it to a string
57
- return "".join(xml_parts)
58
-
59
-
60
- def _ConstructContentList(xml_parts, specification, pretty, level=0):
61
- """ Appends the XML parts corresponding to the specification.
62
-
63
- Args:
64
- xml_parts: A list of XML parts to be appended to.
65
- specification: The specification of the element. See EasyXml docs.
66
- pretty: True if we want pretty printing with indents and new lines.
67
- level: Indentation level.
68
- """
69
- # The first item in a specification is the name of the element.
70
- if pretty:
71
- indentation = " " * level
72
- new_line = "\n"
73
- else:
74
- indentation = ""
75
- new_line = ""
76
- name = specification[0]
77
- if not isinstance(name, str):
78
- raise Exception(
79
- "The first item of an EasyXml specification should be "
80
- "a string. Specification was " + str(specification)
81
- )
82
- xml_parts.append(indentation + "<" + name)
83
-
84
- # Optionally in second position is a dictionary of the attributes.
85
- rest = specification[1:]
86
- if rest and isinstance(rest[0], dict):
87
- for at, val in sorted(rest[0].items()):
88
- xml_parts.append(f' {at}="{_XmlEscape(val, attr=True)}"')
89
- rest = rest[1:]
90
- if rest:
91
- xml_parts.append(">")
92
- all_strings = reduce(lambda x, y: x and isinstance(y, str), rest, True)
93
- multi_line = not all_strings
94
- if multi_line and new_line:
95
- xml_parts.append(new_line)
96
- for child_spec in rest:
97
- # If it's a string, append a text node.
98
- # Otherwise recurse over that child definition
99
- if isinstance(child_spec, str):
100
- xml_parts.append(_XmlEscape(child_spec))
101
- else:
102
- _ConstructContentList(xml_parts, child_spec, pretty, level + 1)
103
- if multi_line and indentation:
104
- xml_parts.append(indentation)
105
- xml_parts.append(f"</{name}>{new_line}")
106
- else:
107
- xml_parts.append("/>%s" % new_line)
108
-
109
-
110
- def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False,
111
- win32=(sys.platform == "win32")):
112
- """ Writes the XML content to disk, touching the file only if it has changed.
113
-
114
- Args:
115
- content: The structured content to be written.
116
- path: Location of the file.
117
- encoding: The encoding to report on the first line of the XML file.
118
- pretty: True if we want pretty printing with indents and new lines.
119
- """
120
- xml_string = XmlToString(content, encoding, pretty)
121
- if win32 and os.linesep != "\r\n":
122
- xml_string = xml_string.replace("\n", "\r\n")
123
-
124
- try: # getdefaultlocale() was removed in Python 3.11
125
- default_encoding = locale.getdefaultlocale()[1]
126
- except AttributeError:
127
- default_encoding = locale.getencoding()
128
-
129
- if default_encoding and default_encoding.upper() != encoding.upper():
130
- xml_string = xml_string.encode(encoding)
131
-
132
- # Get the old content
133
- try:
134
- with open(path) as file:
135
- existing = file.read()
136
- except OSError:
137
- existing = None
138
-
139
- # It has changed, write it
140
- if existing != xml_string:
141
- with open(path, "wb") as file:
142
- file.write(xml_string)
143
-
144
-
145
- _xml_escape_map = {
146
- '"': "&quot;",
147
- "'": "&apos;",
148
- "<": "&lt;",
149
- ">": "&gt;",
150
- "&": "&amp;",
151
- "\n": "&#xA;",
152
- "\r": "&#xD;",
153
- }
154
-
155
-
156
- _xml_escape_re = re.compile("(%s)" % "|".join(map(re.escape, _xml_escape_map.keys())))
157
-
158
-
159
- def _XmlEscape(value, attr=False):
160
- """ Escape a string for inclusion in XML."""
161
-
162
- def replace(match):
163
- m = match.string[match.start() : match.end()]
164
- # don't replace single quotes in attrs
165
- if attr and m == "'":
166
- return m
167
- return _xml_escape_map[m]
168
-
169
- return _xml_escape_re.sub(replace, value)
@@ -1,113 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- # Copyright (c) 2011 Google Inc. All rights reserved.
4
- # Use of this source code is governed by a BSD-style license that can be
5
- # found in the LICENSE file.
6
-
7
- """ Unit tests for the easy_xml.py file. """
8
-
9
- import gyp.easy_xml as easy_xml
10
- import unittest
11
-
12
- from io import StringIO
13
-
14
-
15
- class TestSequenceFunctions(unittest.TestCase):
16
- def setUp(self):
17
- self.stderr = StringIO()
18
-
19
- def test_EasyXml_simple(self):
20
- self.assertEqual(
21
- easy_xml.XmlToString(["test"]),
22
- '<?xml version="1.0" encoding="utf-8"?><test/>',
23
- )
24
-
25
- self.assertEqual(
26
- easy_xml.XmlToString(["test"], encoding="Windows-1252"),
27
- '<?xml version="1.0" encoding="Windows-1252"?><test/>',
28
- )
29
-
30
- def test_EasyXml_simple_with_attributes(self):
31
- self.assertEqual(
32
- easy_xml.XmlToString(["test2", {"a": "value1", "b": "value2"}]),
33
- '<?xml version="1.0" encoding="utf-8"?><test2 a="value1" b="value2"/>',
34
- )
35
-
36
- def test_EasyXml_escaping(self):
37
- original = "<test>'\"\r&\nfoo"
38
- converted = "&lt;test&gt;'&quot;&#xD;&amp;&#xA;foo"
39
- converted_apos = converted.replace("'", "&apos;")
40
- self.assertEqual(
41
- easy_xml.XmlToString(["test3", {"a": original}, original]),
42
- '<?xml version="1.0" encoding="utf-8"?><test3 a="%s">%s</test3>'
43
- % (converted, converted_apos),
44
- )
45
-
46
- def test_EasyXml_pretty(self):
47
- self.assertEqual(
48
- easy_xml.XmlToString(
49
- ["test3", ["GrandParent", ["Parent1", ["Child"]], ["Parent2"]]],
50
- pretty=True,
51
- ),
52
- '<?xml version="1.0" encoding="utf-8"?>\n'
53
- "<test3>\n"
54
- " <GrandParent>\n"
55
- " <Parent1>\n"
56
- " <Child/>\n"
57
- " </Parent1>\n"
58
- " <Parent2/>\n"
59
- " </GrandParent>\n"
60
- "</test3>\n",
61
- )
62
-
63
- def test_EasyXml_complex(self):
64
- # We want to create:
65
- target = (
66
- '<?xml version="1.0" encoding="utf-8"?>'
67
- "<Project>"
68
- '<PropertyGroup Label="Globals">'
69
- "<ProjectGuid>{D2250C20-3A94-4FB9-AF73-11BC5B73884B}</ProjectGuid>"
70
- "<Keyword>Win32Proj</Keyword>"
71
- "<RootNamespace>automated_ui_tests</RootNamespace>"
72
- "</PropertyGroup>"
73
- '<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props"/>'
74
- "<PropertyGroup "
75
- "Condition=\"'$(Configuration)|$(Platform)'=="
76
- '\'Debug|Win32\'" Label="Configuration">'
77
- "<ConfigurationType>Application</ConfigurationType>"
78
- "<CharacterSet>Unicode</CharacterSet>"
79
- "<SpectreMitigation>SpectreLoadCF</SpectreMitigation>"
80
- "<VCToolsVersion>14.36.32532</VCToolsVersion>"
81
- "</PropertyGroup>"
82
- "</Project>"
83
- )
84
-
85
- xml = easy_xml.XmlToString(
86
- [
87
- "Project",
88
- [
89
- "PropertyGroup",
90
- {"Label": "Globals"},
91
- ["ProjectGuid", "{D2250C20-3A94-4FB9-AF73-11BC5B73884B}"],
92
- ["Keyword", "Win32Proj"],
93
- ["RootNamespace", "automated_ui_tests"],
94
- ],
95
- ["Import", {"Project": "$(VCTargetsPath)\\Microsoft.Cpp.props"}],
96
- [
97
- "PropertyGroup",
98
- {
99
- "Condition": "'$(Configuration)|$(Platform)'=='Debug|Win32'",
100
- "Label": "Configuration",
101
- },
102
- ["ConfigurationType", "Application"],
103
- ["CharacterSet", "Unicode"],
104
- ["SpectreMitigation", "SpectreLoadCF"],
105
- ["VCToolsVersion", "14.36.32532"],
106
- ],
107
- ]
108
- )
109
- self.assertEqual(xml, target)
110
-
111
-
112
- if __name__ == "__main__":
113
- unittest.main()
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env python3
2
- # Copyright (c) 2011 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
- """These functions are executed via gyp-flock-tool when using the Makefile
7
- generator. Used on systems that don't have a built-in flock."""
8
-
9
- import fcntl
10
- import os
11
- import struct
12
- import subprocess
13
- import sys
14
-
15
-
16
- def main(args):
17
- executor = FlockTool()
18
- executor.Dispatch(args)
19
-
20
-
21
- class FlockTool:
22
- """This class emulates the 'flock' command."""
23
-
24
- def Dispatch(self, args):
25
- """Dispatches a string command to a method."""
26
- if len(args) < 1:
27
- raise Exception("Not enough arguments")
28
-
29
- method = "Exec%s" % self._CommandifyName(args[0])
30
- getattr(self, method)(*args[1:])
31
-
32
- def _CommandifyName(self, name_string):
33
- """Transforms a tool name like copy-info-plist to CopyInfoPlist"""
34
- return name_string.title().replace("-", "")
35
-
36
- def ExecFlock(self, lockfile, *cmd_list):
37
- """Emulates the most basic behavior of Linux's flock(1)."""
38
- # Rely on exception handling to report errors.
39
- # Note that the stock python on SunOS has a bug
40
- # where fcntl.flock(fd, LOCK_EX) always fails
41
- # with EBADF, that's why we use this F_SETLK
42
- # hack instead.
43
- fd = os.open(lockfile, os.O_WRONLY | os.O_NOCTTY | os.O_CREAT, 0o666)
44
- if sys.platform.startswith("aix") or sys.platform == "os400":
45
- # Python on AIX is compiled with LARGEFILE support, which changes the
46
- # struct size.
47
- op = struct.pack("hhIllqq", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
48
- else:
49
- op = struct.pack("hhllhhl", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
50
- fcntl.fcntl(fd, fcntl.F_SETLK, op)
51
- return subprocess.call(cmd_list)
52
-
53
-
54
- if __name__ == "__main__":
55
- sys.exit(main(sys.argv[1:]))