binaryen 1.1.6.10 → 1.1.6.12
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 +53 -68
- data/lib/binaryen/error.rb +1 -0
- data/lib/binaryen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeb3dcecc8a8a66da44273ff8440bb951eae7bb2abb227b754dd78e7b2b24ae4
|
4
|
+
data.tar.gz: 2154294d63c97358fdf3f1dcbd25e7afe92368d05bb3fb12299e6ffeee088420
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff121e7ba9acbe92590726f82ea50d5f5a31e2c7c0225a973fb6f34ba22f17d2da8315666d4ab5e84482efe0cdcb685a952a0dc9062fd313a9bdcac737e81cc5
|
7
|
+
data.tar.gz: 268acda447d3979778e7c391ff659da4c798e48da5a952d021aa74761630ab62be2631970cfae12b48c4afd97442dab195c1cc7630f55efaf79842c73271654f
|
data/lib/binaryen/command.rb
CHANGED
@@ -9,10 +9,7 @@ module Binaryen
|
|
9
9
|
include POSIX::Spawn
|
10
10
|
DEFAULT_MAX_OUTPUT_SIZE = 256 * 1024 * 1024 * 1024 # 256 MiB
|
11
11
|
DEFAULT_TIMEOUT = 10
|
12
|
-
DEFAULT_ARGS_FOR_COMMAND = {
|
13
|
-
"wasm-opt" => ["--output=-"],
|
14
|
-
}.freeze
|
15
|
-
BUFSIZE = 32 * 1024
|
12
|
+
DEFAULT_ARGS_FOR_COMMAND = {}.freeze
|
16
13
|
|
17
14
|
def initialize(cmd, timeout: DEFAULT_TIMEOUT, max_output_size: DEFAULT_MAX_OUTPUT_SIZE, ignore_missing: false)
|
18
15
|
@cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
|
@@ -23,83 +20,71 @@ module Binaryen
|
|
23
20
|
|
24
21
|
def run(*arguments, stdin: nil, stderr: nil)
|
25
22
|
args = [@cmd] + arguments + @default_args
|
26
|
-
|
27
|
-
|
28
|
-
with_stdin_tempfile(stdin) { |path| spawn_command(*args, path, stderr: stderr) }
|
29
|
-
else
|
30
|
-
spawn_command(*args, stderr: stderr)
|
23
|
+
Timeout.timeout(@timeout) do
|
24
|
+
spawn_command(*args, stderr: stderr, stdin: stdin)
|
31
25
|
end
|
32
26
|
end
|
33
27
|
|
34
28
|
private
|
35
29
|
|
36
|
-
def with_stdin_tempfile(content)
|
37
|
-
Tempfile.open("binaryen-stdin") do |f|
|
38
|
-
f.binmode
|
39
|
-
f.write(content)
|
40
|
-
f.close
|
41
|
-
yield f.path
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
30
|
def command_path(cmd, ignore_missing)
|
46
31
|
Dir[File.join(Binaryen.bindir, cmd)].first || (ignore_missing && cmd)
|
47
32
|
end
|
48
33
|
|
49
|
-
def spawn_command(*args, stderr: nil)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
34
|
+
def spawn_command(*args, stderr: nil, stdin: nil)
|
35
|
+
pid = nil
|
36
|
+
|
37
|
+
IO.pipe do |in_read, in_write|
|
38
|
+
in_read.binmode
|
39
|
+
in_write.binmode
|
40
|
+
in_write.sync = true
|
41
|
+
in_write.write(stdin) if stdin
|
42
|
+
|
43
|
+
Tempfile.create("binaryen-output") do |tmpfile|
|
44
|
+
tmpfile.close
|
45
|
+
|
46
|
+
File.open(File::NULL, "w") do |devnull|
|
47
|
+
IO.pipe do |err_read, err_write|
|
48
|
+
pid = POSIX::Spawn.pspawn(*args, "--output=#{tmpfile.path}", in: in_read, out: devnull, err: err_write)
|
49
|
+
in_read.close
|
50
|
+
err_write.close
|
51
|
+
in_write.close
|
52
|
+
|
53
|
+
_, status = Process.waitpid2(pid)
|
54
|
+
pid = nil
|
55
|
+
|
56
|
+
stderr&.write(err_read.read)
|
57
|
+
err_read.close
|
58
|
+
|
59
|
+
if status.signaled?
|
60
|
+
raise Binaryen::Signal, "command terminated by signal #{status.termsig}"
|
61
|
+
elsif status.exited? && !status.success?
|
62
|
+
raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}"
|
63
|
+
elsif File.size(tmpfile.path) > @max_output_size
|
64
|
+
raise Binaryen::MaximumOutputExceeded, "maximum output size exceeded (#{@max_output_size} bytes)"
|
65
|
+
end
|
66
|
+
|
67
|
+
File.binread(tmpfile.path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
rescue
|
71
|
+
if pid
|
72
|
+
begin
|
73
|
+
Process.kill(:KILL, pid)
|
74
|
+
rescue SystemCallError
|
75
|
+
# Expected
|
76
|
+
end
|
77
|
+
|
78
|
+
begin
|
79
|
+
Process.wait(pid, Process::WNOHANG)
|
80
|
+
rescue SystemCallError
|
81
|
+
# Expected
|
82
|
+
end
|
76
83
|
end
|
77
|
-
rescue Errno::EINTR
|
78
|
-
# This means that the read was interrupted by a signal, which is not an error. So we just retry.
|
79
|
-
end
|
80
|
-
|
81
|
-
if out.bytesize > @max_output_size
|
82
|
-
Process.kill("TERM", pid)
|
83
|
-
raise Binaryen::MaximumOutputExceeded, "maximum output size exceeded (#{@max_output_size} bytes)"
|
84
|
-
end
|
85
84
|
|
86
|
-
|
87
|
-
Process.kill("TERM", pid)
|
88
|
-
raise Timeout::Error, "command timed out after #{@timeout} seconds"
|
85
|
+
raise
|
89
86
|
end
|
90
87
|
end
|
91
|
-
|
92
|
-
_, status = Process.waitpid2(pid, Process::WUNTRACED)
|
93
|
-
|
94
|
-
raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}" unless status.success?
|
95
|
-
|
96
|
-
out
|
97
|
-
ensure
|
98
|
-
[stdin, stdout, stderr_stream].each do |io|
|
99
|
-
io.close
|
100
|
-
rescue
|
101
|
-
nil
|
102
|
-
end
|
103
88
|
end
|
104
89
|
end
|
105
90
|
end
|
data/lib/binaryen/error.rb
CHANGED
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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: posix-spawn
|