forked from MergHQ/CRYENGINE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
1283 lines (1041 loc) · 45 KB
/
wscript
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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
from waflib import Configure, Logs, Utils, Node, TaskGen, Options, ConfigSet
from waflib.Build import BuildContext, CleanContext, Context
from waflib.Tools import c_aliases, c
from waflib.Task import Task,RUN_ME
from waflib.Configure import conf, ConfigurationContext
from waflib.TaskGen import after_method, before_method, feature, extension
from waflib.Errors import BuildError, WafError
from waflib.TaskGen import taskgen_method
import os
import shutil
import ConfigParser
import traceback
import time
import subprocess
import sys
try:
import _winreg
except:
pass
# Load globals from branch spec file if we must
from waf_branch_spec import PLATFORMS
from waf_branch_spec import CONFIGURATIONS
g_bootstrap_was_run = False
###############################################################################
Configure.autoconfig = True
###############################################################################
CRY_WAF_TOOL_DIR='Code/Tools/waf-1.7.13/crywaflib'
###############################################################################
# List of subfolders to parse
SUBFOLDERS = [
'Code',
'Engine',
]
###############################################################################
## Configure Options for WAF
def options(opt):
opt.load('cry_utils' ,tooldir=CRY_WAF_TOOL_DIR)
opt.load('project_settings', tooldir=CRY_WAF_TOOL_DIR)
opt.load('branch_spec', tooldir=CRY_WAF_TOOL_DIR)
opt.load('gui_tasks' , tooldir=CRY_WAF_TOOL_DIR)
###########################################
# Load support for Uber Files
opt.load('generate_uber_files' ,tooldir=CRY_WAF_TOOL_DIR)
###########################################
# Load Project Generators based on host (use the custom cry versions)
host = Utils.unversioned_sys_platform()
opt.load('msvs', tooldir=CRY_WAF_TOOL_DIR)
opt.load('msvs_override_handling', tooldir=CRY_WAF_TOOL_DIR)
opt.load('mscv_helper' ,tooldir=CRY_WAF_TOOL_DIR)
if host == 'darwin':
opt.load('xcode' ,tooldir=CRY_WAF_TOOL_DIR)
if host == 'linux':
opt.load('eclipse' ,tooldir=CRY_WAF_TOOL_DIR)
# Load tools to improve dependency checking (by using compiler features)
if host == 'win32':
opt.load('mscv_helper', tooldir=CRY_WAF_TOOL_DIR)
opt.load('msvcdeps', tooldir=CRY_WAF_TOOL_DIR)
opt.load('gccdeps', tooldir=CRY_WAF_TOOL_DIR)
# Load internal module extensions
module_extension_toolsdir = CRY_WAF_TOOL_DIR + '/module_extensions'
for file_name in [each for each in os.listdir(module_extension_toolsdir) if each.endswith('.py')]:
opt.load(file_name[:-3], tooldir=module_extension_toolsdir)
# Load custom user module extensions
custom_module_extensions = Context.launch_dir + '/_WAF_/custom_module_extensions'
if os.path.exists(custom_module_extensions):
for file_name in [each for each in os.listdir(custom_module_extensions) if each.endswith('.py')]:
opt.load(file_name[:-3], tooldir=custom_module_extensions)
###########################################
# Add custom cryengine options
opt.add_option('-p', '--project-spec', dest='project_spec', action='store', default='', help='Spec to use when building the project')
# Add special command line option to prevent recursive execution of WAF
opt.add_option('--internal-dont-check-recursive-execution', dest='internal_dont_check_recursive_execution', action='store', default='False', help='!INTERNAL ONLY! DONT USE')
# Add options primarily used by the Visual Studio WAF Addin
waf_addin_group = opt.add_option_group('Visual Studio WAF Addin Options')
waf_addin_group.add_option('-a', '--ask-for-user-input', dest='ask_for_user_input', action='store', default='True', help='Disables all user promps in WAF')
waf_addin_group.add_option( '--file-filter', dest='file_filter', action='store', default="", help='Only compile files matching this filter')
waf_addin_group.add_option( '--show-includes', dest='show_includes', action='store', default='False', help='Show all files included (requires a file_filter)')
waf_addin_group.add_option( '--show-preprocessed-file', dest='show_preprocessed_file', action='store', default='False', help='Generate only Preprocessor Output (requires a file_filter)')
waf_addin_group.add_option( '--show-disassembly', dest='show_disassembly', action='store', default='False', help='Generate only Assembler Output (requires a file_filter)')
# DEPRECATED OPTIONS, only used to keep backwards compatibility
waf_addin_group.add_option( '--output-file', dest='output_file', action='store', default="", help='*DEPRECATED* Specify Output File for Disassemly or Preprocess option (requires a file_filter)')
waf_addin_group.add_option( '--use-overwrite-file', dest='use_overwrite_file', action='store', default="False", help='*DEPRECATED* Use special BinTemp/cry_waf.configuration_overwrites to specify per target configurations')
waf_addin_group.add_option( '--console-mode', dest='console_mode', action='store', default="False", help='No Gui. Display console only')
waf_addin_group.add_option( '--generate-product', dest='generate_product', action='store', default="False", help='Generate CryEngine product version (internal use)')
# Lastly, load data driven settings
opt.load('default_settings', tooldir=CRY_WAF_TOOL_DIR)
opt.load('cryengine_modules', tooldir=CRY_WAF_TOOL_DIR)
###############################################################################
## Configure 'configure' step
def configure(conf):
###########################################
# Load base configuration function
conf.load('c_config')
sys_platform = Utils.unversioned_sys_platform()
if sys_platform == 'linux':
host = 'linux_x64'
elif sys_platform== 'win32':
host = 'win_x64'
elif sys_platform== 'darwin':
host = 'darwin_x64'
#Download SDKs for first time git users
if not conf.is_bootstrap_available():
if not os.path.isdir(os.path.join(conf.path.abspath(), 'Code/SDKs')):
download_sdk_exe = os.path.join(conf.path.abspath(), 'download_sdks.exe')
if host == 'win_x64':
if os.path.isfile(download_sdk_exe):
subprocess.call(download_sdk_exe)
else:
conf.fatal('[ERROR] Missing 3rd party SDK folder "<root>/Code/SDKs". \nAuto download failed: "<root>/download_sdks.exe" could not be located.\nPlease follow the ReadMe instructions on GitHub to download the SDKs manually.' )
else:
try:
subprocess.call(["python3","download_sdks.py"])
except:
conf.fatal('[ERROR] Missing 3rd party SDK folder "<root>/Code/SDKs". \nAuto download failed: "<root>/download_sdks.py" could not be located or Python3 is not available.\nPlease follow the ReadMe instructions on GitHub to download the SDKs manually.' )
###########################################
# Check for changes in user settings file
conf.check_user_settings_files()
###########################################
# Load common windows settings if needed
conf.load('winres', tooldir=CRY_WAF_TOOL_DIR)
# Load common platform scripts
conf.load('compile_settings_cryengine', tooldir=CRY_WAF_TOOL_DIR)
conf.load('compile_settings_msvc', tooldir=CRY_WAF_TOOL_DIR)
conf.load('compile_settings_gcc', tooldir=CRY_WAF_TOOL_DIR)
conf.load('compile_settings_clang', tooldir=CRY_WAF_TOOL_DIR)
conf.load('compile_settings_windows', tooldir=CRY_WAF_TOOL_DIR)
conf.load('compile_settings_linux', tooldir=CRY_WAF_TOOL_DIR)
conf.load('compile_settings_linux_x86', tooldir=CRY_WAF_TOOL_DIR)
conf.load('compile_settings_linux_x64', tooldir=CRY_WAF_TOOL_DIR)
conf.load('compile_settings_darwin', tooldir=CRY_WAF_TOOL_DIR)
optional_platforms = [
'durango',
'orbis'
]
for platform in optional_platforms:
file_name = 'compile_settings_' + platform
if os.path.isfile(os.path.join(conf.path.abspath(), CRY_WAF_TOOL_DIR, file_name + '.py')):
conf.load(file_name, tooldir=CRY_WAF_TOOL_DIR)
else:
try:
conf.get_supported_platforms().remove(platform)
except:
pass
Logs.warn('[WARNING] - Compiler settings not found. (%s) ' % file_name )
# Load CppCheck since it is a 'global' platform
conf.load('cppcheck', tooldir=CRY_WAF_TOOL_DIR)
# Load QT last as we need to hook the runnable status at the lowest level
conf.load('qt' ,tooldir=CRY_WAF_TOOL_DIR)
###########################################
# Load support for c# and swig
conf.load('swig', tooldir=CRY_WAF_TOOL_DIR)
conf.load('cs', tooldir=CRY_WAF_TOOL_DIR)
#Get user defined active specs
specs_platforms = set()
if conf.options.specs_to_include_in_project_generation:
spec_list = conf.options.specs_to_include_in_project_generation.replace(' ', '').split(',')
else: # Special case for Buildbot which sets no spec for specs_to_include_in_project_generation.
spec_list = conf.loaded_specs()
# Get the platform list of all active specs
tmp_specs_platforms = set()
for spec in spec_list:
for platform in conf.get_supported_platforms():
tmp_specs_platforms.update(conf.spec_valid_platforms(spec, platform))
# Convert to complete platform names i.e. win -> win_x64 and win_x86
for valid_platform in tmp_specs_platforms:
for value in conf.get_platform_permutation_map(valid_platform).values():
specs_platforms.update(value)
###########################################
# Load settings for all platforms
platforms_done = ''
installed_platforms = []
for platform in conf.get_supported_platforms():
# Check if platform is required for active specs
if platform not in specs_platforms:
continue
Logs.info('[INFO] Configure "%s - [%s]"' % (platform, ', '.join(conf.get_supported_configurations())))
# Load Platform Configuration (except cppcheck as it is not a *real* compiler)
if platform != 'cppcheck':
file_name = 'compile_rules_' + host + '_' + platform
if os.path.isfile(os.path.join(conf.path.abspath(), CRY_WAF_TOOL_DIR, file_name + '.py')):
conf.load('compile_rules_' + host + '_' + platform, tooldir=CRY_WAF_TOOL_DIR)
# Use the specialized function to load platform specifics
function_name = 'check_%s_%s_installed' % ( host, platform )
if not hasattr(conf, function_name):
conf.fatal('[ERROR] Required function \'%s\' not found' % function_name )
# Try to load the function
if not getattr(conf, function_name)():
Logs.warn('[WARNING] - Unable to locate platform "%s" on system. Disabling platform support for: %s !!!' % (platform, platform))
continue
else:
Logs.warn('[WARNING] - Unable to locate compiler rules "%s". Disabling platform support for: %s !!!. ' % (file_name, platform))
continue
# platform installed
installed_platforms.append(platform)
for configuration in conf.get_supported_configurations():
conf.setenv(platform + '_' + configuration) # change env to configuration env
conf.init_compiler_settings()
# Use the specialized function to load platform specifics
function_name = 'load_%s_%s_%s_settings' % ( configuration, host, platform )
if not hasattr(conf, function_name):
conf.fatal('[ERROR] Required function \'%s\' not found' % function_name )
# Try to load the function
getattr(conf, function_name)()
conf.configure_qt()
# Load swig and mono
conf.configure_swig()
conf.configure_mono()
conf.env['build_relevant_platforms'] = installed_platforms
conf.setenv('') # change env back to global env
conf.set_supported_platforms(installed_platforms)
conf.env['build_relevant_platforms'] = installed_platforms # need to store in global cache as well for project_generators
###########################################
# Load support for c and cxx compiler
conf.load('c')
conf.load('cxx')
conf.load('protoc',tooldir=CRY_WAF_TOOL_DIR)
###########################################
# Load Platform specific helpers based on host
host = Utils.unversioned_sys_platform()
if host == 'darwin':
conf.load('c_osx')
###########################################
# Create VS-Projects automatically during configure when running on windows
if host == 'win32' and conf.is_option_true('generate_vs_projects_automatically'):
# Workflow improvement: for all builds generate projects after the build
# except when using the default build target 'utilities' then do it before
if 'build' in Options.commands:
build_cmd_idx = Options.commands.index('build')
Options.commands.insert(build_cmd_idx, 'msvs')
else:
Options.commands.append('msvs')
###########################################
# Load remaining tools for correct auto configure
if host == 'win32':
conf.load('recode', tooldir=CRY_WAF_TOOL_DIR)
conf.load('static_code_analyzer', tooldir=CRY_WAF_TOOL_DIR)
###########################################
# Recurse into subfolders for auto conf when any wscript changes
conf.recurse(dirs=SUBFOLDERS, mandatory=False)
# Load Game Specific parts
for project in conf.game_projects():
conf.game_project = project
conf.recurse( conf.game_code_folder(project))
###########################################
# Always update uber files during configuration
# But don't add the same command twice
if len(Options.commands) == 0:
Options.commands.insert(0, 'generate_uber_files')
elif not Options.commands[0] == 'generate_uber_files':
Options.commands.insert(0, 'generate_uber_files')
# Remove timestamp files to force builds of generate_uber_files and project gen even if
# some command after configure failes
try:
generate_uber_files_timestamp = conf.get_bintemp_folder_node().make_node('generate_uber_files.timestamp')
os.stat(generate_uber_files_timestamp.abspath())
except OSError:
pass
else:
generate_uber_files_timestamp.delete()
try:
project_gen_timestamp = conf.get_bintemp_folder_node().make_node('project_gen.timestamp')
os.stat(project_gen_timestamp.abspath())
except OSError:
pass
else:
project_gen_timestamp.delete()
def post_command_exec(bld):
# [post project gen]
if bld.cmd == 'msvs':
project_gen_timestamp = bld.get_bintemp_folder_node().make_node('project_gen.timestamp')
project_gen_timestamp.write('')
# [post uberfile gen]
elif bld.cmd == 'generate_uber_files':
generate_uber_files_timestamp = bld.get_bintemp_folder_node().make_node('generate_uber_files.timestamp')
generate_uber_files_timestamp.write('')
# [post build]
elif bld.cmd.startswith('build'):
for message in bld.post_build_msg_info:
Logs.info(message)
for message in bld.post_build_msg_warning:
Logs.warn(message)
for message in bld.post_build_msg_error:
Logs.error(message)
stored_file_filter = ''
stored_output_file = ''
###############################################################################
## Run 'build' step
def build(bld):
# Keep backward compatibility
if bld.options.project_spec == 'everything':
bld.options.project_spec = 'trybuilder'
bld.options.project_spec = bld.options.project_spec.strip() # remove spaces
# Create a post build message container
bld.post_build_msg_info = []
bld.post_build_msg_warning = []
bld.post_build_msg_error = []
# Add groups to ensure all task generators who create static lib tasks are executd first
bld.add_group('generate_static_lib')
bld.add_group('regular_group')
# Set back to our regular compile group
bld.set_group('regular_group')
###########################################
# Load common windows settings if needed
bld.load('winres', tooldir=CRY_WAF_TOOL_DIR)
# Check if a valid spec is defined
if bld.cmd != 'generate_uber_files' and bld.cmd != 'msvs' and bld.cmd != 'eclipse':
# project spec is a mandatory parameter
if bld.options.project_spec == '':
bld.fatal('[ERROR] No Project Spec defined. Use "-p <spec_name>" command line option to specify project spec. Valid specs are "%s". ' % bld.loaded_specs())
# Ensure that the selected spec is supported on this platform
if not bld.options.project_spec in bld.loaded_specs():
bld.fatal('[ERROR] Invalid Project Spec (%s) defined, valid specs are %s' % (bld.options.project_spec, bld.loaded_specs()))
# Check for valid single file compilation flag pairs
if bld.is_option_true('show_preprocessed_file') and bld.options.file_filter == "":
bld.fatal('--show-preprocessed-file can only be used in conjunction with --file-filter')
elif bld.is_option_true('show_disassembly') and bld.options.file_filter == "":
bld.fatal('--show-disassembly can only be used in conjunction with --file-filter')
###########################################
# Check timestamps for special commands
if not 'generate_uber_files' in Options.commands and bld.cmd != 'generate_uber_files':
generate_uber_files_timestamp = bld.get_bintemp_folder_node().make_node('generate_uber_files.timestamp')
try:
os.stat(generate_uber_files_timestamp.abspath())
except OSError:
# No generate_uber file timestamp, restart command chain, prefixed with gen uber files cmd
Options.commands = ['generate_uber_files'] + [bld.cmd] + Options.commands
return
if not 'msvs' in Options.commands and bld.cmd != 'msvs':
project_gen_timestamp = bld.get_bintemp_folder_node().make_node('project_gen.timestamp')
try:
os.stat(project_gen_timestamp.abspath())
except OSError:
# No project_gen timestamp, append project_gen to commands
if bld.is_option_true('generate_vs_projects_automatically') and Utils.unversioned_sys_platform() == 'win32':
if not bld.is_option_true('internal_dont_check_recursive_execution'):
Options.commands = Options.commands + ['msvs']
###########################################
# Check for valid variant if we are not generating projects
if bld.cmd == 'xcode' or bld.cmd == 'msvs' or bld.cmd == 'eclipse' or bld.cmd == 'generate_uber_files':
bld.env['PLATFORM'] = 'project_generator'
bld.env['CONFIGURATION'] = 'project_generator'
else:
if not bld.variant:
bld.fatal('please use a valid build configuration, try "waf --help"')
(platform, configuration) = bld.get_platform_and_configuration()
bld.env['PLATFORM'] = platform
bld.env['CONFIGURATION'] = configuration
if not platform in bld.get_supported_platforms():
bld.fatal( '[ERROR] - Target platform "%s" not supported. [on host platform: %s]' % (platform, Utils.unversioned_sys_platform()) )
# When building, only support platform that we are currently building for to reduce internal workload
bld.set_supported_platforms([bld.env['PLATFORM']])
# check if configuration is valid in the current spec scope
bVariantValid = False
for conf in bld.spec_valid_configurations():
if conf == configuration:
bVariantValid = True
if not bVariantValid:
bld.fatal('[ERROR] Building Spec "%s" for "%s|%s" is not supported. Valid Configurations are: "%s".' % (bld.options.project_spec, platform, configuration, ', '.join(bld.spec_valid_configurations())))
# check if platform is valid in the current spec scope
bVariantValid = False
for p0 in bld.spec_valid_platforms():
for p1 in bld.get_platform_list(bld.env['PLATFORM']):
if p0 == p1:
bVariantValid = True
if not bVariantValid:
bld.fatal('[ERROR] Building Spec "%s" for "%s|%s" is not supported.. Valid Platforms are: "%s".' % (bld.options.project_spec, platform, configuration, ', '.join(bld.spec_valid_platforms())))
# Ensure that, if specified, target is supported in this spec
if bld.options.targets:
for target in bld.options.targets.split(','):
if not target in bld.spec_modules():
bld.fatal('[ERROR] Module "%s" is not configurated to be build in spec "%s" in "%s|%s"' % (target, bld.options.project_spec, platform, configuration))
###########################################
# Setup command coordinator
bld.load('cmd_coordinator', tooldir=CRY_WAF_TOOL_DIR)
bld.setup_command_coordinator()
# We might run multiple instances of WAF at the same time
# 1) IB as master ... The WAF IB instance (master) will handle task creation and will intercept each call to a .exe file making it the "Build Master" ... the original WAF instance should just exit here
# 2) IB as service ... The original WAF instance(master) will handle the task creation and "may" forward the .exe calls to the IB instance (slave)
if not bld.instance_is_build_master():
return
###########################################
bld.add_post_fun(post_command_exec)
###########################################
# Setup Output Path for Project Geneators
bld.solution_name = bld.get_solution_name()
bld.projects_dir = bld.get_project_output_folder()
###########################################
# Load configuration overwrites
bld.env['CONFIG_OVERWRITES'] = bld.get_solution_overrides()
###########################################
# Disable optimizations if requested
# Must be done after computing overrides
if bld.is_option_true('force_deoptimized_builds'):
bld.env['CFLAGS'] += bld.env['COMPILER_FLAGS_DisableOptimization']
bld.env['CXXFLAGS'] += bld.env['COMPILER_FLAGS_DisableOptimization']
###########################################
# Load Support for Recode if required
host = Utils.unversioned_sys_platform()
if host == 'win32':
bld.load('recode', tooldir=CRY_WAF_TOOL_DIR)
if str(bld.options.support_recode) == str(True):
bld.enable_recode = bld.check_global_recode_enabled()
###########################################
# Add support for static code analyzer
bld.load('static_code_analyzer', tooldir=CRY_WAF_TOOL_DIR)
# Clear <output folder>/Image/Loose on durango as a workaround for buggy deploy
if bld.env['PLATFORM'] == 'durango':
for node in bld.get_output_folders(bld.env['PLATFORM'], bld.env['CONFIGURATION']):
image_lost_dir = node.find_dir('Image/Loose')
if image_lost_dir:
files = image_lost_dir.ant_glob('**/*')
for f in files:
f.chmod(493) # 0755
f.delete()
# Load Core Engine Parts (Engine, Tools, Core Shaders etc)
bld.game_project = None
bld.recurse(SUBFOLDERS, mandatory=False)
# Load Game Specific parts
for project in bld.game_projects():
bld.game_project = project
bld.recurse( bld.game_code_folder(project))
###############################################################################
@conf
def target_clean(self):
tmp_targets = self.options.targets[:]
to_delete = []
# Sort of recursive algorithm, find all outputs of targets
# Repeat if new targets were added due to use directives
while len(tmp_targets) > 0:
new_targets = []
for tgen in self.get_all_task_gen():
tgen.post()
if not tgen.target in tmp_targets:
continue
for t in tgen.tasks:
# Collect outputs
for n in t.outputs:
if n.is_child_of(self.bldnode):
to_delete.append(n)
# Check for use flag
if hasattr(tgen, 'use'):
new_targets.append(tgen.use)
# Copy new targets
tmp_targets = new_targets[:]
# Final File list to delete
to_delete = list(set(to_delete))
for file in to_delete:
file.delete()
###############################################################################
# Copy pasted from MSVS..
def convert_vs_configuration_to_waf_configuration(configuration):
if 'Debug' in configuration:
return 'debug'
if 'Profile' in configuration:
return 'profile'
if 'Release' in configuration:
return 'release'
if 'Performance' in configuration:
return 'performance'
return ''
###############################################################################
@conf
def utilities(bld):
if not bld.is_option_true('ask_for_user_input'):
return
# Function to handle creating of new libraries
def install_waf_addin():
enviroment = os.environ.copy()
if not 'APPDATA' in enviroment:
print 'APPDATA enviroment variable not found, WAF cannot figure out where to install the addin'
return
install_path = enviroment['APPDATA'] + '\\Microsoft\\MSEnvShared\\Addins'
source_path = bld.path.abspath() + '\\Code\\Tools\\waf_addin\\Bin_Release'
Logs.info('WAF Addin will be installed into:\n%s' % install_path)
bld.start_msg('Create Install directory')
try:
if not os.path.exists(install_path):
os.makedirs(install_path)
except:
bld.end_msg('failed (%s)' % sys.exc_info()[1], color='RED')
else:
bld.end_msg('ok')
for file in ['WAF_Addin.AddIn', 'WAF_Addin.dll', 'WAF_Addin.xml']:
bld.start_msg('Copy %s to install directory' % file)
# Make output writeable
try:
os.chmod(install_path + '\\' + file, 493) # 0755
except:
pass
try:
shutil.copy2(source_path + '\\' + file, install_path + '\\' + file)
except:
bld.end_msg('failed (%s)' % sys.exc_info()[1], color='RED')
else:
bld.end_msg('ok')
Options.commands.insert(0, 'utilities')
def reconfigure_waf():
Options.commands.insert(0, 'configure')
def bootstrap_update():
bld.ExecuteBootstrap()
Options.commands.insert(0, 'utilities')
def regenerate_vs_solution():
Options.commands.insert(0, 'utilities')
Options.commands.insert(0, 'msvs')
def regenerate_uber_files():
Options.commands.insert(0, 'utilities')
Options.commands.insert(0, 'generate_uber_files')
def regenerate_config_file():
print type(bld)
# Remove current config file and remove some state
config_file = bld.get_user_settings_node()
config_file.delete()
# Load user settings
bld.load_user_settings()
# Afterwards return to utilies dialog
Options.commands.insert(0, 'utilities')
def apply_new_crycommon_layout_to_custom_folder():
folder = raw_input('Please enter absolute folder path: ')
if os.path.isdir(folder):
bld.convert_files_in_folder_to_cry_common([bld.root.make_node(folder)])
else:
Logs.error("Folder could not be found.", folder)
Options.commands.insert(0, 'utilities')
def waf_options():
Options.commands.insert(0, 'utilities')
Options.commands.insert(0, 'show_option_dialog')
# Function to handle exit requests
def exit():
pass
if not bld.is_option_true('console_mode'):
conversion_file = ['Apply new CryCommon layout', [
('Custom folder and subfolders', apply_new_crycommon_layout_to_custom_folder)
]]
menu_file = ['', [
('Exit', exit)
]]
menu_regenerate = ['Generate', [
("Visual Studio Solution", regenerate_vs_solution),
("Uber Files", regenerate_uber_files)
]]
menu_tools = ['Tools', [
("Options", waf_options),
("Configure", reconfigure_waf)
]]
if bld.is_bootstrap_available():
menu_tools[1] += [("Run Bootstrap", bootstrap_update)]
#menu_tools[1] += [("Install WAF Addin", install_waf_addin)] # disabled as unmaintained
fn_result = bld.gui_get_waf_menu_choice([menu_tools, menu_regenerate, conversion_file, menu_file])
if fn_result:
fn_result() # Execute result
else:
Options.commands.insert(0, 'utilities')
else:
choices = [
(exit, 'Exit'),
#(install_waf_addin,Install WAF Addin), # disabled as unmaintained
(regenerate_vs_solution, 'Regenerate Visual Studio Solution'),
(regenerate_uber_files, 'Regenerate Uber Files'),
(regenerate_config_file, 'Regenerate Config File')
]
if bld.is_bootstrap_available():
choices += [(bootstrap_update, 'Run Bootstrap Update')]
print(' === Crytek WAF Build System === ')
print(' Please use waf --help to see all valid build targets and build options')
for idx, option in enumerate(choices):
print('%s: %s' % (idx, option[1]))
user_input = raw_input('Please select an option: ')
print('')
# Sanity check for valid user inputs
try:
if int(user_input) < int(0) or int(user_input) > len(choices):
raise
except:
print('Invalid Input, please choose a value between 1 and %s', len(choices))
Options.commands.insert(0, 'utilities')
return
# Input is fine, exectue selection
if int(user_input) == 1:
return
print type(bld)
choices[int(user_input)][0]()
##############################################################################
class execute_utilities(BuildContext):
''' Util class to execute waf utilities dialog '''
cmd = 'utilities'
fun = 'utilities'
###############################################################################
# Create Build Context Commands for multiple platforms/configurations
for platform in PLATFORMS[Utils.unversioned_sys_platform()]:
for configuration in CONFIGURATIONS:
# Create new class to execute build with variant
name = CleanContext.__name__.replace('Context','').lower()
class tmp_clean(CleanContext):
cmd = name + '_' + platform + '_' + configuration
variant = platform + '_' + configuration
def __init__(self, **kw):
super(CleanContext, self).__init__(**kw)
self.top_dir = kw.get('top_dir', Context.top_dir)
def execute(self):
if Configure.autoconfig:
env = ConfigSet.ConfigSet()
do_config = False
try:
env.load(os.path.join(Context.lock_dir, Options.lockfile))
except Exception:
Logs.warn('Configuring the project')
do_config = True
else:
if env.run_dir != Context.run_dir:
do_config = True
else:
h = 0
for f in env['files']:
try:
h = hash((h, Utils.readf(f, 'rb')))
except (IOError, EOFError):
pass # ignore missing files (will cause a rerun cause of the changed hash)
do_config = h != env.hash
if do_config:
Options.commands.insert(0, self.cmd)
Options.commands.insert(0, 'configure')
return
# Execute custom clear command
self.restore()
if not self.all_envs:
self.load_envs()
self.recurse([self.run_dir])
if self.options.targets:
self.target_clean()
else:
try:
self.clean()
finally:
self.store()
# Create new class to execute clean with variant
name = BuildContext.__name__.replace('Context','').lower()
class tmp_build(BuildContext):
cmd = name + '_' + platform + '_' + configuration
variant = platform + '_' + configuration
###############################################################################
# Install Default variant
for y in (BuildContext, CleanContext):
class tmp(y):
variant = 'utilities'
fun = 'utilities'
###############################################################################
# Create Commands for backwards compatibility
if Utils.unversioned_sys_platform() == 'win32':
for configuration in CONFIGURATIONS:
for context in (BuildContext, CleanContext):
name = context.__name__.replace('Context','').lower()
class tmp(context):
cmd = name + '_win32_' + configuration
variant = 'win_x86_' + configuration
for configuration in CONFIGURATIONS:
for context in (BuildContext, CleanContext):
name = context.__name__.replace('Context','').lower()
class tmp(context):
cmd = name + '_win64_' + configuration
variant = 'win_x64_' + configuration
@taskgen_method
def copy_files(self, source_file, output_folders = None):
if not output_folders:
output_folders = self.bld.get_output_folders(self.bld.env['PLATFORM'], self.bld.env['CONFIGURATION'])
for node in output_folders:
output_node = node
if hasattr(self, 'output_sub_folder'):
_output_sub_folder = str(self.output_sub_folder)
if os.path.isabs(_output_sub_folder):
output_node = self.bld.root.make_node(_output_sub_folder)
else:
output_node = output_node.make_node(_output_sub_folder)
output_node = output_node.make_node( os.path.basename(source_file.abspath()) )
path = os.path.dirname( output_node.abspath() )
if not os.path.exists( path ):
os.makedirs( path )
self.create_task('copy_outputs', source_file, output_node)
###############################################################################
# Class to handle copying of the final outputs into the Bin folder
class copy_outputs(Task):
color = 'YELLOW'
def run(self):
src = self.inputs[0].abspath()
tgt = self.outputs[0].abspath()
# Create output folder
if not os.path.exists( os.path.dirname( tgt ) ):
try:
os.makedirs( os.path.dirname( tgt ) )
except:
pass # Some other thread must have created the folder in the meantime
def _copy_file(src, tgt, recursion_count = 0):
# Make output writeable
try:
os.chmod(tgt, 493) # 0755
except:
pass
try:
shutil.copy2(src, tgt)
except (IOError, os.error) as why:
# Try again
if recursion_count < 2:
time.sleep(1)
recursion_count += 1
return _copy_file(src, tgt, recursion_count)
self.err_msg = "[Error] %s\n[Error] Could not perform copy %s -> %s" % (str(why), src, tgt)
return -1
except:
# Try again
if recursion_count < 2:
time.sleep(1)
recursion_count += 1
return _copy_file(src, tgt, recursion_count)
self.err_msg = "[Error] Could not perform copy %s -> %s" % (src, tgt)
return -1
return 0
# Copy file
return _copy_file(src, tgt)
def runnable_status(self):
if super(copy_outputs, self).runnable_status() == -1:
return -1
src = self.inputs[0].abspath()
tgt = self.outputs[0].abspath()
# If there any target file is missing, we have to copy
try:
stat_tgt = os.stat(tgt)
except OSError:
return RUN_ME
# Now compare both file stats
try:
stat_src = os.stat(src)
except OSError:
pass
else:
# same size and identical timestamps -> make no copy
if stat_src.st_mtime >= stat_tgt.st_mtime + 2 or stat_src.st_size != stat_tgt.st_size:
return RUN_ME
# Everything fine, we can skip this task
return -2 # SKIP_ME
###############################################################################
# Function to generate the copy tasks for build outputs
@after_method('set_pdb_flags')
@after_method('apply_incpaths')
@after_method('apply_map_file')
@feature('c', 'cxx')
def add_install_copy(self, output_folders = None):
if self.bld.cmd == "msvs" or 'android' in self.bld.env['PLATFORM']:
return
if not getattr(self, 'link_task', None):
return
if self._type == 'stlib': # Do not copy static libs
return
for src in self.link_task.outputs:
self.copy_files(src, output_folders)
###############################################################################
# Function to generate the EXE_VERSION_INFO defines
@after_method('apply_incpaths')
@feature('c', 'cxx')
def apply_version_info(self):
version = str( self.bld.get_product_version() )
version_parts = version.split('.')
if len(version_parts) < 3:
Logs.warn('Invalid build version (%s), falling back to (1.0.0.1)' % version )
version_parts = ['1', '0', '0', '1']
version_parts[0] = version_parts[0].strip()
version_parts[1] = version_parts[1].strip()
version_parts[2] = version_parts[2].strip()
version_parts[3] = version_parts[3].strip()
for t in getattr(self, 'compiled_tasks', []):
t.env.append_value('DEFINES', 'EXE_VERSION_INFO_0=' + version_parts[0])
t.env.append_value('DEFINES', 'EXE_VERSION_INFO_1=' + version_parts[1])
t.env.append_value('DEFINES', 'EXE_VERSION_INFO_2=' + version_parts[2])
t.env.append_value('DEFINES', 'EXE_VERSION_INFO_3=' + version_parts[3])
###############################################################################
def wrap_execute(execute_method):
"""
Decorator used to set the commands that can be configured automatically
"""
def execute(self):
# Make sure to create all needed temp folders
bin_temp = self.get_bintemp_folder_node()
bin_temp.mkdir()
tmp_files_folder = bin_temp.make_node('TempFiles')
tmp_files_folder.mkdir()
# Before executing any build or configure commands, check for config file
# and for bootstrap updates
self.load_user_settings()
check_for_bootstrap(self)
return execute_method(self)
return execute
BuildContext.execute = wrap_execute(BuildContext.execute)
ConfigurationContext.execute = wrap_execute(ConfigurationContext.execute)
###############################################################################
def check_for_bootstrap(bld):
global g_bootstrap_was_run
if g_bootstrap_was_run:
return
g_bootstrap_was_run = True
if not (bld.is_bootstrap_available() and bld.is_option_true('auto_run_bootstrap')):
return # Skip auto bootstrapping
bootstrap_dat = bld.path.make_node('bootstrap.dat')
bootstrap_timestamp = bld.get_bintemp_folder_node().make_node('bootstrap.timestamp')
# Check for bootstrap.dat
try:
stat_bootstrap_dat = os.stat(bootstrap_dat.abspath())
except OSError:
bld.fatal('bootstrap.dat file not found')
# Check for bootstrap.timestamp, run bootstrap is it doesn't exist
try:
stat_bootstrap_timestamp = os.stat(bootstrap_timestamp.abspath())
if stat_bootstrap_dat.st_mtime < stat_bootstrap_timestamp.st_mtime + 2:
return # No need to bootstrap