forked from forexample/package-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins.py
executable file
·111 lines (94 loc) · 3.05 KB
/
jenkins.py
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
#!/usr/bin/env python3
import argparse
import glob
import os
import shutil
import subprocess
import sys
parser = argparse.ArgumentParser(description="Testing script")
parser.add_argument('--shared', action='store_true', help='Build shared libs')
parser.add_argument(
'--install-boo', action='store_true', help='Install boo and run'
)
parser.add_argument(
'--monolithic', action='store_true', help='Build all in one'
)
cmd_args = parser.parse_args()
cwd = os.getcwd()
exe_dir = os.path.join(cwd, '_install', 'bin')
if not cmd_args.install_boo and cmd_args.shared:
# windows and cygwin
os.environ['PATH'] = '{};{}'.format(exe_dir, os.environ['PATH'])
def do_call(args):
oneline = ''
for i in args:
oneline += ' "{}"'.format(i)
print('[{}]>{}'.format(os.getcwd(), oneline))
try:
subprocess.check_call(args, env=os.environ)
except subprocess.CalledProcessError as error:
print(error)
print(error.output)
sys.exit(1)
if os.path.exists('_builds'):
shutil.rmtree('_builds')
if os.path.exists('_install'):
shutil.rmtree('_install')
if os.name == 'nt':
do_call(['where', 'cmake'])
else:
do_call(['which', 'cmake'])
do_call(['cmake', '--version'])
install_dir = os.path.join('_install')
def run_build(projname, buildtype, install, verbose, test):
os.chdir(cwd)
print('-' * 80)
print("+ {} {}".format(projname, buildtype))
print('-' * 80)
build_dir = os.path.join('_builds', '{}-{}'.format(projname, buildtype))
args = [
'cmake',
'-H{}'.format(projname),
'-B{}'.format(build_dir),
'-DCMAKE_BUILD_TYPE={}'.format(buildtype),
'-DCMAKE_INSTALL_PREFIX={}'.format(install_dir)
]
if buildtype != 'Release':
args += ['-DCMAKE_{}_POSTFIX=-{}'.format(buildtype.upper(), buildtype)]
if verbose:
args += ['-DCMAKE_VERBOSE_MAKEFILE=ON']
if cmd_args.shared:
args += ['-DBUILD_SHARED_LIBS=ON']
else:
args += ['-DBUILD_SHARED_LIBS=OFF']
do_call(args)
args = ['cmake', '--build', build_dir, '--config', buildtype]
if install:
args += ['--target', 'install']
do_call(args)
if test:
os.chdir(build_dir)
args = ['ctest', '-C', buildtype, '-VV']
do_call(args)
os.chdir(cwd)
run_test_after_install = False
if cmd_args.monolithic:
run_build('.', 'Release', install=True, verbose=True, test=False)
run_build('.', 'Debug', install=True, verbose=True, test=False)
run_test_after_install = True
else:
run_build('Foo', 'Release', install=True, verbose=False, test=False)
run_build('Foo', 'Debug', install=True, verbose=False, test=False)
if cmd_args.install_boo:
run_build('Boo', 'Release', install=True, verbose=True, test=False)
run_build('Boo', 'Debug', install=True, verbose=True, test=False)
run_test_after_install = True
else:
run_build('Boo', 'Release', install=False, verbose=True, test=True)
run_build('Boo', 'Debug', install=False, verbose=True, test=True)
if run_test_after_install:
executables = glob.glob(os.path.join(exe_dir, 'boo*'))
if len(executables) != 2:
sys.exit('Expected two executables')
for x in executables:
do_call([x])