-
Notifications
You must be signed in to change notification settings - Fork 9
/
sass.rb
82 lines (67 loc) · 2.33 KB
/
sass.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
76
77
78
79
80
81
82
# typed: false
# frozen_string_literal: true
require "yaml"
# A formula for the Sass CLI.
class Sass < Formula
desc "Stylesheet Preprocessor"
homepage "https://sass-lang.com"
url "https://github.com/sass/dart-sass/archive/1.66.1.tar.gz"
sha256 "d9a13a980d4516852d9e624ac8798631fae36cdcf8b684b0d7c01e7d8914824b"
license "MIT"
head "https://github.com/sass/dart-sass.git", branch: "main"
depends_on "buf" => :build
depends_on "dart-lang/dart/dart" => :build
def install
# Tell the pub server where these installations are coming from.
ENV["PUB_ENVIRONMENT"] = "homebrew:sass"
system _dart/"dart", "pub", "get"
system _dart/"dart", "run", "grinder", "protobuf"
# Build a native-code executable on 64-bit systems only. 32-bit Dart
# doesn't support this.
if Hardware::CPU.is_64_bit?
_install_native_executable
else
_install_script_snapshot
end
chmod 0555, "#{bin}/sass"
end
test do
(testpath/"test.scss").write(".class {property: 1 + 1}")
assert_match "property: 2;", shell_output("#{bin}/sass test.scss 2>&1")
end
private
def _dart
@_dart ||= Formula["dart-lang/dart/dart"].libexec/"bin"
end
def _version
@_version ||= YAML.safe_load(File.read("pubspec.yaml"))["version"]
end
def _protocol_version
@_protocol_version ||= File.read("build/language/spec/EMBEDDED_PROTOCOL_VERSION").strip
end
def _install_native_executable
system _dart/"dart", "compile", "exe",
"-Dversion=#{_version}",
"-Dcompiler-version=#{_version}",
"-Dprotocol-version=#{_protocol_version}",
"bin/sass.dart", "-o", "sass"
bin.install "sass"
end
def _install_script_snapshot
system _dart/"dart", "compile", "jit-snapshot",
"-Dversion=#{_version}",
"-Dcompiler-version=#{_version}",
"-Dprotocol-version=#{_protocol_version}",
"-o", "sass.snapshot",
"bin/sass.dart", "--version"
libexec.install "sass.snapshot"
# Copy the version of the Dart VM we used into our lib directory so that if
# the user upgrades their Dart VM version it doesn't break Sass's snapshot,
# which was compiled with an older version.
cp _dart/"dart", libexec
(bin/"sass").write <<~SH
#!/bin/sh
exec "#{libexec}/dart" "#{libexec}/sass.snapshot" "$@"
SH
end
end