-
Notifications
You must be signed in to change notification settings - Fork 9
/
sass.rb
91 lines (74 loc) · 2.6 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
83
84
85
86
87
88
89
90
91
# 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.77.8.tar.gz"
sha256 "eba4e5a86e7351321dd90923237df3a87f8769014fb8d9357dee77004b42b13b"
license "MIT"
head "https://github.com/sass/dart-sass.git", branch: "main"
depends_on "buf" => :build
depends_on "dart-lang/dart/dart" => :build
resource "language" do
url "https://github.com/sass/sass.git",
revision: "a39dbad4ff95df5d105db52f3cb91360b2bcf0ee"
end
def install
# Tell the pub server where these installations are coming from.
ENV["PUB_ENVIRONMENT"] = "homebrew:sass"
(buildpath/'build/language').install resource("language")
system _dart/"dart", "pub", "get"
ENV["UPDATE_SASS_PROTOCOL"] = "false"
system _dart/"dart", "run", "grinder", "protobuf"
ENV.delete "UPDATE_SASS_PROTOCOL"
# 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