forked from Homebrew/homebrew-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagda.rb
160 lines (124 loc) · 4.82 KB
/
agda.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class Agda < Formula
desc "Dependently typed functional programming language"
homepage "https://wiki.portal.chalmers.se/agda/"
license "BSD-3-Clause"
stable do
url "https://hackage.haskell.org/package/Agda-2.6.2.1/Agda-2.6.2.1.tar.gz"
sha256 "3c4146539e1f2561a05896e3c18a7d0262d98a28f5c5adcc8cce8d8c9d3cbc0d"
resource "stdlib" do
url "https://github.com/agda/agda-stdlib/archive/v1.7.1.tar.gz"
sha256 "6f92ae14664e5d1217e8366c647eb23ca88bc3724278f22dc6b80c23cace01df"
end
end
bottle do
sha256 arm64_monterey: "265f641da45f9692a4adb6324455315a4f3e679968452fdd279ec1f177768585"
sha256 arm64_big_sur: "8076dab57cf328b2f101bbec616c1465e9e1334e7f89fe97a1c65cb688a343cd"
sha256 monterey: "422bcf016bb915c1887d8e1b5429d113ca0ce14f180db0cd2c027292bbe52195"
sha256 big_sur: "482995407f169a1ac2e9e6bb820f91593ba3bd56394deb142bee001b9974cbb2"
sha256 catalina: "c1c94d764cb76bb657b098f2ba07450f4b93114d64f5ca2d839fedc522513ded"
sha256 x86_64_linux: "33c77a87ac06685d06baeb0d975aa68704cdea4acb1da0e8beae44aed10591ae"
end
head do
url "https://github.com/agda/agda.git"
resource "stdlib" do
url "https://github.com/agda/agda-stdlib.git"
end
end
depends_on "cabal-install"
depends_on "emacs"
depends_on "ghc"
uses_from_macos "zlib"
resource "alex" do
url "https://hackage.haskell.org/package/alex-3.2.6/alex-3.2.6.tar.gz"
sha256 "91aa08c1d3312125fbf4284815189299bbb0be34421ab963b1f2ae06eccc5410"
end
resource "cpphs" do
url "https://hackage.haskell.org/package/cpphs-1.20.9.1/cpphs-1.20.9.1.tar.gz"
sha256 "7f59b10bc3374004cee3c04fa4ee4a1b90d0dca84a3d0e436d5861a1aa3b919f"
end
resource "happy" do
url "https://hackage.haskell.org/package/happy-1.20.0/happy-1.20.0.tar.gz"
sha256 "3b1d3a8f93a2723b554d9f07b2cd136be1a7b2fcab1855b12b7aab5cbac8868c"
end
def install
ENV["CABAL_DIR"] = prefix/"cabal"
system "cabal", "v2-update"
cabal_args = std_cabal_v2_args.reject { |s| s["installdir"] }
# happy must be installed before alex
%w[happy alex cpphs].each do |r|
r_installdir = libexec/r/"bin"
ENV.prepend_path "PATH", r_installdir
resource(r).stage do
mkdir r_installdir
system "cabal", "v2-install", *cabal_args, "--installdir=#{r_installdir}"
end
end
system "cabal", "v2-install", "-f", "cpphs", *std_cabal_v2_args
# generate the standard library's documentation and vim highlighting files
resource("stdlib").stage lib/"agda"
cd lib/"agda" do
system "cabal", "v2-install", *cabal_args, "--installdir=#{lib}/agda"
system "./GenerateEverything"
system bin/"agda", "-i", ".", "-i", "src", "--html", "--vim", "README.agda"
end
# Clean up references to Homebrew shims
rm_rf "#{lib}/agda/dist-newstyle/cache"
end
test do
simpletest = testpath/"SimpleTest.agda"
simpletest.write <<~EOS
module SimpleTest where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
infixl 6 _+_
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
infix 4 _≡_
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
cong : ∀ {A B : Set} (f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
+-assoc : ∀ m n o → (m + n) + o ≡ m + (n + o)
+-assoc zero _ _ = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
EOS
stdlibtest = testpath/"StdlibTest.agda"
stdlibtest.write <<~EOS
module StdlibTest where
open import Data.Nat
open import Relation.Binary.PropositionalEquality
+-assoc : ∀ m n o → (m + n) + o ≡ m + (n + o)
+-assoc zero _ _ = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
EOS
iotest = testpath/"IOTest.agda"
iotest.write <<~EOS
module IOTest where
open import Agda.Builtin.IO
open import Agda.Builtin.Unit
postulate
return : ∀ {A : Set} → A → IO A
{-# COMPILE GHC return = \\_ -> return #-}
main : _
main = return tt
EOS
# we need a test-local copy of the stdlib as the test writes to
# the stdlib directory
resource("stdlib").stage testpath/"lib/agda"
# typecheck a simple module
system bin/"agda", simpletest
# typecheck a module that uses the standard library
system bin/"agda", "-i", testpath/"lib/agda/src", stdlibtest
# compile a simple module using the JS backend
system bin/"agda", "--js", simpletest
# test the GHC backend
cabal_args = std_cabal_v2_args.reject { |s| s["installdir"] }
system "cabal", "v2-update"
system "cabal", "v2-install", "ieee754", "--lib", *cabal_args
# compile and run a simple program
system bin/"agda", "-c", iotest
assert_equal "", shell_output(testpath/"IOTest")
end
end