@@ -95,6 +95,24 @@ SetOption('random', 1)
9595# using the nargs='const' mechanism.
9696#
9797
98+ add_option ('ninja' ,
99+ choices = ['true' , 'false' ],
100+ default = 'false' ,
101+ nargs = '?' ,
102+ const = 'true' ,
103+ type = 'choice' ,
104+ help = 'Enable the build.ninja generator tool' ,
105+ )
106+
107+ add_option ('ccache' ,
108+ choices = ['true' , 'false' ],
109+ default = 'false' ,
110+ nargs = '?' ,
111+ const = 'true' ,
112+ type = 'choice' ,
113+ help = 'Enable ccache support' ,
114+ )
115+
98116add_option ('prefix' ,
99117 default = '$BUILD_ROOT/install' ,
100118 help = 'installation prefix' ,
@@ -659,6 +677,9 @@ env_vars.Add('ARFLAGS',
659677 help = 'Sets flags for the archiver' ,
660678 converter = variable_shlex_converter )
661679
680+ env_vars .Add ('CCACHE' ,
681+ help = 'Path to ccache used for the --ccache option. Defaults to first ccache in PATH.' )
682+
662683env_vars .Add (
663684 'CACHE_SIZE' ,
664685 help = 'Maximum size of the cache (in gigabytes)' ,
@@ -801,6 +822,20 @@ env_vars.Add('MSVC_USE_SCRIPT',
801822env_vars .Add ('MSVC_VERSION' ,
802823 help = 'Sets the version of Visual Studio to use (e.g. 12.0, 11.0, 10.0)' )
803824
825+ env_vars .Add ('NINJA_SUFFIX' ,
826+ help = """A suffix to add to the end of generated build.ninja
827+ files. Useful for when compiling multiple build ninja files for
828+ different configurations, for instance:
829+
830+ scons --sanitize=asan --ninja NINJA_SUFFIX=asan ninja-install-all-meta
831+ scons --sanitize=tsan --ninja NINJA_SUFFIX=tsan ninja-install-all-meta
832+
833+ Will generate the files (respectively):
834+
835+ install-all-meta.build.ninja.asan
836+ install-all-meta.build.ninja.tsan
837+ """ )
838+
804839env_vars .Add ('OBJCOPY' ,
805840 help = 'Sets the path to objcopy' ,
806841 default = WhereIs ('objcopy' ))
@@ -1477,12 +1512,18 @@ if link_model.startswith("dynamic"):
14771512if optBuild :
14781513 env .SetConfigHeaderDefine ("MONGO_CONFIG_OPTIMIZED_BUILD" )
14791514
1480- # Enable the fast decider if exlicltly requested or if in 'auto' mode and not in conflict with other
1481- # options.
1482- if get_option ('build-fast-and-loose' ) == 'on' or \
1483- (get_option ('build-fast-and-loose' ) == 'auto' and \
1484- not has_option ('release' ) and \
1485- not has_option ('cache' )):
1515+ # Enable the fast decider if explicitly requested or if in 'auto' mode
1516+ # and not in conflict with other options like the ninja option which
1517+ # sets it's own decider
1518+ if (
1519+ not get_option ('ninja' ) == 'true' and
1520+ get_option ('build-fast-and-loose' ) == 'on' or
1521+ (
1522+ get_option ('build-fast-and-loose' ) == 'auto' and
1523+ not has_option ('release' ) and
1524+ not has_option ('cache' )
1525+ )
1526+ ):
14861527 # See http://www.scons.org/wiki/GoFastButton for details
14871528 env .Decider ('MD5-timestamp' )
14881529 env .SetOption ('max_drift' , 1 )
@@ -1541,12 +1582,9 @@ if env['_LIBDEPS'] == '$_LIBDEPS_OBJS':
15411582 fake_lib .write (str (uuid .uuid4 ()))
15421583 fake_lib .write ('\n ' )
15431584
1544- def noop_action (env , target , source ):
1545- pass
1546-
15471585 env ['ARCOM' ] = write_uuid_to_file
15481586 env ['ARCOMSTR' ] = 'Generating placeholder library $TARGET'
1549- env ['RANLIBCOM' ] = noop_action
1587+ env ['RANLIBCOM' ] = ''
15501588 env ['RANLIBCOMSTR' ] = 'Skipping ranlib for $TARGET'
15511589
15521590libdeps .setup_environment (env , emitting_shared = (link_model .startswith ("dynamic" )))
@@ -3673,6 +3711,70 @@ def doConfigure(myenv):
36733711
36743712
36753713env = doConfigure ( env )
3714+ env ["NINJA_SYNTAX" ] = "#site_scons/third_party/ninja_syntax.py"
3715+
3716+ # Now that we are done with configure checks, enable icecream, if available.
3717+ env .Tool ('icecream' )
3718+
3719+ if get_option ('ninja' ) == 'true' :
3720+ env .Tool ("ninja" )
3721+ def test_txt_writer (alias_name ):
3722+ """Find all the tests registered to alias_name and write them to a file via ninja."""
3723+ rule_written = False
3724+
3725+ def wrapper (env , ninja , node , dependencies ):
3726+ """Make a Ninja-able version of the test files."""
3727+ rule = alias_name .upper () + "_GENERATOR"
3728+ if not rule_written :
3729+ ninja .rule (
3730+ rule ,
3731+ description = "Generate test list text file" ,
3732+ command = "echo $in > $out" ,
3733+ )
3734+ rule_written = True
3735+
3736+ alias = env .Alias (alias_name )
3737+ paths = []
3738+ children = alias .children ()
3739+ for child in children :
3740+ paths .append ('\t ' + str (child ))
3741+
3742+ ninja .build (
3743+ str (node ),
3744+ rule ,
3745+ inputs = '\n ' .join (paths ),
3746+ implicit = dependencies ,
3747+ )
3748+
3749+ return wrapper
3750+ env .NinjaRegisterFunctionHandler ("unit_test_list_builder_action" , test_txt_writer ('$UNITTEST_ALIAS' ))
3751+ env .NinjaRegisterFunctionHandler ("integration_test_list_builder_action" , test_txt_writer ('$INTEGRATION_TEST_ALIAS' ))
3752+ env .NinjaRegisterFunctionHandler ("benchmark_list_builder_action" , test_txt_writer ('$BENCHMARK_ALIAS' ))
3753+
3754+ def fakelib_in_ninja ():
3755+ """Generates empty .a files"""
3756+ rule_written = False
3757+
3758+ def wrapper (env , ninja , node , dependencies ):
3759+ if not rule_written :
3760+ cmd = "touch $out"
3761+ if not env .TargetOSIs ("posix" ):
3762+ cmd = "cmd /c copy NUL $out"
3763+ ninja .rule (
3764+ "FAKELIB" ,
3765+ command = cmd ,
3766+ )
3767+ rule_written = True
3768+
3769+ ninja .build (node .get_path (), rule = 'FAKELIB' , implicit = dependencies )
3770+
3771+ return wrapper
3772+
3773+ env .NinjaRegisterFunctionHandler ("write_uuid_to_file" , fakelib_in_ninja ())
3774+
3775+ # Load ccache after icecream since order matters when we're both changing CCCOM
3776+ if get_option ('ccache' ) == 'true' :
3777+ env .Tool ('ccache' )
36763778
36773779# TODO: Later, this should live somewhere more graceful.
36783780if get_option ('install-mode' ) == 'hygienic' :
@@ -3767,8 +3869,6 @@ if get_option('install-mode') == 'hygienic':
37673869elif get_option ('separate-debug' ) == "on" :
37683870 env .FatalError ('Cannot use --separate-debug without --install-mode=hygienic' )
37693871
3770- # Now that we are done with configure checks, enable icecream, if available.
3771- env .Tool ('icecream' )
37723872
37733873# If the flags in the environment are configured for -gsplit-dwarf,
37743874# inject the necessary emitter.
0 commit comments