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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
#! /usr/bin/env bash
# @@ Do we really want to require PDF doc generation? This will unlikely
# work anywhere except Linux. Maybe we should only distribute .xhtml
# and only generate PDFs for web publishing? Maybe decide when moving
# to ad hoc rules?
# Boostrap the build2 development environment.
#
# Note that this script runs git-update-index commands specified in the
# README-GIT files of cloned repositories.
#
# This script assumes the following steps have been performed:
#
# 1. The latest staged toolchain has been temporarily installed somewhere
# other than /usr/local (e.g., /tmp/build2) and is in PATH.
#
# 2. The CLI and ODB compilers have been built and are either installed (if
# you don't plan to contribute to them) or symlinked in /usr/local/bin/.
# For the latter case it would typically go to ~/work/{cli,odb/}, for
# example (for CLI; note: remove sanitizers for ODB):
#
# NOTE: clone using the git.codesynthesis.com:/var/scm/cli/cli.git SSH
# URL for rw access.
#
# mkdir -p ~/work/cli
# cd ~/work/cli
# git clone --recursive https://git.codesynthesis.com/cli/cli.git
# cd cli
# bdep init -C ../builds/gccN-asan @gccN-asan cc \
# config.cxx=g++-N \
# config.cc.coptions="-Wall -Wextra -Werror -g3 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer"
# b
# sudo ln -s "$(pwd)/cli/cli /usr/local/bin/cli"
# which cli
# cli --version
#
# Once this is done, you should be able to:
#
# mkdir -p ~/work/build2
# cd ~/work/build2
# git clone --recursive https://git.build2.org/etc.git
# PATH="/tmp/build2/bin:$PATH" etc/bootstrap
#
# NOTE: use the git.build2.org:/var/scm/etc.git SSH URL and pass the
# --ssh bootstrap option for rw access.
#
# After a successful bootstrap you can remove the staged toolchain.
#
# Options:
#
# --ssh
# Use SSH URL for cloning (rw access).
#
# --no-symlink
# Do not create executable symlinks in /usr/local/bin/.
#
# --no-clone
# Do not clone the repositories or build the bootstrap build system
# (b-boot) assuming this has already been done. This option is primarily
# useful for initializing additional configurations (e.g., Clang in
# addition to GCC).
#
# --cxx
# --cfg
# C++ compiler to use and the corresponding build configuration name, for
# example, g++-9/gcc9 or clang++-8/clang8; g++/gcc by default.
#
owd="$(pwd)"
trap "{ cd '$owd'; exit 1; }" ERR
set -o errtrace # Trap in functions.
function info () { echo "$*" 1>&2; }
function error () { info "$*"; exit 1; }
# Run a command with tracing (similar to set -x).
#
# Note that this function will execute a command with arguments that contain
# spaces but it will not print them as quoted (and neither does set -x).
#
function run ()
{
echo "+ $@" 1>&2
"$@"
}
# Make sure the necessary tools are runnable.
#
cli --version >/dev/null
odb --version >/dev/null
b --version >/dev/null
bpkg --version >/dev/null
bdep --version >/dev/null
url="https://git.build2.org"
sym=true
clone=true
cxx=g++
cfg=gcc
while [ $# -gt 0 ]; do
case $1 in
--ssh)
url="git.build2.org:/var/scm"
shift
;;
--no-symlink)
sym=
shift
;;
--no-clone)
clone=
shift
;;
--cxx)
shift
cxx="$1"
shift
;;
--cfg)
shift
cfg="$1"
shift
;;
*)
error "unexpected $1"
;;
esac
done
function git_clone () # <url>
{
local u d l
u="$1"
d="$(basename -s .git "$u")"
run git clone --recursive "$u"
# Run git-update-index commands from README-GIT.
#
if [ -f "$d/README-GIT" ]; then
run cd "$d"
l=
while read l || [ -n "$l" ]; do
info "+ $l"
eval $l
done < <(sed -rn -e 's/^(git update-index .+)/\1/p' README-GIT)
run cd -
fi
# Generate documentation (currently and temporarily handled with a script).
#
if [ -f "$d/doc/cli.sh" ]; then
run cd "$d/doc"
run ./cli.sh
run cd -
fi
}
if [ "$clone" ]; then
git_clone "$url/libbutl.git"
git_clone "$url/build2.git"
git_clone "$url/libbpkg.git"
git_clone "$url/bpkg.git"
git_clone "$url/bdep.git"
# Build the bootstrap build system (b-boot).
#
run cd build2
run make -f bootstrap.gmake CXX="$cxx" CXXFLAGS=-O3 -j 8
run make -f bootstrap.gmake CXX="$cxx" CXXFLAGS=-O3 cleano # Cleanup objs.
run build2/b-boot --version
run cd -
fi
# @@ TODO: make build system configuration ASAN/TSAN configurable.
#
# ASAN: -g3 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer
# TSAN: -g3 -fsanitize=thread
run mkdir -p builds
# Build system configuration.
#
run bpkg create -d "builds/$cfg-asan-bs" cc cli \
config.cxx="$cxx" \
config.cc.coptions="-Wall -Wextra -Werror -g3 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" \
config.cc.loptions="-fuse-ld=gold -Wl,--threads,--thread-count,4" \
config.install.root=/tmp/install config.dist.root=/tmp/dist
run bdep init -d libbutl -A "builds/$cfg-asan-bs" "@$cfg-asan-bs" --no-default
run bdep init -d build2 -A "builds/$cfg-asan-bs" "@$cfg-asan-bs"
run b build2/build2/
run build2/build2/b --version
# Package manager (and the rest of the toolchain) configuration.
#
run bpkg create -d "builds/$cfg-asan-pm" cc cli \
config.cxx="$cxx" \
config.cc.coptions="-Wall -Wextra -Werror -g3 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" \
config.cc.loptions="-fuse-ld=gold -Wl,--threads,--thread-count,4" \
config.install.root=/tmp/install config.dist.root=/tmp/dist
run bdep init -d libbutl -A "builds/$cfg-asan-pm" "@$cfg-asan-pm" --default
run bdep init -d libbpkg -A "builds/$cfg-asan-pm" "@$cfg-asan-pm"
run bdep init -d bpkg -A "builds/$cfg-asan-pm" "@$cfg-asan-pm"
run bdep init -d bdep -A "builds/$cfg-asan-pm" "@$cfg-asan-pm"
# Generate database support (currently and temporarily handled with a script).
#
# Note: this has to be done after bdep-init since we need the libodb headers.
# We also have to pre-update version headers.
#
run bpkg update -d builds/$cfg-asan-pm libodb
run b "builds/$cfg-asan-pm/libbutl/libbutl/hxx{version}"
run b "builds/$cfg-asan-pm/libbpkg/libbpkg/hxx{version}"
run b "builds/$cfg-asan-pm/bpkg/bpkg/hxx{version common-options}"
run b "builds/$cfg-asan-pm/bdep/bdep/hxx{version common-options project-options}"
run cd bpkg/bpkg
run ./odb.sh
run cd -
run cd bdep/bdep
run ./odb.sh
run cd -
run b bpkg/bpkg/ bdep/bdep/
run bpkg/bpkg/bpkg --version
run bdep/bdep/bdep --version
# Add symlinks.
#
if [ "$sym" ]; then
run sudo ln -s "$owd/build2/build2/b" /usr/local/bin/b
run sudo ln -s "$owd/build2/build2/b-boot" /usr/local/bin/b-boot
run sudo ln -s "$owd/bpkg/bpkg/bpkg" /usr/local/bin/bpkg
run sudo ln -s "$owd/bdep/bdep/bdep" /usr/local/bin/bdep
run export PATH="/usr/local/bin:$PATH"
run which b bpkg bdep
# Re-run update using the bootstrapped toolchain (normally should be a
# noop).
#
run b build2/build2/ bpkg/bpkg/ bdep/bdep/
fi
|