binaryen 1.1.6.2 → 1.1.6.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 502cfbb2e9e33d3b32d5ab1881bf097fc7321bcb8746e2ae4b4142a6dbe3727a
4
- data.tar.gz: 20c543218c8b5c256012e3b386e4cf6ceda9461899f10d990edcba0b983dbc17
3
+ metadata.gz: ae90a4e59e6f813687257623ab4d4a35633c9409de5459101d8080d65fe1fdf1
4
+ data.tar.gz: 20c161cfa875c14801d03ae2f7a43f5342a0e0a8b9c70f9d9e2d1f44b722f3e7
5
5
  SHA512:
6
- metadata.gz: 2a9d8542c524badbeb6721a9b6e9fc6cd9531e3a44134bce6206cba23c99c1d069850f85e0e222a0749de571d647e57a6f122dba6992661ef819f884581c7bcf
7
- data.tar.gz: e62fa41cc97a4d777e10872d4ec9df6690ca5a5c6d773d8e01de897b93e41880e6bd676a5756776bbdf91629977402c6dec8f7e269a2c32909f1b62143773ba5
6
+ metadata.gz: 74f7b3010d06316d25eb8b3e74fc2fd33b60f50fcd3bd6db83db8b11c135e003f49f460779e02992e0826a86240b220d3c8e1c82e56361e1e6d054cc7b172679
7
+ data.tar.gz: 90de5bc2e078f8083116a8dc8244e3807185ff35c1697ef210070bcd4f01d7bf730f13fa1731f479b06032dcc778109faf848a0daa2da0915ab7fe18b033a3e0
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "English"
4
- require "shellwords"
5
3
  require "timeout"
4
+ require "posix/spawn"
6
5
 
7
6
  module Binaryen
8
7
  # Wrapper around a binaryen executable command with a timeout and streaming IO.
@@ -42,76 +41,25 @@ module Binaryen
42
41
  end
43
42
 
44
43
  def run(*arguments, stdin: nil, stderr: File::NULL)
45
- end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
46
- command = build_command(*arguments)
47
- pipe = IO.popen(command, "rb+", err: stderr)
48
- pid = pipe.pid
49
- timeout_checker = TimeoutChecker.new(end_time: end_time, pid: pid)
50
-
51
- write_to_pipe(pipe, stdin, timeout_checker) if stdin
52
- output = read_from_pipe(pipe, timeout_checker)
53
- wait_or_kill(pid, timeout_checker)
54
-
55
- output
56
- end
57
-
58
- private
59
-
60
- def write_to_pipe(pipe, stdin, timeout_checker)
61
- offset = 0
62
- length = stdin.bytesize
63
-
64
- while offset < length
65
- remaining_time = timeout_checker.check!
66
-
67
- if IO.select(nil, [pipe], nil, remaining_time)
68
- written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
69
- offset += written if written.is_a?(Integer)
70
- else
71
- raise Timeout::Error, "Command timed out"
72
- end
44
+ args = build_arguments(*arguments)
45
+ child = POSIX::Spawn::Child.new(@cmd, *args, input: stdin, timeout: @timeout)
46
+ if child.status && !child.status.success?
47
+ err_io = stderr.is_a?(String) ? File.open(stderr, "w") : stderr
48
+ err_io.binmode
49
+ err_io.write(child.err)
50
+ err_io.rewind
51
+ raise NonZeroExitStatus, "command exited with non-zero status: #{child.status}"
73
52
  end
74
53
 
75
- pipe.close_write
54
+ child.out
55
+ rescue POSIX::Spawn::TimeoutExceeded => e
56
+ raise Timeout::Error, e.message
76
57
  end
77
58
 
78
- def read_from_pipe(pipe, timeout_checker)
79
- output = +""
80
-
81
- while (result = pipe.read_nonblock(8192, exception: false))
82
- remaining_time = timeout_checker.check!
83
- raise Timeout::Error, "Command timed out" if remaining_time <= 0
84
-
85
- case result
86
- when :wait_readable
87
- IO.select([pipe], nil, nil, remaining_time)
88
- when nil
89
- break
90
- else
91
- output << result
92
- end
93
- end
94
-
95
- output
96
- end
97
-
98
- def wait_or_kill(pid, timeout_checker)
99
- loop do
100
- remaining_time = timeout_checker.check!
101
- raise Timeout::Error, "timed out waiting on process" if remaining_time <= 0
102
-
103
- if (_, status = Process.wait2(pid, Process::WNOHANG))
104
- raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}" if status.exitstatus != 0
105
-
106
- return true
107
- else
108
- sleep(0.1)
109
- end
110
- end
111
- end
59
+ private
112
60
 
113
- def build_command(*arguments)
114
- Shellwords.join([@cmd] + arguments + @default_args)
61
+ def build_arguments(*arguments)
62
+ arguments + @default_args
115
63
  end
116
64
 
117
65
  def command_path(cmd, ignore_missing)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binaryen
4
- VERSION = "1.1.6.2"
4
+ VERSION = "1.1.6.3"
5
5
  BINARYEN_VERSION = "version_116"
6
6
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binaryen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6.2
4
+ version: 1.1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-11 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: posix-spawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
13
27
  description:
14
28
  email:
15
29
  - gems@shopify.com