27
27
28
28
import platform
29
29
import re
30
+ import subprocess
30
31
import sys
31
32
import os
32
33
from os .path import join , dirname , abspath
@@ -142,6 +143,9 @@ LIBRARY_FLAGS = {
142
143
# Use visibility=default to disable this.
143
144
'CXXFLAGS' : ['-fvisibility=hidden' ]
144
145
},
146
+ 'strictaliasing:off' : {
147
+ 'CCFLAGS' : ['-fno-strict-aliasing' ]
148
+ },
145
149
'mode:debug' : {
146
150
'CCFLAGS' : ['-g' , '-O0' ],
147
151
'CPPDEFINES' : ['ENABLE_DISASSEMBLER' , 'DEBUG' ],
@@ -651,8 +655,16 @@ def Abort(message):
651
655
sys .exit (1 )
652
656
653
657
654
- def GuessToolchain (os ):
655
- tools = Environment ()['TOOLS' ]
658
+ def GuessOS (env ):
659
+ return utils .GuessOS ()
660
+
661
+
662
+ def GuessArch (env ):
663
+ return utils .GuessArchitecture ()
664
+
665
+
666
+ def GuessToolchain (env ):
667
+ tools = env ['TOOLS' ]
656
668
if 'gcc' in tools :
657
669
return 'gcc'
658
670
elif 'msvc' in tools :
@@ -661,7 +673,9 @@ def GuessToolchain(os):
661
673
return None
662
674
663
675
664
- def GuessVisibility (os , toolchain ):
676
+ def GuessVisibility (env ):
677
+ os = env ['os' ]
678
+ toolchain = env ['toolchain' ];
665
679
if (os == 'win32' or os == 'cygwin' ) and toolchain == 'gcc' :
666
680
# MinGW / Cygwin can't do it.
667
681
return 'default'
@@ -671,27 +685,35 @@ def GuessVisibility(os, toolchain):
671
685
return 'hidden'
672
686
673
687
674
- OS_GUESS = utils .GuessOS ()
675
- TOOLCHAIN_GUESS = GuessToolchain (OS_GUESS )
676
- ARCH_GUESS = utils .GuessArchitecture ()
677
- VISIBILITY_GUESS = GuessVisibility (OS_GUESS , TOOLCHAIN_GUESS )
688
+ def GuessStrictAliasing (env ):
689
+ # There seems to be a problem with gcc 4.5.x
690
+ # see http://code.google.com/p/v8/issues/detail?id=884
691
+ # it can be worked around by disabling strict aliasing
692
+ toolchain = env ['toolchain' ];
693
+ if toolchain == 'gcc' :
694
+ env = Environment (tools = ['gcc' ])
695
+ version = subprocess .Popen ([env ['CC' ], '-dumpversion' ],
696
+ stdout = subprocess .PIPE ).communicate ()[0 ]
697
+ if version .find ('4.5.' ) == 0 :
698
+ return 'off'
699
+ return 'default'
678
700
679
701
680
702
SIMPLE_OPTIONS = {
681
703
'toolchain' : {
682
704
'values' : ['gcc' , 'msvc' ],
683
- 'default ' : TOOLCHAIN_GUESS ,
684
- 'help' : 'the toolchain to use (%s)' % TOOLCHAIN_GUESS
705
+ 'guess ' : GuessToolchain ,
706
+ 'help' : 'the toolchain to use'
685
707
},
686
708
'os' : {
687
709
'values' : ['freebsd' , 'linux' , 'macos' , 'win32' , 'android' , 'openbsd' , 'solaris' , 'cygwin' ],
688
- 'default ' : OS_GUESS ,
689
- 'help' : 'the os to build for (%s)' % OS_GUESS
710
+ 'guess ' : GuessOS ,
711
+ 'help' : 'the os to build for'
690
712
},
691
713
'arch' : {
692
714
'values' :['arm' , 'ia32' , 'x64' , 'mips' ],
693
- 'default ' : ARCH_GUESS ,
694
- 'help' : 'the architecture to build for (%s)' % ARCH_GUESS
715
+ 'guess ' : GuessArch ,
716
+ 'help' : 'the architecture to build for'
695
717
},
696
718
'regexp' : {
697
719
'values' : ['native' , 'interpreted' ],
@@ -800,8 +822,15 @@ SIMPLE_OPTIONS = {
800
822
},
801
823
'visibility' : {
802
824
'values' : ['default' , 'hidden' ],
803
- 'default' : VISIBILITY_GUESS ,
804
- 'help' : 'shared library symbol visibility (%s)' % VISIBILITY_GUESS
825
+ 'guess' : GuessVisibility ,
826
+ 'depends' : ['os' , 'toolchain' ],
827
+ 'help' : 'shared library symbol visibility'
828
+ },
829
+ 'strictaliasing' : {
830
+ 'values' : ['default' , 'off' ],
831
+ 'guess' : GuessStrictAliasing ,
832
+ 'depends' : ['toolchain' ],
833
+ 'help' : 'assume strict aliasing while optimizing'
805
834
},
806
835
'pgo' : {
807
836
'values' : ['off' , 'instrument' , 'optimize' ],
@@ -811,19 +840,55 @@ SIMPLE_OPTIONS = {
811
840
}
812
841
813
842
843
+ def AddOption (result , name , option ):
844
+ if 'guess' in option :
845
+ # Option has a guess function
846
+ guess = option .get ('guess' )
847
+ guess_env = Environment (options = result )
848
+ # Check if all options that the guess function depends on are set
849
+ if 'depends' in option :
850
+ for dependency in option .get ('depends' ):
851
+ if not dependency in guess_env :
852
+ return False
853
+ default = guess (guess_env )
854
+ else :
855
+ # Option has a fixed default
856
+ default = option .get ('default' )
857
+
858
+ help = '%s (%s)' % (option .get ('help' ), ", " .join (option ['values' ]))
859
+ result .Add (name , help , default )
860
+ return True
861
+
862
+
814
863
def GetOptions ():
815
864
result = Options ()
816
865
result .Add ('mode' , 'compilation mode (debug, release)' , 'release' )
817
866
result .Add ('sample' , 'build sample (shell, process, lineprocessor)' , '' )
818
867
result .Add ('cache' , 'directory to use for scons build cache' , '' )
819
868
result .Add ('env' , 'override environment settings (NAME0:value0,NAME1:value1,...)' , '' )
820
869
result .Add ('importenv' , 'import environment settings (NAME0,NAME1,...)' , '' )
821
- for (name , option ) in SIMPLE_OPTIONS .iteritems ():
822
- help = '%s (%s)' % (name , ", " .join (option ['values' ]))
823
- result .Add (name , help , option .get ('default' ))
870
+ options = SIMPLE_OPTIONS
871
+ while len (options ):
872
+ postpone = {}
873
+ for (name , option ) in options .iteritems ():
874
+ if not AddOption (result , name , option ):
875
+ postpone [name ] = option
876
+ options = postpone
824
877
return result
825
878
826
879
880
+ def GetTools (opts ):
881
+ env = Environment (options = opts )
882
+ os = env ['os' ]
883
+ toolchain = env ['toolchain' ]
884
+ if os == 'win32' and toolchain == 'gcc' :
885
+ return ['mingw' ]
886
+ elif os == 'win32' and toolchain == 'msvc' :
887
+ return ['msvc' , 'mslink' , 'mslib' , 'msvs' ]
888
+ else :
889
+ return ['default' ]
890
+
891
+
827
892
def GetVersionComponents ():
828
893
MAJOR_VERSION_PATTERN = re .compile (r"#define\s+MAJOR_VERSION\s+(.*)" )
829
894
MINOR_VERSION_PATTERN = re .compile (r"#define\s+MINOR_VERSION\s+(.*)" )
@@ -904,7 +969,7 @@ def VerifyOptions(env):
904
969
print env ['simulator' ]
905
970
Abort ("Option unalignedaccesses only supported for the ARM architecture." )
906
971
for (name , option ) in SIMPLE_OPTIONS .iteritems ():
907
- if (not option . get ( 'default' )) and ( name not in ARGUMENTS ):
972
+ if (not name in env ):
908
973
message = ("A value for option %s must be specified (%s)." %
909
974
(name , ", " .join (option ['values' ])))
910
975
Abort (message )
@@ -1032,7 +1097,7 @@ def ParseEnvOverrides(arg, imports):
1032
1097
return overrides
1033
1098
1034
1099
1035
- def BuildSpecific (env , mode , env_overrides ):
1100
+ def BuildSpecific (env , mode , env_overrides , tools ):
1036
1101
options = {'mode' : mode }
1037
1102
for option in SIMPLE_OPTIONS :
1038
1103
options [option ] = env [option ]
@@ -1085,7 +1150,7 @@ def BuildSpecific(env, mode, env_overrides):
1085
1150
(object_files , shell_files , mksnapshot ) = env .SConscript (
1086
1151
join ('src' , 'SConscript' ),
1087
1152
build_dir = join ('obj' , target_id ),
1088
- exports = 'context' ,
1153
+ exports = 'context tools ' ,
1089
1154
duplicate = False
1090
1155
)
1091
1156
@@ -1105,21 +1170,21 @@ def BuildSpecific(env, mode, env_overrides):
1105
1170
library = env .SharedLibrary (library_name , object_files , PDB = pdb_name )
1106
1171
context .library_targets .append (library )
1107
1172
1108
- d8_env = Environment ()
1173
+ d8_env = Environment (tools = tools )
1109
1174
d8_env .Replace (** context .flags ['d8' ])
1110
1175
context .ApplyEnvOverrides (d8_env )
1111
1176
shell = d8_env .Program ('d8' + suffix , object_files + shell_files )
1112
1177
context .d8_targets .append (shell )
1113
1178
1114
1179
for sample in context .samples :
1115
- sample_env = Environment ()
1180
+ sample_env = Environment (tools = tools )
1116
1181
sample_env .Replace (** context .flags ['sample' ])
1117
1182
sample_env .Prepend (LIBS = [library_name ])
1118
1183
context .ApplyEnvOverrides (sample_env )
1119
1184
sample_object = sample_env .SConscript (
1120
1185
join ('samples' , 'SConscript' ),
1121
1186
build_dir = join ('obj' , 'sample' , sample , target_id ),
1122
- exports = 'sample context' ,
1187
+ exports = 'sample context tools ' ,
1123
1188
duplicate = False
1124
1189
)
1125
1190
sample_name = sample + suffix
@@ -1132,7 +1197,7 @@ def BuildSpecific(env, mode, env_overrides):
1132
1197
cctest_program = cctest_env .SConscript (
1133
1198
join ('test' , 'cctest' , 'SConscript' ),
1134
1199
build_dir = join ('obj' , 'test' , target_id ),
1135
- exports = 'context object_files' ,
1200
+ exports = 'context object_files tools ' ,
1136
1201
duplicate = False
1137
1202
)
1138
1203
context .cctest_targets .append (cctest_program )
@@ -1142,7 +1207,9 @@ def BuildSpecific(env, mode, env_overrides):
1142
1207
1143
1208
def Build ():
1144
1209
opts = GetOptions ()
1145
- env = Environment (options = opts )
1210
+ tools = GetTools (opts )
1211
+ env = Environment (options = opts , tools = tools )
1212
+
1146
1213
Help (opts .GenerateHelpText (env ))
1147
1214
VerifyOptions (env )
1148
1215
env_overrides = ParseEnvOverrides (env ['env' ], env ['importenv' ])
@@ -1156,7 +1223,7 @@ def Build():
1156
1223
d8s = []
1157
1224
modes = SplitList (env ['mode' ])
1158
1225
for mode in modes :
1159
- context = BuildSpecific (env .Copy (), mode , env_overrides )
1226
+ context = BuildSpecific (env .Copy (), mode , env_overrides , tools )
1160
1227
libraries += context .library_targets
1161
1228
mksnapshots += context .mksnapshot_targets
1162
1229
cctests += context .cctest_targets
0 commit comments