201 lines
5.4 KiB
Ruby
201 lines
5.4 KiB
Ruby
require "language/haskell"
|
||
|
||
class Agda < Formula
|
||
include Language::Haskell::Cabal
|
||
|
||
desc "Dependently typed functional programming language"
|
||
homepage "http://wiki.portal.chalmers.se/agda/"
|
||
|
||
stable do
|
||
url "https://github.com/agda/agda.git",
|
||
:revision => "e3f598313ceac6de8903f9e5693efb30435691fc"
|
||
version "2.5.3-alpha1"
|
||
|
||
resource "stdlib" do
|
||
url "https://github.com/agda/agda-stdlib.git",
|
||
:revision => "c47a1516aaf40892f97b14e3fd1f2bd0c628cadc"
|
||
version "2.5.3-alpha1"
|
||
end
|
||
end
|
||
|
||
bottle do
|
||
rebuild 1
|
||
sha256 "d3301d6a282b9ee76525ffda96fd4ce102bc58a00e982bd8888ebddc54bfa440" => :sierra
|
||
sha256 "53b3cc19b25cd4cfa646fafe8637a8e3ca2d920fd82564ae5ab518b358972298" => :el_capitan
|
||
sha256 "4bcb41224b90cb7e0039f0c488a48cf805922abf40e24a7cf5271210e9cddfa3" => :yosemite
|
||
end
|
||
|
||
head do
|
||
url "https://github.com/agda/agda.git"
|
||
|
||
resource "stdlib" do
|
||
url "https://github.com/agda/agda-stdlib.git"
|
||
end
|
||
end
|
||
|
||
deprecated_option "without-malonzo" => "without-ghc"
|
||
deprecated_option "without-ghc@8.0" => "without-ghc"
|
||
|
||
option "without-stdlib", "Don't install the Agda standard library"
|
||
option "without-ghc", "Disable the GHC backend"
|
||
|
||
depends_on "ghc" => :recommended
|
||
if build.with? "ghc"
|
||
depends_on "cabal-install"
|
||
else
|
||
depends_on "ghc" => :build
|
||
depends_on "cabal-install" => :build
|
||
end
|
||
|
||
depends_on :emacs => ["23.4", :recommended]
|
||
|
||
# Upstream issue from 4 Sep 2017 "Agda fails to build with happy 1.19.6"
|
||
# See https://github.com/agda/agda/issues/2731
|
||
resource "cabal-config" do
|
||
url "https://www.stackage.org/lts-9.1/cabal.config"
|
||
version "lts-9.1"
|
||
sha256 "615e2a56ffd64d169fcc59f02a068d579bf5bdd83b13fd6746e20b8fdc79a738"
|
||
end
|
||
|
||
def install
|
||
buildpath.install resource("cabal-config")
|
||
inreplace "cabal.config", " Agda ==2.5.2,\n", ""
|
||
|
||
# install Agda core
|
||
install_cabal_package :using => ["alex", "happy", "cpphs"]
|
||
|
||
if build.with? "stdlib"
|
||
resource("stdlib").stage lib/"agda"
|
||
|
||
# generate the standard library's bytecode
|
||
cd lib/"agda" do
|
||
cabal_sandbox :home => buildpath, :keep_lib => true do
|
||
cabal_install "--only-dependencies"
|
||
cabal_install
|
||
system "GenerateEverything"
|
||
end
|
||
end
|
||
|
||
# generate the standard library's documentation and vim highlighting files
|
||
cd lib/"agda" do
|
||
system bin/"agda", "-i", ".", "-i", "src", "--html", "--vim", "README.agda"
|
||
end
|
||
end
|
||
|
||
# compile the included Emacs mode
|
||
if build.with? "emacs"
|
||
system bin/"agda-mode", "compile"
|
||
elisp.install_symlink Dir["#{share}/*/Agda-#{version}/emacs-mode/*"]
|
||
end
|
||
end
|
||
|
||
def caveats
|
||
s = ""
|
||
|
||
if build.with? "stdlib"
|
||
s += <<-EOS.undent
|
||
To use the Agda standard library by default:
|
||
mkdir -p ~/.agda
|
||
echo #{HOMEBREW_PREFIX}/lib/agda/standard-library.agda-lib >>~/.agda/libraries
|
||
echo standard-library >>~/.agda/defaults
|
||
EOS
|
||
end
|
||
|
||
s
|
||
end
|
||
|
||
test do
|
||
simpletest = testpath/"SimpleTest.agda"
|
||
simpletest.write <<-EOS.undent
|
||
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.undent
|
||
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.undent
|
||
module IOTest where
|
||
|
||
open import Agda.Builtin.IO
|
||
open import Agda.Builtin.Unit
|
||
|
||
postulate
|
||
return : ∀ {A : Set} → A → IO A
|
||
|
||
{-# COMPILED return (\\_ -> return) #-}
|
||
|
||
main : _
|
||
main = return tt
|
||
EOS
|
||
|
||
stdlibiotest = testpath/"StdlibIOTest.agda"
|
||
stdlibiotest.write <<-EOS.undent
|
||
module StdlibIOTest where
|
||
|
||
open import IO
|
||
|
||
main : _
|
||
main = run (putStr "Hello, world!")
|
||
EOS
|
||
|
||
# typecheck a simple module
|
||
system bin/"agda", simpletest
|
||
|
||
# typecheck a module that uses the standard library
|
||
if build.with? "stdlib"
|
||
system bin/"agda", "-i", lib/"agda"/"src", stdlibtest
|
||
end
|
||
|
||
# compile a simple module using the JS backend
|
||
system bin/"agda", "--js", simpletest
|
||
|
||
# test the GHC backend
|
||
if build.with? "ghc"
|
||
cabal_sandbox do
|
||
cabal_install "text", "ieee754"
|
||
dbpath = Dir["#{testpath}/.cabal-sandbox/*-packages.conf.d"].first
|
||
dbopt = "--ghc-flag=-package-db=#{dbpath}"
|
||
|
||
# compile and run a simple program
|
||
system bin/"agda", "-c", dbopt, iotest
|
||
assert_equal "", shell_output(testpath/"IOTest")
|
||
|
||
# compile and run a program that uses the standard library
|
||
if build.with? "stdlib"
|
||
system bin/"agda", "-c", "-i", lib/"agda"/"src", dbopt, stdlibiotest
|
||
assert_equal "Hello, world!", shell_output(testpath/"StdlibIOTest")
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|