forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo-install.sh
More file actions
executable file
·146 lines (133 loc) · 3.5 KB
/
go-install.sh
File metadata and controls
executable file
·146 lines (133 loc) · 3.5 KB
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
#!/usr/bin/env bash
#
# Build commands, optionally with or without race detector. a list of every command we know about,
# to use by default
#
# This will install binaries into the `.bin` directory under the repository root by default or, if
# $GOMOD_ROOT is set, under that directory.
all_oss_commands=" gitserver indexer query-runner github-proxy lsp-proxy searcher frontend repo-updater symbols "
# GOMOD_ROOT is the directory from which `go install` commands are run. It should contain a go.mod
# file. The go.mod file may be updated as a side effect of updating the dependencies before the `go
# install`.
GOMOD_ROOT=${GOMOD_ROOT:-$PWD}
echo >&2 "Running \`go install\` from $GOMOD_ROOT"
# handle options
verbose=false
while getopts 'v' o; do
case $o in
v) verbose=true;;
\?) echo >&2 "usage: go-install.sh [-v] [commands]"
exit 1
;;
esac
done
shift $(expr $OPTIND - 1)
# check provided commands
ok=true
case $# in
0) commands=$all_oss_commands;;
*) commands=" $* "
for cmd in $commands; do
case $all_oss_commands in
*" $cmd "*) ;;
*) echo >&2 "unknown command: $cmd"
ok=false
;;
esac
done
;;
esac
if [ ! -z "$ENTERPRISE_COMMANDS" ]; then
for entCmd in $ENTERPRISE_COMMANDS; do
exists=false
for cmd in $commands; do
if [ "$cmd" = "$entCmd" ]; then
exists=true
break
fi
done
if [ "$exists" = false ]; then
commands="$commands $entCmd "
fi
done
fi
$ok || exit 1
mkdir -p .bin
export GOBIN=$PWD/.bin
export GO111MODULE=on
if ! go install \
github.com/mattn/goreman \
github.com/google/zoekt/cmd/zoekt-archive-index \
github.com/google/zoekt/cmd/zoekt-sourcegraph-indexserver \
github.com/google/zoekt/cmd/zoekt-webserver; then
echo >&2 "failed to install prerequisites, aborting."
exit 1
fi
TAGS='dev'
if [ -n "$DELVE" ]; then
echo >&2 'Building with optimizations disabled (for debugging). Make sure you have at least go1.10 installed.'
GCFLAGS='all=-N -l'
TAGS="$TAGS delve"
fi
# build a list of "cmd,true" and "cmd,false" pairs to indicate whether each command
# wants its own flags. we can't use variable names with the command in them because
# some commands have hyphens.
raced=""
unraced=""
case $GORACED in
"all") for cmd in $commands; do
raced="$raced $cmd"
done
;;
*) for cmd in $commands; do
case " $GORACED " in
*" $cmd "*)
raced="$raced $cmd"
;;
*)
unraced="$unraced $cmd"
;;
esac
done
;;
esac
# Shared logic for the go install part
do_install() {
race=$1
shift
cmdlist="$*"
cmds=""
for cmd in $cmdlist; do
replaced=false
for enterpriseCmd in $ENTERPRISE_COMMANDS; do
if [ "$cmd" == "$enterpriseCmd" ]; then
cmds="$cmds github.com/sourcegraph/sourcegraph/enterprise/cmd/$enterpriseCmd"
replaced=true
fi
done
if [ $replaced == false ]; then
cmds="$cmds github.com/sourcegraph/sourcegraph/cmd/$cmd"
fi
done
if ( cd $GOMOD_ROOT && go install -v -gcflags="$GCFLAGS" -tags "$TAGS" -race=$race $cmds ); then
if $verbose; then
# echo each command on its own line
echo "$cmdlist" | tr ' ' '\012'
fi
else
failed="$failed $cmdlist"
fi
}
if [ -n "$raced" ]; then
echo >&2 "Go race detector enabled for: $GORACED."
do_install true $raced
else
echo >&2 "Go race detector disabled. You can enable it for specific commands by setting GORACED (e.g. GORACED=frontend,searcher or GORACED=all for all commands)"
fi
if [ -n "$unraced" ]; then
do_install false $unraced
fi
if [ -n "$failed" ]; then
echo >&2 "failed to build:$failed"
exit 1
fi