sass-embedded 1.62.0 → 1.62.1

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: 4b3d0d1ba450405b09e53f216d1e0997dcb5474b8fc4b28bd0995d9af22dffe2
4
- data.tar.gz: 8ac843704ab8d7ab5a4468e9f7783e78aa0ea9f66eaf2193b315505fef01f1d0
3
+ metadata.gz: a23ad45f24f41d4cff9b9a89bdfb5d59fdd1c8ccc651bd3f95819a816aa2d3dc
4
+ data.tar.gz: 6eea5962316620e2fba19fd7e6a655205af9000110f9984dfe3db7e453e9d7b3
5
5
  SHA512:
6
- metadata.gz: 2e832441f74f534c8598b3da5eba98c0b693c808b6834c7d194f3694642b58607aa4c55e21dd69905a64ed730b599addce1262bf22935fec63dc068380ebf951
7
- data.tar.gz: 66dfe65efef95810ad39f5143e6abca7c918158db3d782c5a811fba9ad5e673a299b23f2111282c3daa95ab3eebb013d97fb9ab25ba7f3b1f825b0e59604499e
6
+ metadata.gz: d5cc1925d0eac966d08f4bd4e8bf52c29a131f4d94f98c7cec55f21d47b9dfae23c9d80de35403f5ed01093036c2c852141acc5f6a960c6d11931cc287bf5d96
7
+ data.tar.gz: e559e13e2dd633b8d420fedb57cc6b9dd67bc87a43fef3de2677ee689b9469f672a16c7ab091a87e8565921a152b6d330ae337f1b9456a530c2fcaa9cd746a93
data/ext/sass/Rakefile CHANGED
@@ -21,12 +21,6 @@ file 'sass_embedded' do |t|
21
21
  archive = fetch(ENV.fetch(t.name.upcase) { Configuration.default_sass_embedded })
22
22
  unarchive archive
23
23
  rm archive
24
-
25
- if ENV.key?('NIX_BINTOOLS')
26
- sh 'patchelf',
27
- '--set-interpreter', File.read("#{ENV.fetch('NIX_BINTOOLS')}/nix-support/dynamic-linker").chomp,
28
- (['sass_embedded/src/dart', 'sass_embedded/dart-sass-embedded'].find { |exe| File.exist?(exe) })
29
- end
30
24
  end
31
25
 
32
26
  file 'embedded.rb' => %w[sass_embedded] do |t|
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "sass-embedded": "1.62.0"
3
+ "sass-embedded": "1.62.1"
4
4
  }
5
5
  }
@@ -9,7 +9,16 @@ module Sass
9
9
  # It runs the `dart-sass-embedded` process.
10
10
  class Compiler
11
11
  def initialize
12
- @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(*COMMAND, chdir: __dir__)
12
+ @stdin, @stdout, @stderr, @wait_thread = begin
13
+ Open3.popen3(*COMMAND, chdir: __dir__)
14
+ rescue Errno::ENOENT
15
+ require_relative 'elf'
16
+
17
+ raise if ELF::INTERPRETER.nil?
18
+
19
+ Open3.popen3(ELF::INTERPRETER, *COMMAND, chdir: __dir__)
20
+ end
21
+
13
22
  @stdin.binmode
14
23
  @stdout.binmode
15
24
  @stdin_mutex = Mutex.new
