binaryen 1.1.6.2 → 1.1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/binaryen/command.rb +19 -11
- data/lib/binaryen/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0f235a249bcf6c38016c2033776997d2d636126cea0b37d47c98dc2b932dd08
|
4
|
+
data.tar.gz: 3f123ebb5bdb0f24ebf004097e02ccab417d09838e9ec663a87e43ae472cb9a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d58caa196cbc38e9178dba6fa0efdcdde270d298ef5c3f34e523f5281630ae18c32bac9bd6da379fb7b758a536b94afc2c3c3faddb68118c5ccb64255c256da
|
7
|
+
data.tar.gz: 85f826a48ba40d0e3d48e4806cc52faf265c058b53421af32efdc67eb811075f99c7e83488f6aab85b141478cac104c2d1031931374df75c650972107c8acd5a
|
data/lib/binaryen/command.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "English"
|
4
4
|
require "shellwords"
|
5
5
|
require "timeout"
|
6
|
+
require "posix/spawn"
|
6
7
|
|
7
8
|
module Binaryen
|
8
9
|
# Wrapper around a binaryen executable command with a timeout and streaming IO.
|
@@ -14,6 +15,8 @@ module Binaryen
|
|
14
15
|
# optimized_wasm = command.run("-O4", stdin: "(module)")
|
15
16
|
# ```
|
16
17
|
class Command
|
18
|
+
include POSIX::Spawn
|
19
|
+
|
17
20
|
DEFAULT_ARGS_FOR_COMMAND = {
|
18
21
|
"wasm-opt" => ["--output=-"],
|
19
22
|
}.freeze
|
@@ -41,23 +44,26 @@ module Binaryen
|
|
41
44
|
@default_args = DEFAULT_ARGS_FOR_COMMAND.fetch(cmd, [])
|
42
45
|
end
|
43
46
|
|
44
|
-
def run(*arguments, stdin: nil, stderr:
|
47
|
+
def run(*arguments, stdin: nil, stderr: nil)
|
45
48
|
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
|
46
49
|
command = build_command(*arguments)
|
47
|
-
|
48
|
-
pid = pipe.pid
|
50
|
+
pid, iwr, ord, erd = popen4(*command)
|
49
51
|
timeout_checker = TimeoutChecker.new(end_time: end_time, pid: pid)
|
50
52
|
|
51
|
-
write_to_pipe(
|
52
|
-
|
53
|
-
|
53
|
+
write_to_pipe(iwr, stdin, timeout_checker) if stdin
|
54
|
+
if stderr
|
55
|
+
err_output = read_from_pipe(erd, timeout_checker)
|
56
|
+
write_to_pipe(stderr, err_output, timeout_checker, close_write: false)
|
57
|
+
end
|
58
|
+
output = read_from_pipe(ord, timeout_checker)
|
59
|
+
wait_or_kill(pid, timeout_checker, erd, stderr)
|
54
60
|
|
55
61
|
output
|
56
62
|
end
|
57
63
|
|
58
64
|
private
|
59
65
|
|
60
|
-
def write_to_pipe(pipe, stdin, timeout_checker)
|
66
|
+
def write_to_pipe(pipe, stdin, timeout_checker, close_write: true)
|
61
67
|
offset = 0
|
62
68
|
length = stdin.bytesize
|
63
69
|
|
@@ -72,7 +78,7 @@ module Binaryen
|
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
75
|
-
pipe.close_write
|
81
|
+
pipe.close_write if close_write
|
76
82
|
end
|
77
83
|
|
78
84
|
def read_from_pipe(pipe, timeout_checker)
|
@@ -95,13 +101,15 @@ module Binaryen
|
|
95
101
|
output
|
96
102
|
end
|
97
103
|
|
98
|
-
def wait_or_kill(pid, timeout_checker)
|
104
|
+
def wait_or_kill(pid, timeout_checker, err_read, err_write)
|
99
105
|
loop do
|
100
106
|
remaining_time = timeout_checker.check!
|
101
107
|
raise Timeout::Error, "timed out waiting on process" if remaining_time <= 0
|
102
108
|
|
103
109
|
if (_, status = Process.wait2(pid, Process::WNOHANG))
|
104
|
-
|
110
|
+
|
111
|
+
raise Binaryen::NonZeroExitStatus,
|
112
|
+
"command exited with status #{status.exitstatus}" if status.exitstatus != 0
|
105
113
|
|
106
114
|
return true
|
107
115
|
else
|
@@ -111,7 +119,7 @@ module Binaryen
|
|
111
119
|
end
|
112
120
|
|
113
121
|
def build_command(*arguments)
|
114
|
-
|
122
|
+
[@cmd] + arguments + @default_args
|
115
123
|
end
|
116
124
|
|
117
125
|
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.4
|
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.15
|
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.15
|
13
27
|
description:
|
14
28
|
email:
|
15
29
|
- gems@shopify.com
|