-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunison-language.rb
137 lines (120 loc) · 4.66 KB
/
unison-language.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class UnisonLanguage < Formula
desc "Unison [Language] and Codebase Manager"
homepage "https://unisonweb.org"
license "MIT"
version_scheme 2
version "0.5.31"
on_macos do
if Hardware::CPU.intel?
url "https://github.com/unisonweb/unison/releases/download/release%2F0.5.31/ucm-macos-x64.tar.gz"
sha256 "7165182672c916b0265e2b8607a68c2ae83feae22ba0a37115770ed3575af47a"
head "https://github.com/unisonweb/unison/releases/download/trunk-build/ucm-macos-x64.tar.gz"
elsif Hardware::CPU.arm?
url "https://github.com/unisonweb/unison/releases/download/release%2F0.5.31/ucm-macos-arm64.tar.gz"
sha256 "1fb3d4da43d82014e7a3482967707b20b47ad9fd053d6ebddb3385f7e5b25fda"
head "https://github.com/unisonweb/unison/releases/download/trunk-build/ucm-macos-arm64.tar.gz"
else
odie "Unsupported architecture for ucm"
end
end
on_linux do
url "https://github.com/unisonweb/unison/releases/download/release%2F0.5.31/ucm-linux-x64.tar.gz"
sha256 "528ee3d129b072eb9fa330f83d1015c44559972bebeaa290aa45f7f0b6aab342"
head "https://github.com/unisonweb/unison/releases/download/trunk-build/ucm-linux-x64.tar.gz"
end
option "with-compile-native", "experimental support for `compile.native`"
if build.with? "compile-native"
depends_on "libb2"
end
depends_on "fzf" => :recommended
def install
libexec.install "unison/unison"
libexec.install "runtime"
pkgshare.install "ui"
if build.with? "compile-native"
resource "minimal-racket" do
if OS.linux?
url "https://download.racket-lang.org/releases/8.14/installers/racket-minimal-8.14-x86_64-linux-cs.tgz"
sha256 "a1b5cab3adee21cd00219c7e85315c945db4eab11a6c80653db7687b11c993f0"
elsif OS.mac?
if Hardware::CPU.intel?
url "https://download.racket-lang.org/releases/8.14/installers/racket-minimal-8.14-x86_64-macosx-cs.tgz"
sha256 "168644f90c09b5474a84293e0f81a4b9b2c165cdabb3a5e595953f6b956ec1ed"
elsif Hardware::CPU.arm?
url "https://download.racket-lang.org/releases/8.14/installers/racket-minimal-8.14-aarch64-macosx-cs.tgz"
sha256 "5d3e0c94668889ffb744fa99f7e787b1352de6b30587665cf0a80d34f02e421a"
else
odie "Unsupported architecture for racket"
end
else
odie "Unsupported OS"
end
end
resource("minimal-racket").stage do
(libexec/"racket").install Dir["*"]
(libexec/"racket/lib").install_symlink Formula["libb2"].lib/"libb2.1.dylib"
end
raco = "#{libexec}/racket/bin/raco"
ohai "Installing Racket unison library"
pkgshare.install "racket"
jitlib = "#{pkgshare}/racket/unison.zip"
system raco, "pkg", "install", "--scope", "installation", "--auto", jitlib
ohai "Installing Racket compiler-lib library"
system raco, "pkg", "install", "--scope", "installation", "--auto", "--skip-installed", "compiler-lib"
(bin/"ucm").write <<~EOS
#!/bin/bash
PATH="#{opt_libexec}/racket/bin:$PATH" \\
UCM_WEB_UI="#{pkgshare}/ui" \\
#{opt_libexec}/unison \\
--runtime-path #{opt_libexec}/runtime/bin/unison-runtime \\
"$@"
EOS
else
(bin/"ucm").write <<~EOS
#!/bin/bash
# This installation is not set up for `compile.native`.
UCM_WEB_UI="#{pkgshare}/ui" \\
#{opt_libexec}/unison \\
--runtime-path #{opt_libexec}/runtime/bin/unison-runtime \\
"$@"
EOS
end
end
test do
ohai "Setting up project and downloading base..."
(testpath/"setup.md").write <<~EOS
```ucm
scratch/main> project.create proj
```
```unison
helloWorld = do printLine "Hello, World!"
```
```ucm
proj/main> add
```
EOS
system "ucm", "transcript", "--save-codebase-to", testpath/"codebase", testpath/"setup.md"
ohai "Running helloWorld..."
(testpath/"run.md").write <<~EOS
```ucm
proj/main> run helloWorld
```
```ucm
proj/main> run.native helloWorld
```
EOS
system "ucm", "transcript.fork", "--codebase", testpath/"codebase", testpath/"run.md"
if build.with? "compile-native"
ohai "Compiling helloWorld..."
(testpath/"compile.md").write <<~EOS
```ucm
proj/main> compile.native helloWorld #{testpath/"helloWorld"}
```
EOS
system "ucm", "transcript.fork", "--codebase", testpath/"codebase", testpath/"compile.md"
assert_match "Hello, World!\n", shell_output("#{testpath}/helloWorld")
else
ohai "Skipping `compile.native` test, as it requires `--with-compile-native`."
end
end
end