@@ -0,0 +1,275 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Embedded
5
+ # The {ELF} class.
6
+ #
7
+ # It parses ELF header to extract interpreter.
8
+ # @see https://github.com/torvalds/linux/blob/HEAD/include/uapi/linux/elf.h
9
+ # @see https://github.com/torvalds/linux/blob/HEAD/kernel/kexec_elf.c
10
+ class ELF
11
+ # rubocop:disable Naming/ConstantName
12
+
13
+ # 32-bit ELF base types.
14
+ Elf32_Addr = :__u32
15
+ Elf32_Half = :__u16
16
+ Elf32_Off = :__u32
17
+ Elf32_Sword = :__s32
18
+ Elf32_Word = :__u32
19
+
20
+ # 64-bit ELF base types.
21
+ Elf64_Addr = :__u64
22
+ Elf64_Half = :__u16
23
+ Elf64_SHalf = :__s16
24
+ Elf64_Off = :__u64
25
+ Elf64_Sword = :__s32
26
+ Elf64_Word = :__u32
27
+ Elf64_Xword = :__u64
28
+ Elf64_Sxword = :__s64
29
+
30
+ # rubocop:enable Naming/ConstantName
31
+
32
+ # These constants are for the segment types stored in the image headers
33
+ PT_NULL = 0
34
+ PT_LOAD = 1
35
+ PT_DYNAMIC = 2
36
+ PT_INTERP = 3
37
+ PT_NOTE = 4
38
+ PT_SHLIB = 5
39
+ PT_PHDR = 6
40
+ PT_TLS = 7
41
+ PT_LOOS = 0x60000000
42
+ PT_HIOS = 0x6fffffff
43
+ PT_LOPROC = 0x70000000
44
+ PT_HIPROC = 0x7fffffff
45
+ PT_GNU_EH_FRAME = (PT_LOOS + 0x474e550)
46
+ PT_GNU_STACK = (PT_LOOS + 0x474e551)
47
+ PT_GNU_RELRO = (PT_LOOS + 0x474e552)
48
+ PT_GNU_PROPERTY = (PT_LOOS + 0x474e553)
49
+
50
+ # These constants define the different elf file types
51
+ ET_NONE = 0
52
+ ET_REL = 1
53
+ ET_EXEC = 2
54
+ ET_DYN = 3
55
+ ET_CORE = 4
56
+ ET_LOPROC = 0xff00
57
+ ET_HIPROC = 0xffff
58
+
59
+ EI_NIDENT = 16
60
+
61
+ # rubocop:disable Naming/ConstantName
62
+
63
+ Elf32_Ehdr = [
64
+ [:unsigned_char, :e_ident, EI_NIDENT],
65
+ [Elf32_Half, :e_type],
66
+ [Elf32_Half, :e_machine],
67
+ [Elf32_Word, :e_version],
68
+ [Elf32_Addr, :e_entry],
69
+ [Elf32_Off, :e_phoff],
70
+ [Elf32_Off, :e_shoff],
71
+ [Elf32_Word, :e_flags],
72
+ [Elf32_Half, :e_ehsize],
73
+ [Elf32_Half, :e_phentsize],
74
+ [Elf32_Half, :e_phnum],
75
+ [Elf32_Half, :e_shentsize],
76
+ [Elf32_Half, :e_shnum],
77
+ [Elf32_Half, :e_shstrndx]
78
+ ].freeze
79
+
80
+ Elf64_Ehdr = [
81
+ [:unsigned_char, :e_ident, EI_NIDENT],
82
+ [Elf64_Half, :e_type],
83
+ [Elf64_Half, :e_machine],
84
+ [Elf64_Word, :e_version],
85
+ [Elf64_Addr, :e_entry],
86
+ [Elf64_Off, :e_phoff],
87
+ [Elf64_Off, :e_shoff],
88
+ [Elf64_Word, :e_flags],
89
+ [Elf64_Half, :e_ehsize],
90
+ [Elf64_Half, :e_phentsize],
91
+ [Elf64_Half, :e_phnum],
92
+ [Elf64_Half, :e_shentsize],
93
+ [Elf64_Half, :e_shnum],
94
+ [Elf64_Half, :e_shstrndx]
95
+ ].freeze
96
+
97
+ Elf32_Phdr = [
98
+ [Elf32_Word, :p_type],
99
+ [Elf32_Off, :p_offset],
100
+ [Elf32_Addr, :p_vaddr],
101
+ [Elf32_Addr, :p_paddr],
102
+ [Elf32_Word, :p_filesz],
103
+ [Elf32_Word, :p_memsz],
104
+ [Elf32_Word, :p_flags],
105
+ [Elf32_Word, :p_align]
106
+ ].freeze
107
+
108
+ Elf64_Phdr = [
109
+ [Elf64_Word, :p_type],
110
+ [Elf64_Word, :p_flags],
111
+ [Elf64_Off, :p_offset],
112
+ [Elf64_Addr, :p_vaddr],
113
+ [Elf64_Addr, :p_paddr],
114
+ [Elf64_Xword, :p_filesz],
115
+ [Elf64_Xword, :p_memsz],
116
+ [Elf64_Xword, :p_align]
117
+ ].freeze
118
+
119
+ # rubocop:enable Naming/ConstantName
120
+
121
+ # e_ident[] indexes
122
+ EI_MAG0 = 0
123
+ EI_MAG1 = 1
124
+ EI_MAG2 = 2
125
+ EI_MAG3 = 3
126
+ EI_CLASS = 4
127
+ EI_DATA = 5
128
+ EI_VERSION = 6
129
+ EI_OSABI = 7
130
+ EI_PAD = 8
131
+
132
+ # EI_MAG
133
+ ELFMAG0 = 0x7f
134
+ ELFMAG1 = 'E'.ord
135
+ ELFMAG2 = 'L'.ord
136
+ ELFMAG3 = 'F'.ord
137
+ ELFMAG = [ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3].pack('C*')
138
+ SELFMAG = 4
139
+
140
+ # e_ident[EI_CLASS]
141
+ ELFCLASSNONE = 0
142
+ ELFCLASS32 = 1
143
+ ELFCLASS64 = 2
144
+ ELFCLASSNUM = 3
145
+
146
+ # e_ident[EI_DATA]
147
+ ELFDATANONE = 0
148
+ ELFDATA2LSB = 1
149
+ ELFDATA2MSB = 2
150
+
151
+ def initialize(buffer)
152
+ @buffer = buffer
153
+ @ehdr = read_ehdr
154
+ @buffer.seek(@ehdr[:e_phoff], :SET)
155
+ @proghdrs = Array.new(@ehdr[:e_phnum]) do
156
+ read_phdr
157
+ end
158
+ end
159
+
160
+ def relocatable?
161
+ @ehdr[:e_type] == ET_REL
162
+ end
163
+
164
+ def executable?
165
+ @ehdr[:e_type] == ET_EXEC
166
+ end
167
+
168
+ def shared_object?
169
+ @ehdr[:e_type] == ET_DYN
170
+ end
171
+
172
+ def core?
173
+ @ehdr[:e_type] == ET_CORE
174
+ end
175
+
176
+ def interpreter
177
+ phdr = @proghdrs.find { |p| p[:p_type] == PT_INTERP }
178
+ return if phdr.nil?
179
+
180
+ @buffer.seek(phdr[:p_offset], :SET)
181
+ interpreter = @buffer.read(phdr[:p_filesz])
182
+ raise ArgumentError unless interpreter.end_with?("\0")
183
+
184
+ interpreter.chomp("\0")
185
+ end
186
+
187
+ private
188
+
189
+ def file_class
190
+ @ehdr[:e_ident][EI_CLASS]
191
+ end
192
+
193
+ def data_encoding
194
+ @ehdr[:e_ident][EI_DATA]
195
+ end
196
+
197
+ def read_ehdr
198
+ @ehdr = { e_ident: @buffer.read(EI_NIDENT).unpack('C*') }
199
+ raise ArgumentError unless @ehdr[:e_ident].slice(EI_MAG0, SELFMAG).pack('C*') == ELFMAG
200
+
201
+ case file_class
202
+ when ELFCLASS32
203
+ Elf32_Ehdr
204
+ when ELFCLASS64
205
+ Elf64_Ehdr
206
+ else
207
+ raise ArgumentError
208
+ end.drop(1).to_h do |field|
209
+ [field[1], read1(field[0])]
210
+ end.merge!(@ehdr)
211
+ end
212
+
213
+ def read_phdr
214
+ case file_class
215
+ when ELFCLASS32
216
+ Elf32_Phdr
217
+ when ELFCLASS64
218
+ Elf64_Phdr
219
+ else
220
+ raise ArgumentError
221
+ end.to_h do |field|
222
+ [field[1], read1(field[0])]
223
+ end
224
+ end
225
+
226
+ def read1(type)
227
+ case data_encoding
228
+ when ELFDATA2LSB
229
+ case type
230
+ when :__u16
231
+ @buffer.read(2).unpack1('v*')
232
+ when :__u32
233
+ @buffer.read(4).unpack1('V*')
234
+ when :__u64
235
+ buffer = @buffer.read(8).unpack('V*')
236
+ (buffer[1] << 32) | buffer[0]
237
+ else
238
+ raise ArgumentError
239
+ end
240
+ when ELFDATA2MSB
241
+ case type
242
+ when :__u16
243
+ @buffer.read(2).unpack1('n*')
244
+ when :__u32
245
+ @buffer.read(4).unpack1('N*')
246
+ when :__u64
247
+ buffer = @buffer.read(8).unpack('N*')
248
+ (buffer[0] << 32) | buffer[1]
249
+ else
250
+ raise ArgumentError
251
+ end
252
+ else
253
+ raise ArgumentError
254
+ end
255
+ end
256
+
257
+ INTERPRETER = proc do
258
+ proc_self_exe = '/proc/self/exe'
259
+ if File.exist?(proc_self_exe)
260
+ File.open(proc_self_exe, 'rb') do |exe|
261
+ elf = ELF.new(exe)
262
+ interpreter = elf.interpreter
263
+ if interpreter.nil? && elf.shared_object?
264
+ File.readlink(proc_self_exe)
265
+ else
266
+ interpreter
267
+ end
268
+ end
269
+ end
270
+ end.call
271
+ end
272
+
273
+ private_constant :ELF
274
+ end
275
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sass
4
4
  class Embedded
