blob: 99f1a79c4dac34a03011667912c2d2549e4bf383 (
plain)
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
#! /usr/bin/env bash
# Test examples from the intro2, the Tour section. The optional <repo>
# and <trust> arguments specify the pkg repository and its fingerpring
# that contain libhello-1.0.0.
#
# Usage: intro [options] [<repo> <trust>]
#
usage="usage: $0 [options]"
owd=`pwd`
trap "{ cd $owd; exit 1; }" ERR
set -o errtrace # Trap in functions.
function error () { echo "$*" 1>&2; exit 1; }
tmp=/tmp
show=y
gcc=g++
clang=clang++-16
msvc=cl-15
repo=https://stage.build2.org/1/
trust="EC:50:13:E2:3D:F7:92:B4:50:0B:BF:2A:1F:7D:31:04:C6:57:6F:BC:BE:04:2E:E0:58:14:FA:66:66:21:1F:14"
# Keep in sync with *-tldr.
#
function show () # <cmd> ...
{
if [ $show = "y" ]; then
echo
echo "+ $*"
fi
local p=("$1")
if [ "$1" = b -o "$1" = bpkg -o "$1" = bdep ]; then
p+=(--no-progress)
fi
if [ "$1" = tree ]; then
p+=(-n) # No color.
fi
shift
"${p[@]}" "${@}"
}
cd "$tmp"
function clean ()
{
rm -rf hello hello-host hello-build2 hello-base hello-gcc hello-gcc-1 hello-clang hello-vc-* hello-mingw
}
## if false; then
clean
show bdep new -t exe -l c++ hello
show tree hello
show cd hello
show cat hello/hello.cxx
show cat hello/buildfile
show cat hello/testscript
show cat manifest
show bdep init -C ../hello-gcc @gcc cc config.cxx=$gcc
show bdep init -C ../hello-clang @clang cc config.cxx=$clang
show ls -d -1 ../hello*
show bdep init -C ../hello-vc-debug @debug cc config.cxx=$msvc \
"config.cc.coptions=/MDd /Z7" config.cc.loptions=/DEBUG
show bdep init -C ../hello-vc-release @release cc config.cxx=$msvc \
config.cc.coptions=/O2
show bdep status
show b
show b test
show hello/hello World
show tree ../hello-gcc
show bdep status @clang
show b ../hello-clang/hello/
show b test: ../hello-clang/hello/
show ../hello-clang/hello/hello/hello World
b --no-progress clean: ../hello-clang/hello/
show bdep test @clang
show bdep test @gcc @clang
show bdep init -C ../hello-mingw @mingw cc config.cxx=x86_64-w64-mingw32-g++
show bdep update @mingw
show bdep test @mingw
show ../hello-mingw/hello/hello/hello.exe Windows | cat # Strip term junk.
show git add .
show git commit -m "Initial implementation"
show git remote add origin git@github.com:boris-kolpackov/hello.git
show git push --no-progress origin master -u --force
show bdep ci --simulate success
show bdep deinit @gcc @clang
cd ..
##fi
##if false; then
clean
show bdep new -C hello-gcc @gcc -t exe -l c++ hello cc config.cxx=$gcc
cd hello
show bdep init -C ../hello-clang @clang cc config.cxx=$clang
# Package Repositories
#
show bpkg rep-info https://git.build2.org/hello/libhello.git
show bpkg rep-info https://git.build2.org/hello/libhello.git#HEAD
# Adding and Removing Dependencies
#
cat <<EOF >>repositories.manifest
:
role: prerequisite
location: $repo
EOF
sed -i -re 's/^#depends: libhello/depends: libhello/' manifest # ^1.0.0
sed -i -re 's/^#import/import/' hello/buildfile
cat <<EOF >hello/hello.cxx
#include <iostream>
#include <libhello/hello.hxx>
using namespace std;
int main (int argc, char* argv[])
{
if (argc < 2)
{
cerr << "error: missing name" << endl;
return 1;
}
hello::say_hello (cout, "World");
}
EOF
show bdep status
cat <<EOF >>repositories.manifest
trust: $trust
EOF
show bdep sync
echo '' >>manifest
show b
show bdep status -ai
show bdep sync -a
show bdep test -ai
sed -i -re 's/^import/#import/' hello/buildfile
sed -i -re 's/^depends: libhello/#depends: libhello/' manifest
show bdep status
show bdep sync
# Upgrading and Downgrading Dependencies
#
sed -i -re 's/^#import/import/' hello/buildfile
sed -i -re 's/^#depends: libhello/depends: libhello/' manifest
bdep sync --no-progress
cat <<EOF >>repositories.manifest
:
role: prerequisite
location: https://git.build2.org/hello/libhello.git
EOF
show bdep fetch
show bdep status libhello
show bdep sync libhello
show bdep status -r
show bdep status -o libhello
show bdep sync libhello/1.0.0
# Using Unpackaged Dependencies.
#
cd ..
rm -rf libextra libextra-gcc unpkg-gcc hello-gcc-1
show bdep new -C libextra-gcc -t lib -l c++ libextra cc config.cxx=$gcc
show b install: libextra/ config.install.root=/tmp/unpkg-gcc
show tree unpkg-gcc
cd hello
show bdep init -C ../hello-gcc-1 @gcc1 cc config.cxx=$gcc \
config.cc.poptions=-I$tmp/unpkg-gcc/include \
config.cc.loptions=-L$tmp/unpkg-gcc/lib
sed -i -re 's/^libs =/import libs = libextra%lib{extra}/' hello/buildfile
cat <<EOF >>hello/hello.cxx
#include <libextra/extra.hxx>
void f ()
{
extra::say_hello (cout, "Extra");
}
EOF
show b test: ../hello-gcc-1/
show b configure: ../hello-gcc/ \
config.cc.poptions+=-I$tmp/unpkg-gcc/include \
config.cc.loptions+=-L$tmp/unpkg-gcc/lib
show b test
# Using System-Installed Dependencies.
#
cat <<EOF >>manifest
depends: libsqlite3 ^3.18.0
EOF
sed -i -re 's/^import libs =/import libs = libsqlite3%lib{sqlite3}/' hello/buildfile
cat <<EOF >>hello/hello.cxx
#include <sqlite3.h>
EOF
show bdep sync ?sys:libsqlite3
cd ..
# Build-time Dependencies.
#
clean
show bdep new -t exe -l c++ hello
cd hello
show bdep init -C @gcc cc config.cxx=$gcc
show bdep init -C @clang cc config.cxx=$clang
cat <<EOF >>repositories.manifest
:
role: prerequisite
location: https://pkg.cppget.org/1/alpha
trust: 70:64:FE:E4:E0:F3:60:F1:B4:51:E1:FA:12:5C:E0:B3:DB:DF:96:33:39:B9:2E:E5:C2:68:63:4C:A6:47:39:43
EOF
echo 'depends: * xxd >= 8.2.0' >>manifest
cat <<EOF >hello/buildfile
import! [metadata] xxd = xxd%exe{xxd}
exe{hello}: {hxx ixx txx cxx}{** -names} cxx{names} $libs testscript
cxx{names}: file{names.txt} \$xxd
{{
i = \$path(\$<[0])
env --cwd \$directory(\$i) -- \$xxd -i \$leaf(\$i) >\$path(\$>)
}}
EOF
cat <<EOF >hello/hello.cxx
#include <iostream>
#include <string>
extern unsigned char names_txt[];
extern unsigned int names_txt_len;
int main (int argc, char* argv[])
{
using namespace std;
if (argc < 2)
{
cerr << "error: missing name" << endl;
return 1;
}
cout << string (reinterpret_cast<const char*> (names_txt), names_txt_len) << ", " << argv[1] << '!' << endl;
}
EOF
echo -n "Hello" >hello/names.txt
show bdep config list
#show bdep sync --create-host-config # Needed if not terminal.
show b
b --no-progress test
show bdep config list
show bdep update @clang
echo 'depends: * libbuild2-hello' >>manifest
echo 'using hello' >>hello/buildfile
#show bdep sync --create-build2-config # Needed if not terminal.
show b
show bdep config list
show bdep update @clang
cd ..
# Linked Configurations.
#
clean
show bdep new -t exe -l c++ hello
cd hello
cat <<EOF >>repositories.manifest
:
role: prerequisite
location: $repo
trust: $trust
EOF
sed -i -re 's/^#depends: libhello/depends: libhello/' manifest # ^1.0.0
sed -i -re 's/^#import/import/' hello/buildfile
show bdep config create ../hello-base @base --no-default cc config.cxx=$gcc
show bdep config create ../hello-gcc @gcc --default cc config.cxx=$gcc
show bdep config create ../hello-clang @clang cc config.cxx=$clang
show bdep config link @gcc @base
show bdep config link @clang @base
show bdep init @gcc { @base }+ ?libhello
show bdep init @clang
show bdep update @gcc
show bdep update @clang
cd ..
# Versioning and Release Management.
#
clean
show bdep new -C hello-gcc @gcc -t exe -l c++ hello cc config.cxx=$gcc
cd hello
git remote add origin git@github.com:boris-kolpackov/hello.git
git push --no-progress origin :build2-control || true
git push --no-progress -d origin v0.1.0-a.1 || true
git push --no-progress -d origin v0.1.0 || true
git add .
git commit -m "Initial implementation"
git push --no-progress -f -u
show bdep status
show b info
show bdep sync
show bdep status
echo '' >>buildfile
git commit -a -m "Another commit"
show bdep status
show bdep release --alpha --push
show bdep release --no-open --push
show bdep publish --simulate success --repository https://stage.build2.org
show bdep release --open --push
cd ..
## fi
# Developing Multiple Packages and Projects (multi-project).
#
rm -rf libhello
clean
show bdep new -C hello-gcc @gcc -t exe -l c++ hello cc config.cxx=$gcc
cd hello
show bdep init -C ../hello-clang @clang cc config.cxx=$clang
cd ..
show bdep new -t lib -l c++ libhello
show tree libhello
show cd libhello
show bdep init -A ../hello-gcc @gcc
show bdep init -A ../hello-clang @clang
show cd ../hello
cat <<EOF >>manifest
depends: libhello
EOF
sed -i -re 's/^#import/import/' hello/buildfile
show bdep test -i
cd ..
# Developing Multiple Packages and Projects (multi-package).
#
clean
show bdep new -C hello-gcc @gcc -t exe -l c++ hello cc config.cxx=$gcc
show cd hello
show bdep init -C ../hello-clang @clang cc config.cxx=$clang
mkdir tmp
mv build hello buildfile manifest .gitignore tmp/
mv tmp hello
show bdep new --package -t lib -l c++ libhello
show cat packages.manifest
cat <<EOF >>packages.manifest
:
location: hello/
EOF
show cd libhello
show bdep init -a
show cd ..
cat <<EOF >>hello/manifest
depends: libhello
EOF
sed -i -re 's/^#import/import/' hello/hello/buildfile
show bdep test
cd ..
# Package Consumption: executable.
#
rm -rf tools
show bpkg create -d tools cc \
config.cxx=$gcc \
config.cc.coptions=-O3 \
config.install.root=/opt/tools \
config.install.sudo=sudo \
config.bin.rpath=/opt/tools/lib
show cd tools
show bpkg build hello@https://git.build2.org/hello/hello.git
show bpkg install hello
show /opt/tools/bin/hello World
show tree /opt/tools
show bpkg uninstall hello
show bpkg install -r hello
show tree /opt/tools
show bpkg uninstall -r hello
show bpkg drop hello
cd ..
# Package Consumption: library.
#
rm -rf libs
show bpkg create -d libs cc \
config.cxx=$gcc \
config.cc.coptions=-O3 \
config.install.root=/opt/libs \
config.install.sudo=sudo \
config.bin.rpath=/opt/libs/lib \
config.bin.lib=shared
show cd libs
show bpkg build libhello@https://git.build2.org/hello/libhello.git
show bpkg install libhello
show tree /opt/libs
show bpkg uninstall libhello
show bpkg drop libhello
cd ..
|