forked from ruslo/polly
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpolly.py
More file actions
executable file
·561 lines (463 loc) · 15.1 KB
/
polly.py
File metadata and controls
executable file
·561 lines (463 loc) · 15.1 KB
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
#!/usr/bin/env python3
# Copyright (c) 2014-2015, Ruslan Baratov
# All rights reserved.
import argparse
import os
import platform
import shutil
import sys
import detail.call
import detail.cpack_generator
import detail.create_archive
import detail.create_framework
import detail.generate_command
import detail.get_nmake_environment
import detail.ios_dev_root
import detail.logging
import detail.open_project
import detail.osx_dev_root
import detail.pack_command
import detail.rmtree
import detail.target
import detail.test_command
import detail.timer
import detail.toolchain_name
import detail.toolchain_table
import detail.verify_mingw_path
import detail.verify_msys_path
toolchain_table = detail.toolchain_table.toolchain_table
assert(sys.version_info.major == 3)
assert(sys.version_info.minor >= 2) # Current cygwin version is 3.2.3
print(
'Python version: {}.{}'.format(
sys.version_info.major, sys.version_info.minor
)
)
description="""
Script for building. Available toolchains:\n
"""
for x in toolchain_table:
description += ' ' + x.name + '\n'
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=description
)
parser.add_argument(
'--toolchain',
choices=[x.name for x in toolchain_table],
help="CMake generator/toolchain",
)
parser.add_argument(
'--config',
help="CMake build type (Release, Debug, ...)",
)
parser.add_argument(
'--keep-going',
action='store_true',
help="Continue as much as possible after an error. see make -k"
)
parser.add_argument(
'--config-all',
help="CMake build type for project and hunter packages: --config <type> --fwd HUNTER_CONFIGURATION_TYPES=<type>",
)
parser.add_argument(
'--home',
help="Project home directory (directory with CMakeLists.txt)"
)
parser.add_argument(
'--output',
help="Project build directory (i.e., cmake -B)"
)
parser.add_argument(
'--cache',
help="CMake -C <initial-cache> = Pre-load a script to populate the cache."
)
parser.add_argument('--test', action='store_true', help="Run ctest after build")
parser.add_argument('--test-xml', help="Save ctest output to xml")
parser.add_argument(
'--pack',
choices=detail.cpack_generator.available_generators,
nargs='?',
const=detail.cpack_generator.default(),
help="Run cpack after build"
)
parser.add_argument(
'--archive',
help="Create an archive of locally installed files"
)
parser.add_argument(
'--nobuild', action='store_true', help="Do not build (only generate)"
)
parser.add_argument(
'--open', action='store_true', help="Open generated project (for IDE)"
)
verbosity_group=parser.add_mutually_exclusive_group()
verbosity_group.add_argument(
'--verbosity-level', dest='verbosity', help="Verbosity level",
choices=['silent', 'normal', 'full'], default='normal'
)
verbosity_group.add_argument('--verbose', action='store_true', help="Full verbose output")
parser.add_argument(
'--install', action='store_true', help="Run install (local directory)"
)
parser.add_argument(
'--ios-multiarch',
action='store_true',
help="Build multi-architecture binary (effectively add CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO)"
)
parser.add_argument(
'--ios-combined',
action='store_true',
help="Combine iOS simulator and device libraries on install (effectively add CMAKE_IOS_INSTALL_COMBINED=YES)"
)
parser.add_argument(
'--framework', action='store_true', help="Create framework"
)
parser.add_argument(
'--framework-device',
action='store_true',
help="Create framework for device (exclude simulator architectures)"
)
parser.add_argument(
'--framework-lib',
default='*',
help="Regular expression for the source library used for --framework"
)
parser.add_argument(
'--strip', action='store_true', help="Run strip/install cmake targets"
)
parser.add_argument(
'--identity',
help="Specify code signing identity for --framework"
)
parser.add_argument(
'--plist',
help="User specified Info.plist file for --framework"
)
parser.add_argument(
'--clear',
action='store_true',
help="Remove build and install dirs before build"
)
parser.add_argument(
'--reconfig',
action='store_true',
help="Run configure even if CMakeCache.txt exists. Used to add new args."
)
parser.add_argument(
'--fwd',
nargs='*',
help="Arguments to cmake without '-D', like:\nBOOST_ROOT=/some/path"
)
parser.add_argument(
'--iossim',
action='store_true',
help="Build for ios simulator"
)
parser.add_argument(
'--jobs',
type=int,
help="Number of concurrent build operations"
)
parser.add_argument(
'--target',
help="Target to build for the 'cmake --build' command"
)
def PositiveInt(string):
value = int(string)
if value > 0:
return value
m = 'Should be greater that zero: {}'.format(string)
raise argparse.ArgumentTypeError(m)
parser.add_argument(
'--discard',
type=PositiveInt,
help='Option to reduce output. Discard every N lines of execution messages'
' (note that full log is still available in log.txt)'
)
parser.add_argument(
'--tail',
type=PositiveInt,
help='Print last N lines if build failed'
)
parser.add_argument(
'--output_filter',
help="Output filter"
)
parser.add_argument(
'--timeout',
type=PositiveInt,
help='Timeout for CTest'
)
parser.add_argument(
'--cmake',
help="CMake binary (cmake or cmake3)"
)
parser.add_argument(
'--cpack',
help="CPack binary (cpack or cpack3)"
)
parser.add_argument(
'--ctest',
help="CTest binary (ctest or ctest3)"
)
parser.add_argument(
'--dry-run',
action='store_true',
help="Print the corresponding CMake command and quit"
)
args = parser.parse_args()
polly_toolchain = detail.toolchain_name.get(args.toolchain)
toolchain_entry = detail.toolchain_table.get_by_name(polly_toolchain)
cpack_generator = args.pack
polly_root = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
polly_root = os.path.realpath(polly_root)
if args.config and args.config_all:
sys.exit('Must specify --config or --config-all but not both')
if args.config_all:
args.config = args.config_all
"""Build directory tag"""
if args.config and not toolchain_entry.multiconfig:
build_tag = "{}-{}".format(polly_toolchain, args.config)
else:
build_tag = polly_toolchain
"""Tune environment"""
if toolchain_entry.name.startswith('mingw'):
mingw_path = os.getenv("MINGW_PATH")
detail.verify_mingw_path.verify(mingw_path)
os.environ['PATH'] = "{};{}".format(mingw_path, os.getenv('PATH'))
if toolchain_entry.name.startswith('msys'):
msys_path = os.getenv("MSYS_PATH")
detail.verify_msys_path.verify(msys_path)
os.environ['PATH'] = "{};{}".format(msys_path, os.getenv('PATH'))
vs_ninja = toolchain_entry.is_ninja and toolchain_entry.vs_version
if toolchain_entry.is_nmake or vs_ninja:
os.environ = detail.get_nmake_environment.get(
toolchain_entry.arch, toolchain_entry.vs_version
)
if toolchain_entry.ios_version:
ios_dev_root = detail.ios_dev_root.get(toolchain_entry.ios_version)
if ios_dev_root:
print("Set environment DEVELOPER_DIR to {}".format(ios_dev_root))
os.environ['DEVELOPER_DIR'] = ios_dev_root
if toolchain_entry.nocodesign:
xcconfig = os.path.join(polly_root, 'scripts', 'NoCodeSign.xcconfig')
print("Set environment XCODE_XCCONFIG_FILE to {}".format(xcconfig))
os.environ['XCODE_XCCONFIG_FILE'] = xcconfig
if toolchain_entry.osx_version:
osx_dev_root = detail.osx_dev_root.get(toolchain_entry.osx_version)
if osx_dev_root:
print("Set environment DEVELOPER_DIR to {}".format(osx_dev_root))
os.environ['DEVELOPER_DIR'] = osx_dev_root
toolchain_path = os.path.join(polly_root, "{}.cmake".format(polly_toolchain))
if not os.path.exists(toolchain_path):
sys.exit("Toolchain file not found: {}".format(toolchain_path))
toolchain_option = "-DCMAKE_TOOLCHAIN_FILE={}".format(toolchain_path)
if args.output:
if not os.path.isdir(args.output):
sys.exit("Specified build directory does not exist: {}".format(args.output))
if not os.access(args.output, os.W_OK):
sys.exit("Specified build directory is not writeable: {}".format(args.output))
cdir = args.output
else:
cdir = os.getcwd()
home = '.'
if args.home:
home = args.home
# Check the existence of CMakeLists.txt and exit before creating any directories
cmakelists_path = '{}/CMakeLists.txt'.format(home)
if not os.path.exists(cmakelists_path):
sys.exit('Specified path for CMakeList does not exist: {}'.format(cmakelists_path))
build_dir = os.path.join(cdir, '_builds', build_tag)
print("Build dir: {}".format(build_dir))
build_dir_option = "-B{}".format(build_dir)
install_dir = os.path.join(cdir, '_install', polly_toolchain)
local_install = args.install or args.strip or args.framework or args.framework_device or args.archive
if args.install and args.strip:
sys.exit('Both --install and --strip specified')
if args.strip:
install_target_name = 'install/strip'
elif local_install:
install_target_name = 'install'
else:
install_target_name = '' # not used
target = detail.target.Target()
target.add(condition=local_install, name=install_target_name)
target.add(condition=args.target, name=args.target)
# After 'target.add'
if args.strip and not toolchain_entry.is_make:
sys.exit('CMake install/strip targets are only supported for the Unix Makefile generator')
if local_install:
install_dir_option = "-DCMAKE_INSTALL_PREFIX={}".format(install_dir)
if (args.framework or args.framework_device) and platform.system() != 'Darwin':
sys.exit('Framework creation only for Mac OS X')
framework_dir = os.path.join(cdir, '_framework', polly_toolchain)
archives_dir = os.path.join(cdir, '_archives')
if args.clear:
detail.rmtree.rmtree(build_dir)
detail.rmtree.rmtree(install_dir)
detail.rmtree.rmtree(framework_dir)
# --verbose flag triggers full verbosity level
if args.verbose:
args.verbosity='full'
polly_temp_dir = os.path.join(build_dir, '_3rdParty', 'polly')
if not os.path.exists(polly_temp_dir):
os.makedirs(polly_temp_dir)
logging = detail.logging.Logging(
cdir, args.verbosity, args.discard, args.tail, polly_toolchain
)
if args.cmake:
cmake_bin = args.cmake
else:
cmake_bin = 'cmake'
if os.path.isabs(cmake_bin):
if not os.path.exists(cmake_bin):
sys.exit("CMake binary not found: {}".format(cmake_bin))
else:
if os.name == 'nt':
# Windows
detail.call.call(['where', cmake_bin], logging)
else:
detail.call.call(['which', cmake_bin], logging)
detail.call.call([cmake_bin, '--version'], logging)
generate_command = [
cmake_bin,
'-H{}'.format(home),
build_dir_option
]
if args.cache:
if not os.path.isfile(args.cache):
sys.exit("Specified cache file does not exist: {}".format(args.cache))
if not os.access(args.cache, os.R_OK):
sys.exit("Specified cache file is not readable: {}".format(args.cache))
generate_command.append("-C{}".format(args.cache))
if (args.config and not toolchain_entry.multiconfig) or args.config_all:
generate_command.append("-DCMAKE_BUILD_TYPE={}".format(args.config))
if toolchain_entry.generator:
generate_command.append('-G{}'.format(toolchain_entry.generator))
if toolchain_entry.toolset:
generate_command.append('-T{}'.format(toolchain_entry.toolset))
if toolchain_entry.xp:
toolset = 'v{}0_xp'.format(toolchain_entry.vs_version)
generate_command.append('-T{}'.format(toolset))
if toolchain_option:
generate_command.append(toolchain_option)
if args.verbosity == 'full':
generate_command.append('-DCMAKE_VERBOSE_MAKEFILE=ON')
generate_command.append('-DPOLLY_STATUS_DEBUG=ON')
generate_command.append('-DHUNTER_STATUS_DEBUG=ON')
if args.ios_multiarch:
generate_command.append('-DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO')
if args.ios_combined:
generate_command.append('-DCMAKE_IOS_INSTALL_COMBINED=YES')
if local_install:
generate_command.append(install_dir_option)
if cpack_generator:
generate_command.append('-DCPACK_GENERATOR={}'.format(cpack_generator))
if args.fwd != None:
for x in args.fwd:
generate_command.append("-D{}".format(x))
if args.config_all:
generate_command.append("-DHUNTER_CONFIGURATION_TYPES={}".format(args.config_all))
timer = detail.timer.Timer()
timer.start('Generate')
detail.generate_command.run(
generate_command, build_dir, polly_temp_dir, args.reconfig, logging, args.output_filter, args.dry_run
)
timer.stop()
build_command = [
cmake_bin,
'--build',
build_dir
]
if args.config:
build_command.append('--config')
build_command.append(args.config)
build_command += target.args()
# NOTE: This must be the last `build_command` modification!
build_command.append('--')
if args.iossim:
build_command.append('-sdk')
build_command.append('iphonesimulator')
if args.jobs:
if toolchain_entry.is_xcode:
build_command.append('-jobs')
build_command.append('{}'.format(args.jobs))
elif toolchain_entry.is_make and not toolchain_entry.is_nmake:
build_command.append('-j')
build_command.append('{}'.format(args.jobs))
elif toolchain_entry.is_msvc and (int(toolchain_entry.vs_version) >= 12):
build_command.append('/maxcpucount:{}'.format(args.jobs))
if args.keep_going:
if toolchain_entry.is_make:
build_command.append('-k') ## keep going
if not args.nobuild:
timer.start('Build')
if toolchain_entry.is_xcode:
# Workaround for https://gitlab.kitware.com/cmake/cmake/issues/17851
zero_check_command = [
cmake_bin,
'--build',
build_dir,
'--target',
'ZERO_CHECK'
]
detail.call.call(zero_check_command, logging, sleep=1)
detail.call.call(build_command, logging, sleep=1, output_filter=args.output_filter)
timer.stop()
if args.archive:
timer.start('Archive creation')
detail.create_archive.run(
install_dir,
archives_dir,
args.archive,
toolchain_entry.name,
args.config
)
timer.stop()
if args.framework or args.framework_device:
timer.start('Framework creation')
detail.create_framework.run(
install_dir,
framework_dir,
toolchain_entry.ios_version,
polly_root,
args.framework_device,
logging,
args.plist,
args.identity,
args.framework_lib
)
timer.stop()
if not args.nobuild:
os.chdir(build_dir)
if args.test or args.test_xml:
timer.start('Test')
if args.ctest:
ctest_bin = args.ctest
else:
ctest_bin = 'ctest'
if os.path.isabs(ctest_bin):
if not os.path.exists(ctest_bin):
sys.exit("Ctest binary not found: {}".format(ctest_bin))
detail.test_command.run(build_dir, args.config, logging, args.test_xml, args.verbosity == 'full', args.timeout, ctest_bin)
timer.stop()
if args.pack:
timer.start('Pack')
if args.cpack:
cpack_bin = args.cpack
else:
cpack_bin = 'cpack'
if os.path.isabs(cpack_bin):
if not os.path.exists(cpack_bin):
sys.exit("CPack binary not found: {}".format(cpack_bin))
detail.pack_command.run(args.config, logging, cpack_generator, cpack_bin, cmake_bin)
timer.stop()
if args.open:
detail.open_project.open(toolchain_entry, build_dir, logging)
print('-')
print('Log saved: {}'.format(logging.log_path))
print('-')
timer.result()
print('-')
print('SUCCESS')