@@ -95,6 +95,24 @@ SetOption('random', 1)
95
95
# using the nargs='const' mechanism.
96
96
#
97
97
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
+
98
116
add_option ('prefix' ,
99
117
default = '$BUILD_ROOT/install' ,
100
118
help = 'installation prefix' ,
@@ -659,6 +677,9 @@ env_vars.Add('ARFLAGS',
659
677
help = 'Sets flags for the archiver' ,
660
678
converter = variable_shlex_converter )
661
679
680
+ env_vars .Add ('CCACHE' ,
681
+ help = 'Path to ccache used for the --ccache option. Defaults to first ccache in PATH.' )
682
+
662
683
env_vars .Add (
663
684
'CACHE_SIZE' ,
664
685
help = 'Maximum size of the cache (in gigabytes)' ,
@@ -801,6 +822,20 @@ env_vars.Add('MSVC_USE_SCRIPT',
801
822
env_vars .Add ('MSVC_VERSION' ,
802
823
help = 'Sets the version of Visual Studio to use (e.g. 12.0, 11.0, 10.0)' )
803
824
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
+
804
839
env_vars .Add ('OBJCOPY' ,
805
840
help = 'Sets the path to objcopy' ,
806
841
default = WhereIs ('objcopy' ))
@@ -1477,12 +1512,18 @@ if link_model.startswith("dynamic"):
1477
1512
if optBuild :
1478
1513
env .SetConfigHeaderDefine ("MONGO_CONFIG_OPTIMIZED_BUILD" )
1479
1514
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
+ ):
1486
1527
# See http://www.scons.org/wiki/GoFastButton for details
1487
1528
env .Decider ('MD5-timestamp' )
1488
1529
env .SetOption ('max_drift' , 1 )
@@ -1541,12 +1582,9 @@ if env['_LIBDEPS'] == '$_LIBDEPS_OBJS':
1541
1582
fake_lib .write (str (uuid .uuid4 ()))
1542
1583
fake_lib .write ('\n ' )
1543
1584
1544
- def noop_action (env , target , source ):
1545
- pass
1546
-
1547
1585
env ['ARCOM' ] = write_uuid_to_file
1548
1586
env ['ARCOMSTR' ] = 'Generating placeholder library $TARGET'
1549
- env ['RANLIBCOM' ] = noop_action
1587
+ env ['RANLIBCOM' ] = ''
1550
1588
env ['RANLIBCOMSTR' ] = 'Skipping ranlib for $TARGET'
1551
1589
1552
1590
libdeps .setup_environment (env , emitting_shared = (link_model .startswith ("dynamic" )))
@@ -3673,6 +3711,70 @@ def doConfigure(myenv):
3673
3711
3674
3712
3675
3713
env = 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' )
3676
3778
3677
3779
# TODO: Later, this should live somewhere more graceful.
3678
3780
if get_option ('install-mode' ) == 'hygienic' :
@@ -3767,8 +3869,6 @@ if get_option('install-mode') == 'hygienic':
3767
3869
elif get_option ('separate-debug' ) == "on" :
3768
3870
env .FatalError ('Cannot use --separate-debug without --install-mode=hygienic' )
3769
3871
3770
- # Now that we are done with configure checks, enable icecream, if available.
3771
- env .Tool ('icecream' )
3772
3872
3773
3873
# If the flags in the environment are configured for -gsplit-dwarf,
3774
3874
# inject the necessary emitter.
0 commit comments