@btc-vision/bitcoin 6.3.2 → 6.3.4

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 (144) hide show
  1. package/.gitattributes +2 -2
  2. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.ready +0 -0
  3. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.release-please-manifest.json +3 -0
  4. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CHANGELOG.md +962 -0
  5. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CONTRIBUTING.md +34 -0
  6. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/LICENSE +24 -0
  7. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/README.md +273 -0
  8. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/SECURITY.md +2 -0
  9. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/addon.gypi +204 -0
  10. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/bin/node-gyp.js +138 -0
  11. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/.release-please-manifest.json +3 -0
  12. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/LICENSE +28 -0
  13. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/ninja/build.ninja +4 -0
  14. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +12 -0
  15. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/GypVsCMake.md +116 -0
  16. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Hacking.md +46 -0
  17. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/InputFormatReference.md +1080 -0
  18. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/LanguageSpecification.md +430 -0
  19. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/README.md +27 -0
  20. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Testing.md +450 -0
  21. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/UserDocumentation.md +965 -0
  22. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp +8 -0
  23. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp.bat +5 -0
  24. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  25. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  26. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  27. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
  28. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  29. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  30. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  31. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  32. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  33. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +692 -0
  34. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common.py +711 -0
  35. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +171 -0
  36. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
  37. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  38. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  39. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  40. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +804 -0
  41. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  42. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1318 -0
  43. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +127 -0
  44. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  45. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +461 -0
  46. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  47. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +57 -0
  48. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
  49. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
  50. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  51. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2964 -0
  52. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
  53. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
  54. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  55. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input.py +3115 -0
  56. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  57. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  58. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
  59. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  60. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  61. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
  62. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1938 -0
  63. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +53 -0
  64. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  65. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3198 -0
  66. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  67. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +3 -0
  68. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +177 -0
  69. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +23 -0
  70. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  71. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
  72. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  73. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  74. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  75. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  76. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  77. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/markers.py +252 -0
  78. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
  79. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  80. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  81. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  82. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
  83. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  84. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
  85. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pyproject.toml +120 -0
  86. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/release-please-config.json +11 -0
  87. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  88. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/Find-VisualStudio.cs +250 -0
  89. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/build.js +227 -0
  90. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/clean.js +15 -0
  91. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/configure.js +328 -0
  92. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/create-config-gypi.js +150 -0
  93. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/download.js +39 -0
  94. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-node-directory.js +63 -0
  95. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-python.js +310 -0
  96. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-visualstudio.js +590 -0
  97. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/install.js +415 -0
  98. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/list.js +26 -0
  99. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/log.js +168 -0
  100. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/node-gyp.js +188 -0
  101. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/process-release.js +146 -0
  102. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/rebuild.js +12 -0
  103. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/remove.js +43 -0
  104. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/util.js +81 -0
  105. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/macOS_Catalina_acid_test.sh +21 -0
  106. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/package.json +51 -0
  107. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/release-please-config.json +40 -0
  108. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/src/win_delay_load_hook.cc +39 -0
  109. package/browser/index.js +1 -1
  110. package/browser/payments/index.d.ts +2 -0
  111. package/browser/psbt.d.ts +3 -3
  112. package/build/payments/index.d.ts +2 -0
  113. package/build/payments/p2pkh.js +52 -10
  114. package/build/payments/p2sh.js +2 -1
  115. package/build/psbt/psbtutils.d.ts +1 -1
  116. package/build/psbt/psbtutils.js +22 -7
  117. package/build/psbt.d.ts +3 -3
  118. package/build/psbt.js +9 -7
  119. package/coverage/tmp/coverage-31752-1735543485354-0.json +1 -0
  120. package/coverage/tmp/coverage-59920-1735543484555-0.json +1 -0
  121. package/coverage/tmp/coverage-66252-1735543483919-0.json +1 -0
  122. package/coverage/tmp/coverage-68440-1735543485236-0.json +1 -0
  123. package/coverage/tmp/coverage-70588-1735543484426-0.json +1 -0
  124. package/coverage/tmp/coverage-79292-1735543485296-0.json +1 -0
  125. package/coverage/tmp/coverage-80212-1735543483980-0.json +1 -0
  126. package/eslint.config.js +56 -56
  127. package/package.json +1 -1
  128. package/src/address.ts +211 -211
  129. package/src/crypto/crypto-browser.js +75 -75
  130. package/src/crypto/crypto.ts +1 -1
  131. package/src/hooks/HookedSigner.ts +108 -108
  132. package/src/index.ts +86 -86
  133. package/src/networks.ts +235 -235
  134. package/src/payments/embed.ts +55 -55
  135. package/src/payments/index.ts +4 -0
  136. package/src/payments/lazy.ts +28 -28
  137. package/src/payments/p2pk.ts +85 -85
  138. package/src/payments/p2pkh.ts +210 -149
  139. package/src/payments/p2sh.ts +206 -205
  140. package/src/psbt/bip371.ts +441 -441
  141. package/src/psbt/psbtutils.ts +315 -299
  142. package/src/psbt.ts +2187 -2174
  143. package/src/types.ts +122 -122
  144. package/webpack.config.js +79 -79
@@ -0,0 +1,171 @@
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()
@@ -0,0 +1,169 @@
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)
@@ -0,0 +1,113 @@
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()
@@ -0,0 +1,55 @@
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:]))