Skip to content

Commit a550628

Browse files
committed
Launch elf interpreter explicitly on nixos
1 parent 0e4c035 commit a550628

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

exe/sass

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ require_relative '../ext/sass/cli'
66
module Sass
77
# The `sass` command line interface
88
module CLI
9-
begin
10-
Kernel.exec(*COMMAND, *ARGV)
11-
rescue Errno::ENOENT
12-
require_relative '../lib/sass/elf'
13-
14-
raise if ELF::INTERPRETER.nil?
15-
16-
Kernel.exec(ELF::INTERPRETER, *COMMAND, *ARGV)
17-
end
9+
Kernel.exec(*COMMAND, *ARGV)
1810
end
1911

2012
private_constant :CLI

ext/sass/Rakefile

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ rescue StandardError
3030
end
3131

3232
file 'cli.rb' => %w[dart-sass] do |t|
33+
require_relative '../../lib/sass/elf'
34+
3335
exe = 'dart-sass/sass'
3436
exe = "#{exe}#{['', '.bat', '.exe'].find { |ext| File.exist?("#{exe}#{ext}") }}"
3537

@@ -39,28 +41,57 @@ file 'cli.rb' => %w[dart-sass] do |t|
3941
runtime = "#{runtime}#{['', '.exe'].find { |ext| File.exist?("#{runtime}#{ext}") }}"
4042
snapshot = 'dart-sass/src/sass.snapshot'
4143

42-
command = if File.exist?(runtime) && File.exist?(snapshot)
43-
"
44+
if File.exist?(runtime) && File.exist?(snapshot)
45+
command = "
4446
File.absolute_path('#{runtime}', __dir__).freeze,
4547
File.absolute_path('#{snapshot}', __dir__).freeze
4648
"
47-
else
48-
"
49+
interpreter = File.open(runtime, 'rb') do |file|
50+
Sass.const_get(:ELF).new(file).interpreter
51+
rescue ArgumentError
52+
nil
53+
end
54+
else
55+
command = "
4956
File.absolute_path('#{exe}', __dir__).freeze
5057
"
51-
end
58+
interpreter = nil
59+
end
5260

53-
File.write(t.name, <<~CLI_RB)
54-
# frozen_string_literal: true
61+
if interpreter.nil?
62+
File.write(t.name, <<~CLI_RB)
63+
# frozen_string_literal: true
5564
56-
module Sass
57-
module CLI
58-
COMMAND = [#{command}].freeze
65+
module Sass
66+
# The [CLI] module.
67+
module CLI
68+
COMMAND = [#{command}].freeze
69+
end
70+
71+
private_constant :CLI
5972
end
73+
CLI_RB
74+
else
75+
File.write(t.name, <<~CLI_RB)
76+
# frozen_string_literal: true
6077
61-
private_constant :CLI
62-
end
63-
CLI_RB
78+
require_relative '../../lib/sass/elf'
79+
80+
module Sass
81+
# The [CLI] module.
82+
module CLI
83+
INTERPRETER = '#{interpreter}'
84+
85+
COMMAND = [
86+
*(ELF::INTERPRETER unless ELF::INTERPRETER.nil? ||
87+
ELF::INTERPRETER == INTERPRETER ||
88+
File.basename(ELF::INTERPRETER) != File.basename(INTERPRETER)),#{command}].freeze
89+
end
90+
91+
private_constant :CLI
92+
end
93+
CLI_RB
94+
end
6495
end
6596

6697
file 'embedded_sass.proto' => %w[cli.rb] do |t|

lib/sass/compiler/connection.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ class Compiler
1212
class Connection
1313
def initialize
1414
@mutex = Mutex.new
15-
@stdin, @stdout, @stderr, @wait_thread = begin
16-
Open3.popen3(*CLI::COMMAND, '--embedded', chdir: __dir__)
17-
rescue Errno::ENOENT
18-
require_relative '../elf'
19-
20-
raise if ELF::INTERPRETER.nil?
21-
22-
Open3.popen3(ELF::INTERPRETER, *CLI::COMMAND, '--embedded', chdir: __dir__)
23-
end
15+
@stdin, @stdout, @stderr, @wait_thread = Open3.popen3(*CLI::COMMAND, '--embedded', chdir: __dir__)
2416

2517
@stdin.binmode
2618

lib/sass/elf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def read(type, little_endian)
215215
end
216216
end
217217
end
218-
end
218+
end.freeze
219219
end
220220

221221
private_constant :ELF

0 commit comments

Comments
 (0)