summaryrefslogtreecommitdiff
path: root/intro
blob: 6587f37e84c5e3f8b2d4ce100624665a2f6a7a14 (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
#! /usr/bin/env bash

# Test examples from the into.
#
# Usage: install [options] <hello-repo>
#
# -t <toolchain>
#    Specify the build2 toolchain install/stage directory. The script will
#    use <toolchain>/bin/b and <toolchain>/bin/bpkd instead of just b and
#    bpkg.
#
# -c1
# -c2
# -c3
# -c4
#    C++ compilers 1 (g++-5), 2 (clang++-3.6), 3 (x86_64-w64-mingw32-g++), and
#    4 (cl-14). If the value for 2, 3, 4 is empty, then this test is skipped.
#
# -h
#    The hello2 source directory, by default hello/hello2
#
# -s
#    Show the commands being executed.
#
# -p
#    Prompt for confirmations.
#
# For example:
#
# intro https://pkg.cppget.org/1/hello
# intro /var/bpkg/1/hello
#
usage="usage: $0 [options] <hello-repo>"

owd=`pwd`
trap "{ cd $owd; exit 1; }" ERR
set -o errtrace # Trap in functions.

function error () { echo "$*" 1>&2; exit 1; }

tmp=/tmp
rep=
toolchain=
hello2=hello/hello2
show=n
prompt=-y

# Add for both build2.org and stage.build2.org.
#
trust="--trust FF:DF:7D:38:67:4E:C3:82:65:7E:EE:1F:D4:80:EC:56:C4:33:5B:65:3F:9B:29:9A:30:56:B9:77:B9:F2:01:94"
trust+=" --trust 37:CE:2C:A5:1D:CF:93:81:D7:07:46:AD:66:B3:C3:90:83:B8:96:9E:34:F0:E7:B3:A2:B0:6C:EF:66:A4:BE:65"

c1=g++-5
c2=clang++-3.6
c3=x86_64-w64-mingw32-g++
c4=cl-14

while [ $# -gt 0 ]; do
  case $1 in
    -t)
      shift
      toolchain=${1%/}
      shift
      ;;
    -c1)
      shift
      c1="$1"
      shift
      ;;
    -c2)
      shift
      c2="$1"
      shift
      ;;
    -c3)
      shift
      c3="$1"
      shift
      ;;
    -c4)
      shift
      c4="$1"
      shift
      ;;
    -h)
      shift
      hello2=${1%/}
      shift
      ;;
    -s)
      show=y
      shift
      ;;
    -p)
      prompt=
      trust=
      shift
      ;;
    *)
      rep=${1%/}
      break
      ;;
  esac
done

if [ -z "$rep" ]; then
  error "$usage"
fi

