binaryen 1.1.6.9 → 1.1.6.11
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 +52 -70
- 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: d2514a32fe0aa37ddffcc4da057a610ccac94f7e4a43318b3979d3c72788b165
|
4
|
+
data.tar.gz: 6da6579ae2cdba43f375ed3795e41da20b12e4854ed9c3c22b43bd92cb6fa8e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d0c1f916e3e38511bac7e28325f20e8dabec9666bd154f14d06a6c346640431596d44d0c63f603966f470a4c526037c9a29d2c70172605ffb3690af56cfcbf7
|
7
|
+
data.tar.gz: 4ddc9df067ee8354a995a9cf7eb09ea27ce54455dd266266149192e2c45564f1969c21f601f719f3ff45e34a2649e490c09aee28118c1b24a1a283458302e70b
|
data/lib/binaryen/command.rb
CHANGED
@@ -7,11 +7,9 @@ require "tempfile"
|
|
7
7
|
module Binaryen
|
8
8
|
class Command
|
9
9
|
include POSIX::Spawn
|
10
|
-
DEFAULT_MAX_OUTPUT_SIZE = 256 * 1024 * 1024
|
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
|
12
|
+
DEFAULT_ARGS_FOR_COMMAND = {}.freeze
|
15
13
|
|
16
14
|
def initialize(cmd, timeout: DEFAULT_TIMEOUT, max_output_size: DEFAULT_MAX_OUTPUT_SIZE, ignore_missing: false)
|
17
15
|
@cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
|
@@ -22,86 +20,70 @@ module Binaryen
|
|
22
20
|
|
23
21
|
def run(*arguments, stdin: nil, stderr: nil)
|
24
22
|
args = [@cmd] + arguments + @default_args
|
25
|
-
|
26
|
-
|
27
|
-
with_stdin_tempfile(stdin) { |path| spawn_command(*args, path, stderr: stderr) }
|
28
|
-
else
|
29
|
-
spawn_command(*args, stderr: stderr)
|
23
|
+
Timeout.timeout(@timeout) do
|
24
|
+
spawn_command(*args, stderr: stderr, stdin: stdin)
|
30
25
|
end
|
31
26
|
end
|
32
27
|
|
33
28
|
private
|
34
29
|
|
35
|
-
def with_stdin_tempfile(content)
|
36
|
-
Tempfile.open("binaryen-stdin") do |f|
|
37
|
-
f.binmode
|
38
|
-
f.write(content)
|
39
|
-
f.close
|
40
|
-
yield f.path
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
30
|
def command_path(cmd, ignore_missing)
|
45
31
|
Dir[File.join(Binaryen.bindir, cmd)].first || (ignore_missing && cmd)
|
46
32
|
end
|
47
33
|
|
48
|
-
def spawn_command(*args, stderr: nil)
|
49
|
-
|
50
|
-
data_buffer = "".b
|
51
|
-
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
52
|
-
pid, stdin, stdout, stderr_stream = popen4(*args)
|
53
|
-
stdin.close
|
54
|
-
@pid = pid
|
55
|
-
readers = [stdout, stderr_stream]
|
56
|
-
|
57
|
-
while readers.any?
|
58
|
-
elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
|
59
|
-
remaining_time = @timeout - elapsed_time
|
60
|
-
ready = IO.select(readers, nil, nil, remaining_time)
|
61
|
-
raise Timeout::Error, "command timed out after #{@timeout} seconds" if ready.nil?
|
62
|
-
|
63
|
-
ready[0].each do |io|
|
64
|
-
max_amount_to_read = @max_output_size - out.bytesize + 1
|
65
|
-
data = io.read_nonblock(max_amount_to_read, data_buffer, exception: false)
|
66
|
-
|
67
|
-
if data == :wait_readable
|
68
|
-
# If the IO object is not ready for reading, read_nonblock returns :wait_readable.
|
69
|
-
# This isn't an error, but a notification.
|
70
|
-
next
|
71
|
-
elsif data.nil?
|
72
|
-
# At EOF, read_nonblock returns nil instead of raising EOFError.
|
73
|
-
readers.delete(io)
|
74
|
-
io.close
|
75
|
-
elsif io == stdout
|
76
|
-
out << data_buffer
|
77
|
-
elsif io == stderr_stream && stderr
|
78
|
-
stderr << data_buffer
|
79
|
-
end
|
80
|
-
rescue Errno::EINTR
|
81
|
-
# This means that the read was interrupted by a signal, which is not an error. So we just retry.
|
82
|
-
end
|
34
|
+
def spawn_command(*args, stderr: nil, stdin: nil)
|
35
|
+
pid = nil
|
83
36
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
37
|
+
IO.pipe do |in_read, in_write|
|
38
|
+
in_read.binmode
|
39
|
+
in_write.binmode
|
88
40
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
41
|
+
Tempfile.create("binaryen") do |tmpfile|
|
42
|
+
tmpfile.close
|
43
|
+
|
44
|
+
File.open(File::NULL, "w") do |devnull|
|
45
|
+
IO.pipe do |err_read, err_write|
|
46
|
+
pid = POSIX::Spawn.pspawn(*args, "--output=#{tmpfile.path}", in: in_read, out: devnull, err: err_write)
|
47
|
+
in_read.close
|
48
|
+
err_write.close
|
49
|
+
|
50
|
+
in_write.write(stdin) if stdin
|
51
|
+
in_write.close
|
52
|
+
|
53
|
+
_, status = Process.waitpid2(pid)
|
54
|
+
pid = nil
|
94
55
|
|
95
|
-
|
56
|
+
stderr&.write(err_read.read)
|
57
|
+
err_read.close
|
96
58
|
|
97
|
-
|
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
|
98
66
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
83
|
+
end
|
84
|
+
|
85
|
+
raise
|
86
|
+
end
|
105
87
|
end
|
106
88
|
end
|
107
89
|
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.11
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: posix-spawn
|