binaryen 1.1.6.1 → 1.1.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f28c12d0f3983f4a8856a70bd62767df1021eac072a97edea0174b59648519d1
4
- data.tar.gz: 6973598a0a4d375e1445a6d463853b6a37a4343b735c191fa10b7457cdb4273e
3
+ metadata.gz: ae90a4e59e6f813687257623ab4d4a35633c9409de5459101d8080d65fe1fdf1
4
+ data.tar.gz: 20c161cfa875c14801d03ae2f7a43f5342a0e0a8b9c70f9d9e2d1f44b722f3e7
5
5
  SHA512:
6
- metadata.gz: 31693bb150232527b2ebae35f6a44f72d3af7a02ec3d6370df366226eb7e4b718375db2c832f6fe169a843c1c4b4ced9116d0d4e247a4805d473c01f8d9677a9
7
- data.tar.gz: feac4bb36b20f5b5e0d7907fb2cad013e2c90c23bb5cdb7b233ca0e74407ab558de9f765b2bd8adcbe9148976363b1dca9781b6dbf37dead3f0dac867c36eaad
6
+ metadata.gz: 74f7b3010d06316d25eb8b3e74fc2fd33b60f50fcd3bd6db83db8b11c135e003f49f460779e02992e0826a86240b220d3c8e1c82e56361e1e6d054cc7b172679
7
+ data.tar.gz: 90de5bc2e078f8083116a8dc8244e3807185ff35c1697ef210070bcd4f01d7bf730f13fa1731f479b06032dcc778109faf848a0daa2da0915ab7fe18b033a3e0
@@ -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
- def initialize(cmd, timeout: 10, ignore_missing: false)
22
- @cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
23
- @timeout = timeout
24
- @default_args = DEFAULT_ARGS_FOR_COMMAND.fetch(cmd, [])
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
- output, remaining_timeout = read_from_pipe(pipe, start_time, remaining_timeout)
39
-
40
- wait_or_kill(pid, start_time, remaining_timeout)
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 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]
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 wait_or_kill(pid, start_time, remaining_timeout)
102
- while remaining_timeout > 0
103
- start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
104
-
105
- if (_, status = Process.wait2(pid, Process::WNOHANG))
106
- if status.exitstatus != 0
107
- raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}"
108
- end
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
- Process.kill("KILL", pid)
117
- raise Timeout::Error, "timed out waiting on process"
54
+ child.out
55
+ rescue POSIX::Spawn::TimeoutExceeded => e
56
+ raise Timeout::Error, e.message
118
57
  end
119
58
 
120
- def build_command(*arguments)
121
- Shellwords.join([@cmd] + arguments + @default_args)
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)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binaryen
4
- VERSION = "1.1.6.1"
4
+ VERSION = "1.1.6.3"
5
5
  BINARYEN_VERSION = "version_116"
6
6
  end
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.1
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-02 00:00:00.000000000 Z
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.21
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