binaryen 1.1.6.1 → 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 +4 -4
- data/lib/binaryen/command.rb +31 -90
- data/lib/binaryen/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae90a4e59e6f813687257623ab4d4a35633c9409de5459101d8080d65fe1fdf1
|
4
|
+
data.tar.gz: 20c161cfa875c14801d03ae2f7a43f5342a0e0a8b9c70f9d9e2d1f44b722f3e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74f7b3010d06316d25eb8b3e74fc2fd33b60f50fcd3bd6db83db8b11c135e003f49f460779e02992e0826a86240b220d3c8e1c82e56361e1e6d054cc7b172679
|
7
|
+
data.tar.gz: 90de5bc2e078f8083116a8dc8244e3807185ff35c1697ef210070bcd4f01d7bf730f13fa1731f479b06032dcc778109faf848a0daa2da0915ab7fe18b033a3e0
|
data/lib/binaryen/command.rb
CHANGED
@@ -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.
|
@@ -18,107 +17,49 @@ module Binaryen
|
|
18
17
|
"wasm-opt" => ["--output=-"],
|
19
18
|
}.freeze
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def run(*arguments, stdin: nil, stderr: File::NULL)
|
28
|
-
command = build_command(*arguments)
|
29
|
-
pipe = IO.popen(command, "rb+", err: stderr)
|
30
|
-
pid = pipe.pid
|
31
|
-
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
32
|
-
remaining_timeout = @timeout
|
33
|
-
|
34
|
-
if stdin
|
35
|
-
start_time, remaining_timeout = write_to_pipe(pipe, stdin, start_time, remaining_timeout)
|
20
|
+
class TimeoutChecker
|
21
|
+
def initialize(end_time:, pid:)
|
22
|
+
@end_time = end_time
|
23
|
+
@pid = pid
|
36
24
|
end
|
37
25
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
output
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def write_to_pipe(pipe, stdin, start_time, remaining_timeout)
|
48
|
-
offset = 0
|
49
|
-
length = stdin.bytesize
|
50
|
-
|
51
|
-
while offset < length
|
52
|
-
start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
|
53
|
-
if IO.select(nil, [pipe], nil, remaining_timeout)
|
54
|
-
written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
|
55
|
-
case written
|
56
|
-
when Integer
|
57
|
-
offset += written
|
58
|
-
when :wait_writable
|
59
|
-
puts "wait"
|
60
|
-
# If the pipe is not ready for writing, retry
|
61
|
-
end
|
62
|
-
else
|
26
|
+
def check!
|
27
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
28
|
+
if now >= @end_time
|
29
|
+
Process.kill("KILL", @pid)
|
63
30
|
raise Timeout::Error, "Command timed out"
|
64
31
|
end
|
32
|
+
remaining_time = @end_time - now
|
33
|
+
remaining_time
|
65
34
|
end
|
66
|
-
|
67
|
-
pipe.close_write
|
68
|
-
[start_time, remaining_timeout]
|
69
|
-
end
|
70
|
-
|
71
|
-
def read_from_pipe(pipe, start_time, remaining_timeout)
|
72
|
-
output = +""
|
73
|
-
|
74
|
-
while (result = pipe.read_nonblock(8192, exception: false))
|
75
|
-
start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
|
76
|
-
|
77
|
-
case result
|
78
|
-
when :wait_readable
|
79
|
-
IO.select([pipe], nil, nil, remaining_timeout)
|
80
|
-
when nil
|
81
|
-
break
|
82
|
-
else
|
83
|
-
output << result
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
[output, remaining_timeout]
|
88
35
|
end
|
89
36
|
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
raise Timeout::Error, "command timed out" if remaining_timeout <= 0
|
95
|
-
|
96
|
-
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
97
|
-
|
98
|
-
[start_time, remaining_timeout]
|
37
|
+
def initialize(cmd, timeout: 10, ignore_missing: false)
|
38
|
+
@cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
|
39
|
+
@timeout = timeout
|
40
|
+
@default_args = DEFAULT_ARGS_FOR_COMMAND.fetch(cmd, [])
|
99
41
|
end
|
100
42
|
|
101
|
-
def
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
return true
|
111
|
-
else
|
112
|
-
sleep(0.1)
|
113
|
-
end
|
43
|
+
def run(*arguments, stdin: nil, stderr: File::NULL)
|
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}"
|
114
52
|
end
|
115
53
|
|
116
|
-
|
117
|
-
|
54
|
+
child.out
|
55
|
+
rescue POSIX::Spawn::TimeoutExceeded => e
|
56
|
+
raise Timeout::Error, e.message
|
118
57
|
end
|
119
58
|
|
120
|
-
|
121
|
-
|
59
|
+
private
|
60
|
+
|
61
|
+
def build_arguments(*arguments)
|
62
|
+
arguments + @default_args
|
122
63
|
end
|
123
64
|
|
124
65
|
def command_path(cmd, ignore_missing)
|
data/lib/binaryen/version.rb
CHANGED
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.
|
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-
|
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
|
@@ -92,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
106
|
- !ruby/object:Gem::Version
|
93
107
|
version: '0'
|
94
108
|
requirements: []
|
95
|
-
rubygems_version: 3.4.
|
109
|
+
rubygems_version: 3.4.22
|
96
110
|
signing_key:
|
97
111
|
specification_version: 4
|
98
112
|
summary: Vendors binaryen libraries, headers, and executables for use in Ruby
|