forked from dlang/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·211 lines (189 loc) · 5.14 KB
/
update.sh
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env zsh
# Run this script to install or update your dmd toolchain from
# github.
#
# Make sure zsh is installed. You may need to change the shebang.
#
# First run, create a working directory, e.g. /path/to/d/. Then run
# this script from that directory (the location of the script itself
# doesn't matter). It will create the following subdirectories:
# /path/to/d/dmd, /path/to/d/druntime, /path/to/d/phobos,
# /path/to/d/dlang.org, /path/to/d/tools, and
# /path/to/d/installer. Then it will fetch all corresponding projects
# from github and build them fresh.
#
# On an ongoing basis, to update your toolchain from github go again
# to the same directory (in our example /path/to/d) and run the script
# again. The script will detect that directories exist and will do an
# update.
#
setopt err_exit
local projects
typeset -a projects
projects=(dmd druntime phobos dlang.org tools installer)
# Working directory
local wd=$(pwd)
# Configuration
local makecmd=make
local parallel=8
local model=64
# List of projects to install vs. update. Their disjoint union is
# $projects.
local toInstall toUpdate
typeset -a toInstall toUpdate
# Mess to go here
local tempdir=$(mktemp -d /tmp/dmd-update.XXX)
#
# Take care of the command line arguments
#
function handleCmdLine() {
local arg
for arg in $*; do
case $arg in
(--tag=*)
tag="`echo $arg | sed 's/[-a-zA-Z0-9]*=//'`"
;;
(install)
install="yes"
;;
(*)
echo "Error: $arg not recognized." >&2
exit 1
;;
esac
done
if [[ ! -z $tag ]]; then
wd+="/$tag"
mkdir -p "$wd"
fi
}
#
# Confirm correct choices
#
function confirmChoices() {
function joinWithWorkingDir() {
for i in $*; do
echo "$wd/$i"
done
}
for project in $projects; do
if [ -e "$wd/$project" ]; then
toUpdate=($toUpdate "$project")
else
toInstall=($toInstall "$project")
fi
done
if [[ ! -z $toInstall ]]; then
echo "*** The following projects will be INSTALLED:"
joinWithWorkingDir ${toInstall}
echo "*** Note: this script assumes you have a github account set up."
fi
if [[ ! -z $toUpdate ]]; then
echo "*** The following projects will be UPDATED:"
joinWithWorkingDir ${toUpdate}
fi
echo "Is this what you want?"
local yn
while true; do
read yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n.";;
esac
done
}
#
# Install from scratch
#
function installAnew() {
local projects
projects=($*)
for project in $projects; do
(
cd $wd &&
git clone --quiet git://github.com/D-Programming-Language/$project.git &&
touch $tempdir/$project
) &
done
wait
for project in $projects; do
if [ ! -f $tempdir/$project ]; then
echo "Getting $project failed." >&2
rm -rf $tempdir
exit 1
fi
if [[ ! -z $tag &&
($project = dmd || $project = druntime || $project = phobos ||
$project = dlang.org) ]]; then
( cd $wd/$project && git checkout v$tag )
fi
done
}
#
# Freshen existing stuff
#
function update() {
echo "Updating projects in $wd..."
function update_project() {
local project=$1
local gitproject="git://github.com/D-Programming-Language/$project.git"
if ! ( cd "$wd/$project" && \
git checkout master && \
git pull --ff-only $gitproject master && \
git pull $gitproject master --tags && \
git fetch $gitproject && \
git fetch --tags $gitproject) 2>$tempdir/$project.log
then
echo "Failure updating $wd/$project." >>$tempdir/errors
exit 1
fi
}
for project in $toUpdate; do
update_project $project &
done
wait
if [ -f $tempdir/errors ]; then
cat $tempdir/*.log >&2
exit 1
fi
}
function makeWorld() {
# First make dmd
(
cd "$wd/dmd/src" &&
$makecmd -f posix.mak clean MODEL=$model &&
$makecmd -f posix.mak -j $parallel MODEL=$model
)
# Update the running dmd version
if [[ ! -z $install ]]; then
local old=$(which dmd)
if [ -f "$old" ]; then
echo "Copying "$wd/dmd/src/dmd" over $old"
[ ! -w "$old" ] && local sudo="sudo"
$sudo cp "$wd/dmd/src/dmd" "$old"
fi
fi
# Then make druntime
(
cd "$wd/druntime" &&
$makecmd -f posix.mak -j $parallel DMD="$wd/dmd/src/dmd" MODEL=$model
)
# Then make phobos
(
cd "$wd/phobos" &&
$makecmd -f posix.mak -j $parallel DMD="$wd/dmd/src/dmd" MODEL=$model
)
# Then make website
(
cd "$wd/dlang.org" &&
$makecmd -f posix.mak clean DMD="$wd/dmd/src/dmd" MODEL=$model &&
$makecmd -f posix.mak html -j $parallel DMD="$wd/dmd/src/dmd" MODEL=$model
)
}
# main
handleCmdLine $*
confirmChoices
installAnew $toInstall
update $toUpdate
makeWorld