-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathfunctions.star
510 lines (466 loc) · 16.9 KB
/
functions.star
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# Use, modification, and distribution are
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE.txt)
#
# Copyright Rene Rivera 2020.
# For Drone CI we use the Starlark scripting language to reduce duplication.
# As the yaml syntax for Drone CI is rather limited.
# Downloads the script inside the directory @boostCI_dir from the master branch of BoostCI into @boostCI_dir
# Does NOT download if the file already exists, e.g. when testing BoostCI or when there is a customized file
# Then makes the script executable
def download_script_from_boostCI(filename, boostCI_dir):
url = '$BOOST_CI_URL/%s/%s' % (boostCI_dir, filename)
target_path = '%s/%s' % (boostCI_dir, filename)
# Note that this always runs the `chmod` even when not downloading
return '[ -e "{1}" ] || curl -s -S --retry 10 --create-dirs -L "{0}" -o "{1}" && chmod 755 {1}'.format(url, target_path)
# Same as above but using powershell
def download_script_from_boostCI_pwsh(filename, boostCI_dir):
url = '$env:BOOST_CI_URL/%s/%s' % (boostCI_dir, filename)
target_path = '%s/%s' % (boostCI_dir, filename)
return ' '.join([
'if(![System.IO.File]::Exists("{1}")){{',
'$null = md "%s" -ea 0;' % boostCI_dir,
'try{{',
# Use pwsh.exe to invoke a potentially newer PowerShell
'pwsh.exe -Command Invoke-WebRequest "{0}" -Outfile "{1}" -MaximumRetryCount 10 -RetryIntervalSec 15',
'}}catch{{',
'Invoke-WebRequest "{0}" -Outfile "{1}";',
'}}',
'}}',
]).format(url, target_path)
# Common steps for unix systems
# Takes the install script (inside the Boost.CI "ci/drone" folder) and the build script (relative to the root .drone folder)
def unix_common(install_script, buildscript_to_run):
if not buildscript_to_run.endswith('.sh'):
buildscript_to_run += '.sh'
return [
"echo '============> SETUP'",
"uname -a",
"echo $DRONE_STAGE_MACHINE",
"export PATH=/usr/local/bin:$PATH",
# Install script
download_script_from_boostCI(install_script, 'ci/drone'),
# Chosen build script inside .drone
download_script_from_boostCI(buildscript_to_run, '.drone'),
"echo '============> PACKAGES'",
"ci/drone/" + install_script,
"echo '============> INSTALL AND TEST'",
".drone/" + buildscript_to_run,
]
# Add the value into the env[key] if it is not None
def add_if_set(env, key, value):
if value != None:
env[key] = value
# Generate pipeline for Linux platform compilers.
def linux_cxx(
# Unique name for this job
name,
# If set: Values for corresponding env variables, $CXX, $CXXFLAGS, ...
cxx=None, cxxflags=None, packages=None, sources=None, llvm_os=None, llvm_ver=None,
# Worker image and arch
arch="amd64", image="cppalliance/ubuntu16.04:1",
# Script to call for the build step and value of $DRONE_JOB_BUILDTYPE
buildtype="boost", buildscript="",
# Additional env variables, environment overwrites values in globalenv
environment={}, globalenv={},
triggers={ "branch": [ "master", "develop", "drone*", "bugfix/*", "feature/*", "fix/*", "pr/*" ] }, node={},
# Run with additional privileges (e.g for ASAN)
privileged=False):
job_env = {
"TRAVIS_BUILD_DIR": "/drone/src",
"TRAVIS_OS_NAME": "linux",
"DRONE_JOB_BUILDTYPE": buildtype,
"BOOST_CI_URL": "https://github.com/boostorg/boost-ci/raw/master",
}
add_if_set(job_env, "CXX", cxx)
add_if_set(job_env, "CXXFLAGS", cxxflags)
add_if_set(job_env, "PACKAGES", packages)
add_if_set(job_env, "SOURCES", sources)
add_if_set(job_env, "LLVM_OS", llvm_os)
add_if_set(job_env, "LLVM_VER", llvm_ver)
job_env.update(globalenv)
job_env.update(environment)
if not buildscript:
buildscript = buildtype
steps=[
{
"name": "Everything",
"image": image,
"pull": "if-not-exists",
"privileged" : privileged,
"environment": job_env,
# Installed in Docker:
# - ppa:git-core/ppa
# - tzdata sudo software-properties-common wget curl apt-transport-https git make cmake apt-file sudo unzip libssl-dev build-essential autotools-dev autoconf libc++-helpers automake g++ git
"commands": unix_common("linux-cxx-install.sh", buildscript)
}
]
imagecachename=image.replace('/', '-').replace(':','-')
if "drone_cache_mount" in job_env:
mountpoints=[x.strip() for x in job_env["drone_cache_mount"].split(',')]
pre_step={
"name": "restore-cache",
"image": "meltwater/drone-cache",
"environment": {
"AWS_ACCESS_KEY_ID":
{ "from_secret": "drone_cache_aws_access_key_id"},
"AWS_SECRET_ACCESS_KEY":
{ "from_secret": "drone_cache_aws_secret_access_key"}
},
"pull": "if-not-exists",
"settings": {
"restore": "true",
"cache_key": "{{ .Repo.Namespace }}-{{ .Repo.Name }}-{{ .Commit.Branch }}-{{ arch }}-" + imagecachename,
"bucket": "cppalliance-drone-cache",
"region": "us-east-2",
"mount": mountpoints
}
}
steps=[ pre_step ] + steps
if ("drone_cache_mount" in job_env) and ("drone_cache_rebuild" in job_env and job_env['drone_cache_rebuild'] != "false" and job_env['drone_cache_rebuild'] != False):
mountpoints=[x.strip() for x in job_env["drone_cache_mount"].split(',')]
post_step={
"name": "rebuild-cache",
"image": "meltwater/drone-cache",
"environment": {
"AWS_ACCESS_KEY_ID":
{ "from_secret": "drone_cache_aws_access_key_id"},
"AWS_SECRET_ACCESS_KEY":
{ "from_secret": "drone_cache_aws_secret_access_key"}
},
"pull": "if-not-exists",
"settings": {
"rebuild": "true",
"cache_key": "{{ .Repo.Namespace }}-{{ .Repo.Name }}-{{ .Commit.Branch }}-{{ arch }}-" + imagecachename,
"bucket": "cppalliance-drone-cache",
"region": "us-east-2",
"mount": mountpoints
}
}
steps=steps + [ post_step ]
return {
"name": "Linux %s" % name,
"kind": "pipeline",
"type": "docker",
"trigger": triggers,
"platform": {
"os": "linux",
"arch": arch
},
"clone": {
"retries": 5
},
"node": node,
"steps": steps
}
def windows_cxx(
name,
cxx="g++", cxxflags=None, packages=None, sources=None, llvm_os=None, llvm_ver=None,
arch="amd64", image="cppalliance/dronevs2019",
buildtype="boost", buildscript="",
environment={}, globalenv={},
triggers={ "branch": [ "master", "develop", "drone*", "bugfix/*", "feature/*", "fix/*", "pr/*" ] }, node={},
privileged=False):
job_env = {
"TRAVIS_OS_NAME": "windows",
"CXX": cxx,
"DRONE_JOB_BUILDTYPE": buildtype,
"BOOST_CI_URL": "https://github.com/boostorg/boost-ci/raw/master",
}
add_if_set(job_env, "CXXFLAGS", cxxflags)
add_if_set(job_env, "PACKAGES", packages)
add_if_set(job_env, "SOURCES", sources)
add_if_set(job_env, "LLVM_OS", llvm_os)
add_if_set(job_env, "LLVM_VER", llvm_ver)
job_env.update(globalenv)
job_env.update(environment)
if not buildscript:
buildscript = buildtype
buildscript_to_run = buildscript + '.bat'
return {
"name": "Windows %s" % name,
"kind": "pipeline",
"type": "docker",
"trigger": triggers,
"platform": {
"os": "windows",
"arch": arch
},
"node": node,
"steps": [
{
"name": "Everything",
"image": image,
"pull": "if-not-exists",
"privileged": privileged,
"environment": job_env,
"commands": [
"echo '============> SETUP'",
"echo $env:DRONE_STAGE_MACHINE",
# Install script
download_script_from_boostCI_pwsh('windows-cxx-install.bat', 'ci/drone'),
# Chosen build script inside .drone
download_script_from_boostCI_pwsh(buildscript_to_run, '.drone'),
"echo '============> PACKAGES'",
"ci/drone/windows-cxx-install.bat",
"echo '============> INSTALL AND COMPILE'",
"cmd /c .drone\\\\%s `& exit" % buildscript_to_run,
]
}
]
}
def osx_cxx(
name,
cxx=None, cxxflags=None, packages=None, sources=None, llvm_os=None, llvm_ver=None,
arch="amd64", osx_version=None, xcode_version=None,
buildtype="boost", buildscript="",
environment={}, globalenv={},
triggers={ "branch": [ "master", "develop", "drone*", "bugfix/*", "feature/*", "fix/*", "pr/*" ] }, node={},
privileged=False):
job_env = {
"TRAVIS_OS_NAME": "osx",
"CXX": cxx,
"DRONE_JOB_BUILDTYPE": buildtype,
"BOOST_CI_URL": "https://github.com/boostorg/boost-ci/raw/master",
}
add_if_set(job_env, "CXX", cxx)
add_if_set(job_env, "CXXFLAGS", cxxflags)
add_if_set(job_env, "PACKAGES", packages)
add_if_set(job_env, "SOURCES", sources)
add_if_set(job_env, "LLVM_OS", llvm_os)
add_if_set(job_env, "LLVM_VER", llvm_ver)
job_env.update(globalenv)
job_env.update(environment)
if not buildscript:
buildscript = buildtype
if xcode_version:
job_env["DEVELOPER_DIR"] = "/Applications/Xcode-" + xcode_version + ".app/Contents/Developer"
if not osx_version:
if xcode_version[0:2] in [ "16", "15"]:
osx_version="sonoma"
arch="arm64"
elif xcode_version[0:4] in [ "14.2", "14.3"]:
osx_version="sonoma"
arch="arm64"
elif xcode_version[0:2] in [ "14", "13"]:
osx_version="monterey"
arch="arm64"
elif xcode_version[0:4] in [ "12.5"]:
osx_version="monterey"
arch="arm64"
elif xcode_version[0:2] in [ "12","11","10"]:
osx_version="catalina"
elif xcode_version[0:1] in [ "9","8","7","6"]:
osx_version="highsierra"
elif not osx_version:
osx_version="catalina"
nodetmp={}
nodetmp.update(node)
nodetmp.update({"os": osx_version})
return {
"name": "OSX %s" % name,
"kind": "pipeline",
"type": "exec",
"trigger": triggers,
"platform": {
"os": "darwin",
"arch": arch
},
"node": nodetmp,
"steps": [
{
"name": "Everything",
"privileged" : privileged,
"environment": job_env,
"commands": unix_common("osx-cxx-install.sh", buildscript)
}
]
}
def freebsd_cxx(
name,
cxx=None, cxxflags=None, packages=None, sources=None, llvm_os=None, llvm_ver=None,
arch="amd64", freebsd_version="13.1",
buildtype="boost", buildscript="",
environment={}, globalenv={},
triggers={ "branch": [ "master", "develop", "drone*", "bugfix/*", "feature/*", "fix/*", "pr/*" ] }, node={},
privileged=False):
job_env = {
"TRAVIS_OS_NAME": "freebsd",
"DRONE_JOB_BUILDTYPE": buildtype,
"BOOST_CI_URL": "https://github.com/boostorg/boost-ci/raw/master",
}
add_if_set(job_env, "CXX", cxx)
add_if_set(job_env, "CXXFLAGS", cxxflags)
add_if_set(job_env, "PACKAGES", packages)
add_if_set(job_env, "SOURCES", sources)
add_if_set(job_env, "LLVM_OS", llvm_os)
add_if_set(job_env, "LLVM_VER", llvm_ver)
job_env.update(globalenv)
job_env.update(environment)
if not buildscript:
buildscript = buildtype
nodetmp={}
nodetmp.update(node)
nodetmp.update({"os": "freebsd" + freebsd_version})
return {
"name": "FreeBSD %s" % name,
"kind": "pipeline",
"type": "exec",
"trigger": triggers,
"platform": {
"os": "freebsd",
"arch": arch
},
"node": nodetmp,
"steps": [
{
"name": "Everything",
"privileged" : privileged,
"environment": job_env,
"commands": unix_common("freebsd-cxx-install.sh", buildscript)
}
]
}
# The functions job and job_impl were added in 2023-01 to provide a simplified job syntax.
# Instead of calling linux_cxx() directly, run job() instead.
#
# Define a job, i.e. a single entry in the build matrix
# It takes values for OS, compiler and C++-standard and optional arguments.
# A value of `None` means "unset" as opposed to an empty string which for environment variables will set them to empty.
def job_impl(
# Required:
os, compiler, cxxstd,
# Name of the job, a reasonable default will be generated based on the other arguments
name=None,
# `image` will be deduced from `os`, `arch` and `compiler` when not set
arch='amd64', image=None,
# Those correspond to the B2_* variables and hence arguments to b2 (with the default build.sh)
variant=None, address_model=None, stdlib=None, defines=None, cxxflags=None, linkflags=None, testflags=None,
# Sanitizers. Using any will set the variant to 'debug' and default `defines` to 'BOOST_NO_STRESS_TEST=1'
valgrind=False, asan=False, ubsan=False, tsan=False,
# Packages to install, will default to the compiler and the value of `install` (for additional packages)
packages=None, install='',
# If True then the LLVM repo corresponding to the Ubuntu image will be added
add_llvm=False,
# .drone/*.sh script to run
buildscript='drone',
# build type env variable (defaults to 'boost' or 'valgrind', sets the token when set to 'codecov')
buildtype=None,
# job specific environment
env={},
# Any other keyword arguments are passed directly to the *_cxx-function
**kwargs):
if not name:
deduced_name = True
name = compiler.replace('-', ' ')
if address_model:
name += ' x' + address_model
if stdlib:
name += ' ' + stdlib
if cxxstd:
name += ' C++' + cxxstd
if arch != 'amd64':
name = '%s: %s' % (arch.upper(), name)
else:
deduced_name = False
cxx = compiler.replace('gcc-', 'g++-')
if packages == None:
packages = cxx
if install:
packages += ' ' + install
env['B2_TOOLSET' if os == 'windows' else 'B2_COMPILER'] = compiler
if cxxstd != None:
env['B2_CXXSTD'] = cxxstd
if valgrind:
if buildtype == None:
buildtype = 'valgrind'
if testflags == None:
testflags = 'testing.launcher=valgrind'
env.setdefault('VALGRIND_OPTS', '--error-exitcode=1')
if asan or tsan:
kwargs['privileged'] = True
# Set env var if privileged is set by any means
if kwargs.get('privileged'):
env['DRONE_EXTRA_PRIVILEGED'] = 'True'
if asan:
env['B2_ASAN'] = '1'
if ubsan:
env['B2_UBSAN'] = '1'
if tsan:
env['B2_TSAN'] = '1'
# Set defaults for all sanitizers
if valgrind or asan or ubsan:
if variant == None:
variant = 'debug'
if defines == None:
defines = 'BOOST_NO_STRESS_TEST=1'
if variant != None:
env['B2_VARIANT'] = variant
if address_model != None:
env['B2_ADDRESS_MODEL'] = address_model
if stdlib != None:
env['B2_STDLIB'] = stdlib
if defines != None:
env['B2_DEFINES'] = defines
if cxxflags != None:
env['B2_CXXFLAGS'] = cxxflags
if linkflags != None:
env['B2_LINKFLAGS'] = linkflags
if testflags != None:
env['B2_TESTFLAGS'] = testflags
if buildtype == None:
buildtype = 'boost'
elif buildtype == 'codecov':
env.setdefault('CODECOV_TOKEN', {'from_secret': 'codecov_token'})
elif buildtype == 'coverity':
env.setdefault('COVERITY_SCAN_NOTIFICATION_EMAIL', {'from_secret': 'coverity_scan_email'})
env.setdefault('COVERITY_SCAN_TOKEN', {'from_secret': 'coverity_scan_token'})
# Put common args of all *_cxx calls not modified below into kwargs to avoid duplicating them
kwargs['arch'] = arch
kwargs['buildtype'] = buildtype
kwargs['buildscript'] = buildscript
kwargs['environment'] = env
if os.startswith('ubuntu'):
if not image:
image = 'cppalliance/droneubuntu%s:1' % os.split('-')[1].replace('.', '')
if arch != 'amd64':
image = image[0:-1] + 'multiarch'
if add_llvm:
names = {
'1604': 'xenial',
'1804': 'bionic',
'2004': 'focal',
'2204': 'jammy',
}
kwargs['llvm_os'] = names[image.split('ubuntu')[-1].split(':')[0]] # get part between 'ubuntu' and ':'
kwargs['llvm_ver'] = compiler.split('-')[1]
return linux_cxx(name, cxx, packages=packages, image=image, **kwargs)
elif os.startswith('freebsd'):
# Deduce version if os is `freebsd-<version>`
parts = os.split('freebsd-')
if len(parts) == 2:
version = kwargs.setdefault('freebsd_version', parts[1])
if deduced_name:
name = '%s %s' % (kwargs['freebsd_version'], name)
return freebsd_cxx(name, cxx, **kwargs)
elif os.startswith('osx'):
# If format is `osx-xcode-<version>` deduce xcode_version, else assume it is passed directly
parts = os.split('osx-xcode-')
if len(parts) == 2:
version = kwargs.setdefault('xcode_version', parts[1])
if deduced_name:
name = 'XCode %s: %s' % (version, name)
return osx_cxx(name, cxx, **kwargs)
elif os == 'windows':
if not image:
names = {
'msvc-14.0': 'dronevs2015',
'msvc-14.1': 'dronevs2017',
'msvc-14.2': 'dronevs2019:2',
'msvc-14.3': 'dronevs2022:1',
}
image = 'cppalliance/' + names[compiler]
kwargs.setdefault('cxx', '')
return windows_cxx(name, image=image, **kwargs)
else:
fail('Unknown OS:', os)