5
- VERSION = '1.62.0'
5
+ VERSION = '1.62.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass-embedded
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.62.0
4
+ version: 1.62.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-12 00:00:00.000000000 Z
11
+ date: 2023-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 2.19.0
103
+ version: 2.20.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 2.19.0
110
+ version: 2.20.0
111
111
  description: A Ruby library that will communicate with Embedded Dart Sass using the
112
112
  Embedded Sass protocol.
113
113
  email:
@@ -131,6 +131,7 @@ files:
131
131
  - lib/sass/embedded/channel.rb
132
132
  - lib/sass/embedded/compiler.rb
133
133
  - lib/sass/embedded/dispatcher.rb
134
+ - lib/sass/embedded/elf.rb
134
135
  - lib/sass/embedded/host.rb
135
136
  - lib/sass/embedded/host/function_registry.rb
136
137
  - lib/sass/embedded/host/importer_registry.rb
@@ -160,8 +161,8 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
160
161
  licenses:
161
162
  - MIT
162
163
  metadata:
163
- documentation_uri: https://rubydoc.info/gems/sass-embedded/1.62.0
164
- source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v1.62.0
164
+ documentation_uri: https://rubydoc.info/gems/sass-embedded/1.62.1
165
+ source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v1.62.1
165
166
  funding_uri: https://github.com/sponsors/ntkme
166
167
  post_install_message:
167
168
  rdoc_options: []