if [[ $hello2 != /* ]]; then
  hello2=$owd/$hello2
fi

if [ ! -d "$hello2" ]; then
  error "hello2 directory $hello2 does not exist"
fi

if [ -n "$toolchain" ]; then
  export PATH="$toolchain/bin:$PATH"

  if [ "`which b`" != "$toolchain/bin/b" ]; then
    error "b does not appear to be in $toolchain/bin/"
  fi

  if [ "`which bpkg`" != "$toolchain/bin/bpkg" ]; then
    error "bpkg does not appear to be in $toolchain/bin/"
  fi
fi

if [ -z "`which tree`" ]; then
  tree="ls -1"
else
  tree=tree
fi

function show () # <cmd> ...
{
  if [ $show = "y" ]; then
    echo "$*"
    "${@}"
    echo
  else
    "${@}"
  fi
}

function create () # <dir> <bpkg-args>
{
  local d=$1; shift

  rm -rf $tmp/$d
  mkdir $tmp/$d
  cd $tmp/$d
  show bpkg create "${@}"
}

function info () # stable|testing
{
  local d=$1; shift
  show bpkg rep-info $trust $rep/$d
}

function add () # stable|testing
{
  local d=$1; shift
  show bpkg add $rep/$d
}

function fetch ()
{
  show bpkg fetch $trust
}

function build () # <bpkg-args>
{
  show bpkg build $prompt "${@}"
}

function drop () # <bpkg-args>
{
  show bpkg drop $prompt "${@}"
}

function status () # <pkg> <expected> [<args>]
{
  local p="$1"
  shift
  local e="$1"
  shift

  if [ $show = "y" ]; then
    echo "bpkg status $* $p"
  fi

  local s="$(bpkg status "${@}" $p)"
  echo "$s"

  if [ "$s" != "$e" ]; then
    error "status $1: '"$s"', expected: '"$e"'"
  fi

  if [ $show = "y" ]; then
    echo
  fi
}

function clean () # <bpk>
{
  show bpkg clean "${@}"
}

function update () # <bpk>
{
  show bpkg update "${@}"
}

function test () # <bpk>
{
  show bpkg test "${@}"
}

create hello-gcc5-release cxx config.cxx="$c1" config.cxx.coptions=-O3
if [ -n "$c2" ]; then
  create hello-vc14-release cxx config.cxx="$c4" config.cxx.coptions=/O2
fi
create hello-gcc5-release cc config.cxx="$c1" config.cc.coptions=-O3

info stable
add stable
fetch
build hello
drop hello
build -v -y hello

status libhello "configured 1.0.0; available sys:?"
status hello "configured 1.0.0 hold_package; available sys:?"
drop -y hello
status hello "available 1.0.0 sys:?"
status libfoobar "unknown"




build -y hello
add testing
fetch
status libhello "configured 1.0.0; available 1.1.0 sys:?"
build -y hello
build libhello
clean hello
update hello
build libhello/1.0.0

test libhello hello
show ls -1F
show ls -1F hello-1.0.0/
show hello-1.0.0/hello || true
show hello-1.0.0/hello World

show bpkg install                    \
     config.install.root=/opt/hello  \
     config.install.sudo=sudo        \
     config.bin.rpath=/opt/hello/lib \
     hello
show $tree -F /opt/hello/
show /opt/hello/bin/hello World

show bpkg uninstall                  \
     config.install.root=/opt/hello  \
     config.install.sudo=sudo        \
     config.bin.rpath=/opt/hello/lib \
     hello
show ls /opt/hello || true

show cd $hello2
show b config.cxx=$c1 config.import.libhello=$tmp/hello-gcc5-release
show $tree -F
show ./hello
b config.cxx=$c1 config.import.libhello=$tmp/hello-gcc5-release clean # Extra.

show cd $tmp
rm -rf hello2-gcc5-release
show mkdir hello2-gcc5-release
show b config.cxx=$c1 \
     config.cc.coptions=-O3 \
     config.import.libhello=$tmp/hello-gcc5-release \
     "configure($hello2/@hello2-gcc5-release/)"

show b hello2-gcc5-release/
show cd hello2-gcc5-release/
show b
show b clean
show b -v

show cd $tmp
show b "configure($hello2/@$tmp/hello-gcc5-release/hello2/)"
show b $tmp/hello-gcc5-release/hello2/
status hello2 "unknown" -d $tmp/hello-gcc5-release
show b "{clean disfigure}($tmp/hello-gcc5-release/hello2/)"

build -d $tmp/hello-gcc5-release $hello2/
build -d $tmp/hello-gcc5-release -L libhello
update -d $tmp/hello-gcc5-release hello2
show $tmp/hello-gcc5-release/hello2-1.0.0/hello

if [ -n "$c2" ]; then
  create hello-clang36-release cc config.cxx=$c2 config.cc.coptions=-O3
  add testing
  fetch
  build libhello/1.0.0 $hello2/
fi

if [ -n "$c3" ]; then
  create hello-mingw64 cc config.cxx=$c3
  add stable
  fetch
  build -y hello
  export WINEDEBUG=fixme-all
  show wine hello-1.0.0/hello.exe Windows
  test libhello hello
fi