-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcompile
executable file
·144 lines (127 loc) · 3.68 KB
/
compile
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
#!/usr/bin/env bash
# usage: bin/compile <build-dir> <cache-dir>
set -eo pipefail
mkdir -p "$1" "$2"
build=$(cd "$1/" && pwd)
cache=$(cd "$2/" && pwd)
ver=${GOVERSION:-1.3}
file=${GOFILE:-go$ver.$(uname|tr A-Z a-z)-amd64.tar.gz}
url=${GOURL:-https://storage.googleapis.com/golang/$file}
buildpack=$(dirname $(dirname $0))
venv=$cache/venv
virtualenv() {
python "$buildpack/vendor/virtualenv-1.7/virtualenv.py" "$@"
}
if ! test -f $build/.godir
then
echo >&2 " ! A .godir is required. For instructions visit"
echo >&2 " ! https://github.com/michaljemala/cloudfoundry-buildpack-go"
exit 1
fi
if test -e $build/bin && ! test -d $build/bin
then
echo >&2 " ! File bin exists and is not a directory."
exit 1
fi
# Download (if not cached) and install Go
if test -d $cache/go
then
v=$(cat $cache/go/VERSION)
echo " Using Go ${v:2:${#v}}"
else
rm -rf $cache/go
mkdir -p $cache/go
echo -n " Installing Go $ver..."
ts=`date +%s`
curl -sO $url
tar -C $cache/go -zxf $file --strip-components=1
rm -f $file
te=`date +%s`
echo " done in $(($te-$ts))s"
fi
export GOROOT=$cache/go
export GOPATH=$build/.cf/go
# Check if Mercurial and Bazaar are installed
if ! (which hg > /dev/null && which bzr > /dev/null)
then
echo -n " Installing Virtualenv..."
rm -rf $venv
virtualenv --distribute --never-download --prompt='(venv) ' $venv > /dev/null 2>&1
source $venv/bin/activate > /dev/null 2>&1
echo " done"
PATH=$venv/bin:$PATH
# Download (if not cached) and install pure hg binary
if ! test -d $cache/mercurial
then
echo -n " Downloading Mercurial sources..."
ts=`date +%s`
pip install --download=$cache mercurial > /dev/null 2>&1
mkdir $cache/mercurial
tar -C $cache/mercurial -zxf $cache/mercurial*.tar.gz --strip-components=1
rm -R $cache/mercurial*.tar.gz
te=`date +%s`
echo " done in $(($te-$ts))s"
fi
echo -n " Installing Mercurial..."
cd $cache/mercurial
python setup.py --pure install > /dev/null 2>&1
cd ../../
echo " done"
# Download (if not cached) and install pure bzr binary
if ! test -d $cache/bazaar
then
echo -n " Downloading Bazaar sources..."
ts=`date +%s`
pip install --download=$cache bzr > /dev/null 2>&1
mkdir $cache/bazaar
tar -C $cache/bazaar -zxf $cache/bzr*.tar.gz --strip-components=1
rm -R $cache/bzr*.tar.gz
te=`date +%s`
echo " done in $(($te-$ts))s"
fi
echo -n " Installing Bazaar..."
cd $cache/bazaar
python setup.py install build_ext --allow-python-fallback > /dev/null 2>&1
cd ../../
echo " done"
fi
name=$(cat $build/.godir)
p=$GOPATH/src/$name
mkdir -p $p
cp -R $build/* $p
PATH=$GOROOT/bin:$PATH
PATH=$GOPATH/bin:$PATH
unset GIT_DIR # unset git dir or it will mess with goinstall
# If Godeps file present, use godep to fetch dependencies,
# otherwise use straight up "go get"
if test -f $p/Godeps
then
echo -n " Fetching godep..."
ts=`date +%s`
go get github.com/tools/godep
te=`date +%s`
echo " done in $(($te-$ts))s"
echo -n " Running godep restore..."
ts=`date +%s`
cd $p
godep restore
te=`date +%s`
echo " done in $(($te-$ts))s"
echo -n " Running 'go install'..."
ts=`date +%s`
go install
te=`date +%s`
echo " done in $(($te-$ts))s"
else
echo -n " Running 'go get -tags cf ./...'..."
ts=`date +%s`
cd $p
go get -tags cf ./...
te=`date +%s`
echo " done in $(($te-$ts))s"
fi
mkdir -p $build/bin
mv $GOPATH/bin/* $build/bin
rm -rf $build/.cf
mkdir -p $build/.profile.d
echo 'export PATH=$PATH:$HOME/bin' > $build/.profile.d/go.sh