binaryen 1.1.6.1 → 1.1.6.2
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 +37 -44
- data/lib/binaryen/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 502cfbb2e9e33d3b32d5ab1881bf097fc7321bcb8746e2ae4b4142a6dbe3727a
|
4
|
+
data.tar.gz: 20c543218c8b5c256012e3b386e4cf6ceda9461899f10d990edcba0b983dbc17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a9d8542c524badbeb6721a9b6e9fc6cd9531e3a44134bce6206cba23c99c1d069850f85e0e222a0749de571d647e57a6f122dba6992661ef819f884581c7bcf
|
7
|
+
data.tar.gz: e62fa41cc97a4d777e10872d4ec9df6690ca5a5c6d773d8e01de897b93e41880e6bd676a5756776bbdf91629977402c6dec8f7e269a2c32909f1b62143773ba5
|
data/lib/binaryen/command.rb
CHANGED
@@ -18,6 +18,23 @@ module Binaryen
|
|
18
18
|
"wasm-opt" => ["--output=-"],
|
19
19
|
}.freeze
|
20
20
|
|
21
|
+
class TimeoutChecker
|
22
|
+
def initialize(end_time:, pid:)
|
23
|
+
@end_time = end_time
|
24
|
+
@pid = pid
|
25
|
+
end
|
26
|
+
|
27
|
+
def check!
|
28
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
29
|
+
if now >= @end_time
|
30
|
+
Process.kill("KILL", @pid)
|
31
|
+
raise Timeout::Error, "Command timed out"
|
32
|
+
end
|
33
|
+
remaining_time = @end_time - now
|
34
|
+
remaining_time
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
21
38
|
def initialize(cmd, timeout: 10, ignore_missing: false)
|
22
39
|
@cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
|
23
40
|
@timeout = timeout
|
@@ -25,58 +42,49 @@ module Binaryen
|
|
25
42
|
end
|
26
43
|
|
27
44
|
def run(*arguments, stdin: nil, stderr: File::NULL)
|
45
|
+
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
|
28
46
|
command = build_command(*arguments)
|
29
47
|
pipe = IO.popen(command, "rb+", err: stderr)
|
30
48
|
pid = pipe.pid
|
31
|
-
|
32
|
-
remaining_timeout = @timeout
|
33
|
-
|
34
|
-
if stdin
|
35
|
-
start_time, remaining_timeout = write_to_pipe(pipe, stdin, start_time, remaining_timeout)
|
36
|
-
end
|
49
|
+
timeout_checker = TimeoutChecker.new(end_time: end_time, pid: pid)
|
37
50
|
|
38
|
-
|
39
|
-
|
40
|
-
wait_or_kill(pid,
|
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)
|
41
54
|
|
42
55
|
output
|
43
56
|
end
|
44
57
|
|
45
58
|
private
|
46
59
|
|
47
|
-
def write_to_pipe(pipe, stdin,
|
60
|
+
def write_to_pipe(pipe, stdin, timeout_checker)
|
48
61
|
offset = 0
|
49
62
|
length = stdin.bytesize
|
50
63
|
|
51
64
|
while offset < length
|
52
|
-
|
53
|
-
|
65
|
+
remaining_time = timeout_checker.check!
|
66
|
+
|
67
|
+
if IO.select(nil, [pipe], nil, remaining_time)
|
54
68
|
written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
|
55
|
-
|
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
|
69
|
+
offset += written if written.is_a?(Integer)
|
62
70
|
else
|
63
71
|
raise Timeout::Error, "Command timed out"
|
64
72
|
end
|
65
73
|
end
|
66
74
|
|
67
75
|
pipe.close_write
|
68
|
-
[start_time, remaining_timeout]
|
69
76
|
end
|
70
77
|
|
71
|
-
def read_from_pipe(pipe,
|
78
|
+
def read_from_pipe(pipe, timeout_checker)
|
72
79
|
output = +""
|
73
80
|
|
74
81
|
while (result = pipe.read_nonblock(8192, exception: false))
|
75
|
-
|
82
|
+
remaining_time = timeout_checker.check!
|
83
|
+
raise Timeout::Error, "Command timed out" if remaining_time <= 0
|
76
84
|
|
77
85
|
case result
|
78
86
|
when :wait_readable
|
79
|
-
IO.select([pipe], nil, nil,
|
87
|
+
IO.select([pipe], nil, nil, remaining_time)
|
80
88
|
when nil
|
81
89
|
break
|
82
90
|
else
|
@@ -84,37 +92,22 @@ module Binaryen
|
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
def update_timeout(start_time, remaining_timeout)
|
91
|
-
elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
|
92
|
-
remaining_timeout -= elapsed_time
|
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]
|
95
|
+
output
|
99
96
|
end
|
100
97
|
|
101
|
-
def wait_or_kill(pid,
|
102
|
-
|
103
|
-
|
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
|
104
102
|
|
105
103
|
if (_, status = Process.wait2(pid, Process::WNOHANG))
|
106
|
-
if status.exitstatus != 0
|
107
|
-
raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}"
|
108
|
-
end
|
104
|
+
raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}" if status.exitstatus != 0
|
109
105
|
|
110
106
|
return true
|
111
107
|
else
|
112
108
|
sleep(0.1)
|
113
109
|
end
|
114
110
|
end
|
115
|
-
|
116
|
-
Process.kill("KILL", pid)
|
117
|
-
raise Timeout::Error, "timed out waiting on process"
|
118
111
|
end
|
119
112
|
|
120
113
|
def build_command(*arguments)
|
data/lib/binaryen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
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
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
|
-
rubygems_version: 3.4.
|
95
|
+
rubygems_version: 3.4.22
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Vendors binaryen libraries, headers, and executables for use in Ruby
|