forked from lotia/homebrew-versions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go15.rb
115 lines (99 loc) · 3.86 KB
/
go15.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
class Go15 < Formula
desc "Go programming environment"
homepage "https://golang.org"
url "https://storage.googleapis.com/golang/go1.5.4.src.tar.gz"
mirror "https://fossies.org/linux/misc/go1.5.4.src.tar.gz"
version "1.5.4"
sha256 "002acabce7ddc140d0d55891f9d4fcfbdd806b9332fb8b110c91bc91afb0bc93"
bottle do
sha256 "0d0d96d66bbf85396ea445c357a31a5e3bff80197c34527a788454e6b59067db" => :el_capitan
sha256 "57d3da12e509369ca49fa3fe1dd945b9ca6b5deff328832a867d1e665c4ed7c6" => :yosemite
sha256 "de116cc18565a6b564f7b9546717b0314126ed5fc2fd93bad5d1cbc0e6c39c2a" => :mavericks
end
option "without-cgo", "Build without cgo"
option "without-godoc", "godoc will not be installed for you"
option "without-vet", "vet will not be installed for you"
resource "gotools" do
url "https://go.googlesource.com/tools.git",
:revision => "d02228d1857b9f49cd0252788516ff5584266eb6"
end
resource "gobootstrap" do
if MacOS.version > :lion
url "https://storage.googleapis.com/golang/go1.4.2.darwin-amd64-osx10.8.tar.gz"
sha256 "c2f53983fc8fe5159d811081022ebc401b8111759ce008f91193abdae82cdbc9"
else
url "https://storage.googleapis.com/golang/go1.4.2.darwin-amd64-osx10.6.tar.gz"
sha256 "da40e85a2c9bda9d2c29755c8b57b8d5932440ba466ca366c2a667697a62da4c"
end
end
conflicts_with "go", :because => "Differing versions of the same formula"
def install
# GOROOT_FINAL must be overidden later on real Go install
ENV["GOROOT_FINAL"] = buildpath/"gobootstrap"
# build the gobootstrap toolchain Go >=1.4
(buildpath/"gobootstrap").install resource("gobootstrap")
cd "#{buildpath}/gobootstrap/src" do
system "./make.bash", "--no-clean"
end
# This should happen after we build the test Go, just in case
# the bootstrap toolchain is aware of this variable too.
ENV["GOROOT_BOOTSTRAP"] = ENV["GOROOT_FINAL"]
cd "src" do
ENV["GOROOT_FINAL"] = libexec
ENV["GOOS"] = "darwin"
ENV["CGO_ENABLED"] = build.with?("cgo") ? "1" : "0"
system "./make.bash", "--no-clean"
end
(buildpath/"pkg/obj").rmtree
rm_rf "gobootstrap" # Bootstrap not required beyond compile.
libexec.install Dir["*"]
bin.install_symlink Dir["#{libexec}/bin/go*"]
if build.with?("godoc") || build.with?("vet")
ENV.prepend_path "PATH", bin
ENV["GOPATH"] = buildpath
(buildpath/"src/golang.org/x/tools").install resource("gotools")
if build.with? "godoc"
cd "src/golang.org/x/tools/cmd/godoc/" do
system "go", "build"
(libexec/"bin").install "godoc"
end
bin.install_symlink libexec/"bin/godoc"
end
if build.with? "vet"
cd "src/golang.org/x/tools/cmd/vet/" do
system "go", "build"
# This is where Go puts vet natively; not in the bin.
(libexec/"pkg/tool/darwin_amd64/").install "vet"
end
end
end
end
def caveats; <<-EOS.undent
As of go 1.2, a valid GOPATH is required to use the `go get` command:
https://golang.org/doc/code.html#GOPATH
You may wish to add the GOROOT-based install location to your PATH:
export PATH=$PATH:#{opt_libexec}/bin
EOS
end
test do
(testpath/"hello.go").write <<-EOS.undent
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
EOS
# Run go fmt check for no errors then run the program.
# This is a a bare minimum of go working as it uses fmt, build, and run.
system "#{bin}/go", "fmt", "hello.go"
assert_equal "Hello World\n", shell_output("#{bin}/go run hello.go")
if build.with? "godoc"
assert File.exist?(libexec/"bin/godoc")
assert File.executable?(libexec/"bin/godoc")
end
if build.with? "vet"
assert File.exist?(libexec/"pkg/tool/darwin_amd64/vet")
assert File.executable?(libexec/"pkg/tool/darwin_amd64/vet")
end
end
end