summaryrefslogtreecommitdiff
path: root/src/mongo/SConscript
blob: eb2db8e7cc0d32bfde04dbea840e4d6fbe511b64 (plain)
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
# -*- mode: python; -*-

# This SConscript describes build rules for the "mongo" project.

import itertools
import os
import re
import sys
from buildscripts import utils

Import("env")
Import("has_option")
Import("get_option")
Import("usemozjs")
Import("use_system_version_of_library")
Import("use_libunwind")
Import("wiredtiger")

env = env.Clone()

env.InjectMongoIncludePaths()

env.SConscript(
    dirs=[
        'base',
        'bson',
        'client',
        'crypto',
        'db',
        'dbtests',
        'embedded',
        'executor',
        'idl',
        'installer',
        'logger',
        'logv2',
        'platform',
        'rpc',
        's',
        'scripting',
        'shell',
        'stdx',
        'tools',
        'transport',
        'unittest',
        'util',
        'watchdog',
    ],
    exports=[
        'env',
    ],
)

# NOTE: The 'base' library does not really belong here. Its presence
# here is temporary. Do not add to this library, do not remove from
# it, and do not declare other libraries in this file.
baseEnv = env.Clone()

if use_libunwind == True:
    baseEnv.InjectThirdParty('unwind')

quick_exit_env = baseEnv.Clone()
if has_option('gcov'):
    quick_exit_env.Append(
        CPPDEFINES=[
            'MONGO_GCOV',
        ],
    )
quick_exit_obj = baseEnv.LibraryObject(
    target='quick_exit',
    source=[
        'util/quick_exit.cpp',
    ],
)[0]

debugger_env = baseEnv.Clone()
if has_option("gdbserver"):
    debugger_env.Append(CPPDEFINES=["USE_GDBSERVER"])
elif has_option("lldb-server"):
    debugger_env.Append(CPPDEFINES=["USE_LLDB_SERVER"])

debugger_obj = debugger_env.LibraryObject(
    target='debugger',
    source=[
        'util/debugger.cpp',
    ],
)[0]

baseEnv.Library(
    target='base',
    source=[
        'base/data_range.cpp',
        'base/data_range_cursor.cpp',
        'base/data_type.cpp',
        'base/data_type_string_data.cpp',
        'base/data_type_terminated.cpp',
        'base/error_codes.cpp',
        'base/error_extra_info.cpp',
        'base/global_initializer.cpp',
        'base/global_initializer_registerer.cpp',
        'base/init.cpp',
        'base/initializer.cpp',
        'base/initializer_dependency_graph.cpp',
        'base/parse_number.cpp',
        'base/shim.cpp',
        'base/simple_string_data_comparator.cpp',
        'base/status.cpp',
        'base/string_data.cpp',
        'base/validate_locale.cpp',
        'bson/bson_comparator_interface_base.cpp',
        'bson/bson_depth.cpp',
        'bson/bson_validate.cpp',
        'bson/bsonelement.cpp',
        'bson/bsonmisc.cpp',
        'bson/bsonobj.cpp',
        'bson/bsonobjbuilder.cpp',
        'bson/bsontypes.cpp',
        'bson/json.cpp',
        'bson/oid.cpp',
        'bson/simple_bsonelement_comparator.cpp',
        'bson/simple_bsonobj_comparator.cpp',
        'bson/timestamp.cpp',
        'logger/component_message_log_domain.cpp',
        'logger/console.cpp',
        'logger/log_manager.cpp',
        'logger/logger.cpp',
        'logger/message_event_utf8_encoder.cpp',
        'logger/ramlog.cpp',
        'logger/rotatable_file_manager.cpp',
        'logger/rotatable_file_writer.cpp',
        'logv2/attributes.cpp',
        'logv2/bson_formatter.cpp',
        'logv2/console.cpp',
        'logv2/file_rotate_sink.cpp',
        'logv2/json_formatter.cpp',
        'logv2/log_component.cpp',
        'logv2/log_component_settings.cpp',
        'logv2/log_detail.cpp',
        'logv2/log_domain.cpp',
        'logv2/log_domain_global.cpp',
        'logv2/log_domain_internal.cpp',
        'logv2/log_manager.cpp',
        'logv2/log_severity.cpp',
        'logv2/log_tag.cpp',
        'logv2/log_util.cpp',
        'logv2/plain_formatter.cpp',
        'logv2/ramlog.cpp',
        'logv2/redaction.cpp',
        'logv2/shared_access_fstream.cpp',
        'logv2/text_formatter.cpp',
        'platform/decimal128.cpp',
        'platform/mutex.cpp',
        'platform/posix_fadvise.cpp',
        'platform/process_id.cpp',
        'platform/random.cpp',
        'platform/shared_library.cpp',
        'platform/shared_library_${TARGET_OS_FAMILY}.cpp',
        'platform/stack_locator.cpp',
        'platform/stack_locator_${TARGET_OS}.cpp',
        'platform/strcasestr.cpp',
        'platform/strnlen.cpp',
        'util/allocator.cpp',
        'util/assert_util.cpp',
        'util/base64.cpp',
        'util/boost_assert_impl.cpp',
        'util/concurrency/idle_thread_block.cpp',
        'util/concurrency/thread_name.cpp',
        'util/duration.cpp',
        'util/errno_util.cpp',
        'util/exception_filter_win32.cpp',
        'util/exit.cpp',
        'util/file.cpp',
        'util/hex.cpp',
        'util/itoa.cpp',
        'util/platform_init.cpp',
        'util/shell_exec.cpp',
        'util/signal_handlers_synchronous.cpp',
        'util/stacktrace.cpp',
        'util/stacktrace_${TARGET_OS_FAMILY}.cpp',
        'util/stacktrace_somap.cpp',
        'util/stacktrace_threads.cpp',
        'util/str.cpp',
        'util/str_escape.cpp',
        'util/system_clock_source.cpp',
        'util/system_tick_source.cpp',
        'util/testing_proctor.cpp',
        'util/text.cpp',
        'util/thread_safety_context.cpp',
        'util/time_support.cpp',
        'util/timer.cpp',
        'util/uuid.cpp',
        'util/version.cpp',
        debugger_obj,
        quick_exit_obj,
    ],
    # NOTE: This library *must not* depend on any libraries than
    # the ones declared here. Do not add to this list.
    LIBDEPS=[
        '$BUILD_DIR/third_party/murmurhash3/murmurhash3',
        '$BUILD_DIR/third_party/shim_abseil',
        '$BUILD_DIR/third_party/shim_boost',
        '$BUILD_DIR/third_party/shim_fmt',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/third_party/shim_intel_decimal128',
        '$BUILD_DIR/third_party/shim_pcrecpp',
        '$BUILD_DIR/third_party/shim_unwind' if use_libunwind else [],
        'boost_assert_shim',
        'stdx/stdx',
    ],
    AIB_COMPONENT='platform',
)

# Shim library for boost to depend on
env.Library(
    target='boost_assert_shim',
    source=[
        'util/boost_assert_shim.cpp'
    ],
    # NOTE: This library *must not* depend on any mongodb code
    LIBDEPS=[],
)

js_engine_ver = get_option("js-engine") if get_option("server-js") == "on" else "none"

# On windows, we need to escape the backslashes in the command-line
# so that windows paths look okay.
cmd_line = " ".join(sys.argv).encode('unicode_escape')
if env.TargetOSIs('windows'):
    cmd_line = cmd_line.replace(b'\\', b'\\')

module_list = ',\n'.join(['"{0}"_sd'.format(x) for x in env['MONGO_MODULES']])

# This generates a numeric representation of the version string so that
# you can easily compare versions of MongoDB without having to parse
# the version string.
#
# The rules for this are
# {major}{minor}{release}{pre/rc/final}
# If the version is pre-release and not an rc, the final number is 0
# If the version is an RC, the final number of 1 + rc number
# If the version is pre-release between RC's, the final number is 1 + rc number
# If the version is a final release, the final number is 99
#
# Examples:
# 3.1.1-123     = 3010100
# 3.1.1-rc2     = 3010103
# 3.1.1-rc2-123 = 3010103
# 3.1.1         = 3010199
#
version_parts = [ x for x in re.match(r'^(\d+)\.(\d+)\.(\d+)-?((?:(rc)(\d+))?.*)?',
    env['MONGO_VERSION']).groups() ]
version_extra = version_parts[3] if version_parts[3] else ""
if version_parts[4] == 'rc':
    version_parts[3] = int(version_parts[5]) + -50
elif version_parts[3]:
    version_parts[2] = int(version_parts[2]) + 1
    version_parts[3] = -100
else:
    version_parts[3] = 0
version_parts = [ int(x) for x in version_parts[:4]]

# Render the MONGO_BUILDINFO_ENVIRONMENT_DATA dict into an initializer for a
# `std::vector<VersionInfoInterface::BuildInfoField>`.
def fmtBuildInfo(data):
    def fmtBool(val):
        return "true" if val else "false"
    def fmtStr(val):
        return 'R"({0})"_sd'.format(val.replace("\\", r"\\"))
    def fmtObj(obj):
        return '{{{}, {}, {}, {}}}'.format(fmtStr(obj['key']),
                                           fmtStr(env.subst(obj['value'])),
                                           fmtBool(obj['inBuildInfo']),
                                           fmtBool(obj['inVersion']))
    return ',\n'.join([fmtObj(obj) for _,obj in data.items()])

buildInfoInitializer = fmtBuildInfo(env['MONGO_BUILDINFO_ENVIRONMENT_DATA'])

generatedVersionFile = env.Substfile(
    'util/version_constants.h.in',
    SUBST_DICT=[
        ('@mongo_version@', env['MONGO_VERSION']),
        ('@mongo_version_major@', version_parts[0]),
        ('@mongo_version_minor@', version_parts[1]),
        ('@mongo_version_patch@', version_parts[2]),
        ('@mongo_version_extra@', version_parts[3]),
        ('@mongo_version_extra_str@', version_extra),
        ('@mongo_git_hash@', env['MONGO_GIT_HASH']),
        ('@buildinfo_js_engine@', js_engine_ver),
        ('@buildinfo_allocator@', env['MONGO_ALLOCATOR']),
        ('@buildinfo_modules@', module_list),
        ('@buildinfo_environment_data@', buildInfoInitializer),
    ])
env.Alias('generated-sources', generatedVersionFile)

if env.TargetOSIs('windows'):
    enterpriseEnv = env.Clone().InjectModule("enterprise")
    generatedResourceConstantFile = enterpriseEnv.Substfile(
        'util/resource_constants.h.in',
        SUBST_DICT=[
            ('@mongo_version@', env['MONGO_VERSION']),
            ('@mongo_version_major@', version_parts[0]),
            ('@mongo_version_minor@', version_parts[1]),
            ('@mongo_version_patch@', version_parts[2]),
            ('@mongo_git_hash@', env['MONGO_GIT_HASH']),
        ])
    env.Alias('generated-sources', generatedResourceConstantFile)

config_header_substs = (
    ('@mongo_config_altivec_vec_vbpermq_output_index@', 'MONGO_CONFIG_ALTIVEC_VEC_VBPERMQ_OUTPUT_INDEX'),
    ('@mongo_config_debug_build@', 'MONGO_CONFIG_DEBUG_BUILD'),
    ('@mongo_config_have_execinfo_backtrace@', 'MONGO_CONFIG_HAVE_EXECINFO_BACKTRACE'),
    ('@mongo_config_have_explicit_bzero@', 'MONGO_CONFIG_HAVE_EXPLICIT_BZERO'),
    ('@mongo_config_have_fips_mode_set@', 'MONGO_CONFIG_HAVE_FIPS_MODE_SET'),
    ('@mongo_config_have_header_unistd_h@', 'MONGO_CONFIG_HAVE_HEADER_UNISTD_H'),
    ('@mongo_config_have_memset_s@', 'MONGO_CONFIG_HAVE_MEMSET_S'),
    ('@mongo_config_have_posix_monotonic_clock@', 'MONGO_CONFIG_HAVE_POSIX_MONOTONIC_CLOCK'),
    ('@mongo_config_have_pthread_setname_np@', 'MONGO_CONFIG_HAVE_PTHREAD_SETNAME_NP'),
    ('@mongo_config_have_ssl_ec_key_new@', 'MONGO_CONFIG_HAVE_SSL_EC_KEY_NEW'),
    ('@mongo_config_have_ssl_set_ecdh_auto@', 'MONGO_CONFIG_HAVE_SSL_SET_ECDH_AUTO'),
    ('@mongo_config_have_std_enable_if_t@', 'MONGO_CONFIG_HAVE_STD_ENABLE_IF_T'),
    ('@mongo_config_have_strnlen@', 'MONGO_CONFIG_HAVE_STRNLEN'),
    ('@mongo_config_max_extended_alignment@', 'MONGO_CONFIG_MAX_EXTENDED_ALIGNMENT'),
    ('@mongo_config_optimized_build@', 'MONGO_CONFIG_OPTIMIZED_BUILD'),
    ('@mongo_config_ssl_has_asn1_any_definitions@', 'MONGO_CONFIG_HAVE_ASN1_ANY_DEFINITIONS'),
    ('@mongo_config_ssl_provider@', 'MONGO_CONFIG_SSL_PROVIDER'),
    ('@mongo_config_ssl@', 'MONGO_CONFIG_SSL'),
    ('@mongo_config_usdt_enabled@', 'MONGO_CONFIG_USDT_ENABLED'),
    ('@mongo_config_usdt_provider@', 'MONGO_CONFIG_USDT_PROVIDER'),
    ('@mongo_config_use_libunwind@', 'MONGO_CONFIG_USE_LIBUNWIND'),
    ('@mongo_config_use_raw_latches@', 'MONGO_CONFIG_USE_RAW_LATCHES'),
    ('@mongo_config_wiredtiger_enabled@', 'MONGO_CONFIG_WIREDTIGER_ENABLED'),
)

def makeConfigHeaderDefine(self, key):
    val = "// #undef {0}".format(key)
    if key in self['CONFIG_HEADER_DEFINES']:
        val = "#define {0} {1}".format(key, self['CONFIG_HEADER_DEFINES'][key])
    return val
env.AddMethod(makeConfigHeaderDefine)

generateConfigHeaderFile = env.Substfile(
    'config.h.in',
    SUBST_DICT=[(k, env.makeConfigHeaderDefine(v)) for (k, v) in config_header_substs]
)
env.Alias('generated-sources', generateConfigHeaderFile)

env.Library(
    target="mongod_options_init",
    source=[
        "db/mongod_options_init.cpp",
    ],
    LIBDEPS=[
        'base',
    ],
    LIBDEPS_PRIVATE=[
        'db/mongod_options',
        '$BUILD_DIR/mongo/util/net/ssl_options_server' if get_option('ssl') == 'on' else '',
    ]
)

if env.TargetOSIs('windows'):
    generatedDbManifest = env.Substfile(
        'db/mongod.manifest.in',
        SUBST_DICT=[
            ('@mongo_version_major@', version_parts[0]),
            ('@mongo_version_minor@', version_parts[1]),
            ('@mongo_version_patch@', version_parts[2]),
            ('@mongo_version_extra@', version_parts[3]),
            ('@mongo_version_extra_str@', version_extra),
        ])

    env.Alias('generated-sources', generatedDbManifest)
    env.Depends("db/mongod.res", generatedDbManifest)

mongod = env.Program(
    target="mongod",
    source=[
        'db/mongod.cpp'
    ] + env.WindowsResourceFile("db/mongod.rc"),
    LIBDEPS=[
        # NOTE: Do not add new libdeps (public or private) here unless
        # required by the linker to satisfy symbol dependencies from
        # the files listed above in `sources`. If you need to add a
        # library to inject a static or mongo initializer to mongod,
        # please add that library as a private libdep of
        # mongod_initializers.
        'base',
        'mongod_main',
    ],
    AIB_COMPONENT="mongod",
    AIB_COMPONENTS_EXTRA=[
        "core",
        "default",
        "dist",
        "dist-test",
        "servers",
        "integration-tests",
    ],
)

env.Library(
    target="mongod_initializers",
    source=[
        # NOTE: If you add an additional source file here, please delete
        # the file db/mongod_initializers.cpp.
        "db/mongod_initializers.cpp",
    ],
    LIBDEPS_PRIVATE=[
        # NOTE: If you need to add a static or mongo initializer to mongod startup,
        # please add that library here, as a private library dependency.
        '$BUILD_DIR/third_party/shim_snappy',
        'base',
        'db/auth/auth_op_observer',
        'db/auth/authmongod',
        'db/bson/dotted_path_support',
        'db/catalog/catalog_impl',
        'db/catalog/collection_options',
        'db/catalog/document_validation',
        'db/catalog/health_log',
        'db/catalog/index_key_validate',
        'db/client_metadata_propagation_egress_hook',
        'db/collection_index_usage_tracker',
        'db/commands/mongod_fcv',
        'db/commands/mongod',
        'db/commands/server_status_servers',
        'db/common',
        'db/concurrency/flow_control_ticketholder',
        'db/concurrency/lock_manager',
        'db/concurrency/write_conflict_exception',
        'db/curop_metrics',
        'db/curop',
        'db/db_raii',
        'db/dbdirectclient',
        'db/dbhelpers',
        'db/exec/working_set',
        'db/free_mon/free_mon_mongod',
        'db/ftdc/ftdc_mongod',
        'db/fts/ftsmongod',
        'db/index_builds_coordinator_mongod',
        'db/index/index_access_method',
        'db/index/index_access_methods',
        'db/index/index_descriptor',
        'db/initialize_server_security_state',
        'db/initialize_snmp',
        'db/introspect',
        'db/keys_collection_client_direct',
        'db/kill_sessions_local',
        'db/logical_session_cache_impl',
        'db/logical_time_metadata_hook',
        'db/matcher/expressions_mongod_only',
        'db/mirror_maestro',
        'db/mongod_options',
        'db/ops/write_ops_parsers',
        'db/periodic_runner_job_abort_expired_transactions',
        'db/pipeline/aggregation',
        'db/pipeline/process_interface/mongod_process_interface_factory',
        'db/query_exec',
        'db/read_concern_d_impl',
        'db/read_write_concern_defaults',
        'db/repair_database_and_check_version',
        'db/repl/bgsync',
        'db/repl/oplog_application',
        'db/repl/oplog_buffer_blocking_queue',
        'db/repl/oplog_buffer_collection',
        'db/repl/oplog_buffer_proxy',
        'db/repl/repl_coordinator_impl',
        'db/repl/repl_set_commands',
        'db/repl/repl_settings',
        'db/repl/replica_set_aware_service',
        'db/repl/rs_rollback',
        'db/repl/serveronly_repl',
        'db/repl/storage_interface_impl',
        'db/repl/topology_coordinator',
        'db/rw_concern_d',
        'db/s/balancer',
        'db/s/sessions_collection_config_server',
        'db/s/sharding_commands_d',
        'db/s/sharding_runtime_d',
        'db/service_context_d',
        'db/service_liaison_mongod',
        'db/sessions_collection_rs',
        'db/sessions_collection_standalone',
        'db/startup_warnings_mongod',
        'db/stats/counters',
        'db/stats/serveronly_stats',
        'db/stats/top',
        'db/storage/backup_cursor_hooks',
        'db/storage/biggie/storage_biggie',
        'db/storage/devnull/storage_devnull',
        'db/storage/ephemeral_for_test/storage_ephemeral_for_test',
        'db/storage/flow_control_parameters',
        'db/storage/flow_control',
        'db/storage/storage_control',
        'db/storage/storage_engine_lock_file',
        'db/storage/storage_engine_metadata',
        'db/storage/storage_init_d',
        'db/storage/storage_options',
        'db/storage/wiredtiger/storage_wiredtiger' if wiredtiger else [],
        'db/system_index',
        'db/traffic_recorder',
        'db/ttl_collection_cache',
        'db/ttl_d',
        'db/update_index_data',
        'db/update/update_driver',
        'db/views/views_mongod',
        'db/windows_options' if env.TargetOSIs('windows') else [],
        'executor/network_interface_factory',
        'mongod_options_init',
        'rpc/rpc',
        's/commands/shared_cluster_commands',
        's/sessions_collection_sharded',
        'scripting/scripting_server',
        'transport/message_compressor_options_server',
        'transport/service_entry_point',
        'transport/transport_layer_manager',
        'util/clock_sources',
        'util/elapsed_tracker',
        'util/fail_point',
        'util/latch_analyzer' if get_option('use-diagnostic-latches') == 'on' else [],
        'util/net/network',
        'util/ntservice',
        'util/options_parser/options_parser_init',
        'util/periodic_runner_factory',
        'util/testing_options',
        'util/version_impl',
        'watchdog/watchdog_mongod',
    ],
    LIBDEPS=[
        # NOTE: This list must remain empty. Please only add to LIBDEPS_PRIVATE
    ],
)

env.Library(
    target="mongod_main",
    source=[
        'db/mongod_main.cpp',
        'db/logical_session_cache_factory_mongod.cpp',
        'db/read_write_concern_defaults_cache_lookup_mongod.cpp',
    ],
    LIBDEPS_PRIVATE=[
        # NOTE: Do not add new libdeps (public or private) here unless
        # required by the linker to satisfy symbol dependencies from
        # the files listed above in `sources`. If you need to add a
        # library to inject a static or mongo initializer to mongod,
        # please add that library as a private libdep of
        # mongod_initializers.
        'base',
        'client/clientdriver_minimal',
        'db/auth/auth_op_observer',
        'db/catalog/catalog_impl',
        'db/catalog/collection',
        'db/catalog/health_log',
        'db/commands/mongod',
        'db/concurrency/flow_control_ticketholder',
        'db/concurrency/lock_manager',
        'db/free_mon/free_mon_mongod',
        'db/ftdc/ftdc_mongod',
        'db/index/index_access_method_factory',
        'db/index/index_access_methods',
        'db/index_builds_coordinator_mongod',
        'db/initialize_server_security_state',
        'db/initialize_snmp',
        'db/keys_collection_client_direct',
        'db/kill_sessions',
        'db/kill_sessions_local',
        'db/log_process_details',
        'db/mirror_maestro',
        'db/mongod_options',
        'db/op_observer',
        'db/periodic_runner_job_abort_expired_transactions',
        'db/pipeline/process_interface/mongod_process_interface_factory',
        'db/repair_database_and_check_version',
        'db/repl/drop_pending_collection_reaper',
        'db/repl/repl_coordinator_impl',
        'db/repl/replication_recovery',
        'db/repl/serveronly_repl',
        'db/repl/storage_interface_impl',
        'db/repl/topology_coordinator',
        'db/repl/wait_for_majority_service',
        'db/s/sessions_collection_config_server',
        'db/s/sharding_runtime_d',
        'db/serverinit',
        'db/service_context_d',
        'db/service_liaison_mongod',
        'db/sessions_collection_rs',
        'db/sessions_collection_standalone',
        'db/startup_warnings_mongod',
        'db/storage/backup_cursor_hooks',
        'db/storage/flow_control',
        'db/storage/flow_control_parameters',
        'db/storage/storage_control',
        'db/storage/storage_engine_common',
        'db/system_index',
        'db/ttl_d',
        'db/vector_clock',
        'mongod_initializers',
        's/grid',
        's/sessions_collection_sharded',
        's/sessions_collection_sharded',
        'scripting/scripting',
        'transport/service_entry_point',
        'transport/transport_layer_manager',
        'util/cmdline_utils/cmdline_utils',
        'util/concurrency/thread_pool',
        'util/latch_analyzer' if get_option('use-diagnostic-latches') == 'on' else [],
        'util/net/ssl_manager',
        'util/signal_handlers',
        'watchdog/watchdog_mongod',
    ],
    LIBDEPS=[
        # NOTE: This list must remain empty. Please only add to LIBDEPS_PRIVATE
    ],
)

if env.TargetOSIs('windows'):
    generatedServerManifest = env.Substfile(
        's/mongos.manifest.in',
        SUBST_DICT=[
            ('@mongo_version_major@', version_parts[0]),
            ('@mongo_version_minor@', version_parts[1]),
            ('@mongo_version_patch@', version_parts[2]),
            ('@mongo_version_extra@', version_parts[3]),
            ('@mongo_version_extra_str@', version_extra),
        ])

    env.Alias('generated-sources', generatedServerManifest)
    env.Depends("s/mongos.res", generatedServerManifest)


mongotrafficreader = env.Program(
    target="mongotrafficreader",
    source=[
        "db/traffic_reader_main.cpp"
    ],
    LIBDEPS=[
        'base',
        'db/traffic_reader',
        'rpc/protocol',
        'util/signal_handlers'
    ],
)

# mongos
mongos = env.Program(
    target='mongos',
    source=[
        's/mongos.cpp',
    ] + env.WindowsResourceFile("s/mongos.rc"),
    LIBDEPS=[
        # NOTE: Do not add new libdeps (public or private) here unless
        # required by the linker to satisfy symbol dependencies from
        # the files listed above in `sources`. If you need to add a
        # library to inject a static or mongo initializer to mongos,
        # please add that library as a private libdep of
        # mongos_initializers.
        'base',
        'mongos_main',
    ],
    AIB_COMPONENT="mongos",
    AIB_COMPONENTS_EXTRA=[
        "core",
        "dist",
        "dist-test",
        "servers",
        "integration-tests",
    ],
)

env.Library(
    target='mongos_initializers',
    source=[
        's/cluster_cursor_stats.cpp',
        's/router_transactions_server_status.cpp',
        's/s_sharding_server_status.cpp',
    ],
    LIBDEPS_PRIVATE=[
        # NOTE: If you need to add a static or mongo initializer to mongos startup,
        # please add that library here, as a private library dependency.
        'db/audit',
        'db/auth/authmongos',
        'db/commands/server_status',
        'db/commands/server_status_core',
        'db/commands/server_status_servers',
        'db/curop',
        'db/dbdirectclient',
        'db/ftdc/ftdc_mongos',
        'db/initialize_server_security_state',
        'db/logical_session_cache',
        'db/logical_session_cache_impl',
        'db/logical_time_metadata_hook',
        'db/pipeline/process_interface/mongos_process_interface_factory',
        'db/read_write_concern_defaults',
        'db/server_options',
        'db/server_options_base',
        'db/service_liaison_mongos',
        'db/session_catalog',
        'db/startup_warnings_common',
        'db/stats/counters',
        'db/windows_options' if env.TargetOSIs('windows') else [],
        's/commands/cluster_commands',
        's/commands/shared_cluster_commands',
        's/committed_optime_metadata_hook',
        's/coreshard',
        's/is_mongos',
        's/mongos_topology_coordinator',
        's/mongos_server_parameters',
        's/query/cluster_cursor_cleanup_job',
        's/sessions_collection_sharded',
        's/sharding_egress_metadata_hook_for_mongos',
        's/sharding_initialization',
        's/sharding_router_api',
        'transport/message_compressor_options_server',
        'transport/service_entry_point',
        'transport/transport_layer_manager',
        'util/clock_sources',
        'util/fail_point',
        'util/latch_analyzer' if get_option('use-diagnostic-latches') == 'on' else [],
        'util/net/ssl_options_server' if get_option('ssl') == 'on' else '',
        'util/ntservice',
        'util/options_parser/options_parser',
        'util/options_parser/options_parser_init',
        'util/testing_options',
        'util/version_impl',
    ],
    LIBDEPS=[
        # NOTE: This list must remain empty. Please only add to LIBDEPS_PRIVATE
    ],
)

env.Library(
    target='mongos_main',
    source=[
        'db/read_write_concern_defaults_cache_lookup_mongos.cpp',
        's/mongos_main.cpp',
        's/mongos_options.cpp',
        's/mongos_options_init.cpp',
        env.Idlc('s/mongos_options.idl')[0],
        's/service_entry_point_mongos.cpp',
        's/sharding_uptime_reporter.cpp',
        's/version_mongos.cpp',
    ],
    LIBDEPS_PRIVATE=[
        # NOTE: Do not add new libdeps (public or private) here unless
        # required by the linker to satisfy symbol dependencies from
        # the files listed above in `sources`. If you need to add a
        # library to inject a static or mongo initializer to mongos,
        # please add that library as a private libdep of
        # mongos_initializers.
        'db/audit',
        'db/auth/authmongos',
        'db/ftdc/ftdc_mongos',
        'db/initialize_server_security_state',
        'db/log_process_details',
        'db/read_write_concern_defaults',
        'db/serverinit',
        'db/service_liaison_mongos',
        'db/session_catalog',
        'db/startup_warnings_common',
        'mongos_initializers',
        's/client/sharding_client',
        's/cluster_last_error_info',
        's/commands/cluster_commands',
        's/committed_optime_metadata_hook',
        's/common_s',
        's/mongos_topology_coordinator',
        's/query/cluster_cursor_cleanup_job',
        's/sessions_collection_sharded',
        's/sharding_egress_metadata_hook_for_mongos',
        's/sharding_initialization',
        's/sharding_router_api',
        'transport/service_entry_point',
        'transport/transport_layer_manager',
        'util/latch_analyzer' if get_option('use-diagnostic-latches') == 'on' else [],
        'util/net/ssl_manager',
        'util/periodic_runner_factory',
        'util/signal_handlers',
    ],
    LIBDEPS=[
        # NOTE: This list must remain empty. Please only add to LIBDEPS_PRIVATE
    ],
)


# --- shell ---

if not has_option('noshell') and usemozjs:
    shellEnv = env.Clone()
    if env.TargetOSIs('windows'):
        shellEnv.Append(LIBS=["winmm.lib"])

        generatedMongoManifest = shellEnv.Substfile(
                'shell/mongo.manifest.in',
                SUBST_DICT=[
                    ('@mongo_version_major@', version_parts[0]),
                    ('@mongo_version_minor@', version_parts[1]),
                    ('@mongo_version_patch@', version_parts[2]),
                    ('@mongo_version_extra@', version_parts[3]),
                    ('@mongo_version_extra_str@', version_extra),
                ])
        shellEnv.Alias('generated-sources', generatedMongoManifest)
        shellEnv.Depends("shell/mongo.res", generatedMongoManifest)

    mongo_shell = shellEnv.Program(
        target="mongo",
        source=[
            "shell/mongo.cpp",
        ] + env.WindowsResourceFile("shell/mongo.rc"),
        LIBDEPS=[
            # NOTE: Do not add new libdeps (public or private) here unless
            # required by the linker to satisfy symbol dependencies from
            # the files listed above in `sources`. If you need to add a
            # library to inject a static or mongo initializer to mongo,
            # please add that library as a private libdep of
            # mongo_initializers.
            'base',
            'mongo_main',
        ],
        AIB_COMPONENT="mongo",
        AIB_COMPONENTS_EXTRA=[
            "core",
            "dist",
            "dist-test",
            "shell",
            "integration-tests",
        ],
    )

    env.Library(
        target="mongo_initializers",
        source=[
            "shell/mongodbcr.cpp",
            "shell/shell_options_init.cpp",
        ],
        LIBDEPS_PRIVATE=[
            # NOTE: If you need to add a static or mongo initializer to mongo startup,
            # please add that library here, as a private library dependency.
            "$BUILD_DIR/third_party/shim_pcrecpp",
            "client/clientdriver_network",
            "client/connection_string",
            "db/catalog/index_key_validate",
            "db/logical_session_id_helpers",
            "db/mongohasher",
            "db/query/command_request_response",
            "db/query/query_request",
            "db/server_options_core",
            "db/storage/duplicate_key_error_info",
            "db/traffic_reader",
            "db/views/resolved_view",
            "executor/network_interface_factory",
            "executor/network_interface_thread_pool",
            "executor/thread_pool_task_executor",
            "rpc/protocol",
            "scripting/scripting",
            "shell/benchrun",
            "shell/encrypted_dbclient" if get_option('ssl') == 'on' else '',
            "shell/kms_shell" if get_option('ssl') == 'on' else '',
            "shell/mongojs",
            "shell/shell_options_register",
            "shell/shell_utils",
            "transport/message_compressor",
            "transport/message_compressor_options_client",
            "transport/transport_layer_manager",
            "util/net/network",
            "util/net/ssl_options_client" if get_option('ssl') == 'on' else '',
            "util/options_parser/options_parser_init",
            "util/password",
            "util/processinfo",
            "util/signal_handlers",
            "util/version_impl",
        ],
        LIBDEPS=[
            # NOTE: This list must remain empty. Please only add to LIBDEPS_PRIVATE
        ],

    )

    env.Library(
        target="mongo_main",
        source=[
            "shell/mongo_main.cpp",
        ],
        LIBDEPS_PRIVATE=[
            # NOTE: Do not add new libdeps (public or private) here unless
            # required by the linker to satisfy symbol dependencies from
            # the files listed above in `sources`. If you need to add a
            # library to inject a static or mongo initializer to mongo,
            # please add that library as a private libdep of
            # mongo_initializers.
            "$BUILD_DIR/third_party/shim_pcrecpp",
            "mongo_initializers",
            "shell/linenoise",
            "shell/shell_utils",
            "transport/transport_layer",
            "util/net/ssl_manager",
            "util/signal_handlers",
        ],
        LIBDEPS=[
            # NOTE: This list must remain empty. Please only add to LIBDEPS_PRIVATE
        ],
    )

else:
    shellEnv = None

#  ----  INSTALL -------

# Stage the top-level mongodb banners
distsrc = env.Dir('#distsrc')


env.AutoInstall(
    target='$PREFIX',
    source=[
        distsrc.File('README'),
        # TODO: we need figure out what to do when we use a different
        # THIRD-PARTY-NOTICES for example, with Embedded
        distsrc.File('THIRD-PARTY-NOTICES'),
        distsrc.File('MPL-2'),
    ],
    AIB_COMPONENT='common',
    AIB_ROLE='base',
)

# If no module has introduced a file named LICENSE-Enterprise.txt then this
# is a Community build, so inject the AGPL and the Community license
enterprise_license = [banner for banner in env["MODULE_BANNERS"] if banner.name ==  "LICENSE-Enterprise.txt"]
if not enterprise_license:
    env.Append(MODULE_BANNERS = [distsrc.File('LICENSE-Community.txt')])

# All module banners get staged to the top level of the tarfile, so we
# need to fail if we are going to have a name collision.
module_banner_filenames = set([f.name for f in env['MODULE_BANNERS']])
if not len(module_banner_filenames) == len(env['MODULE_BANNERS']):
    # TODO: Be nice and identify conflicts in error.
    env.FatalError("ERROR: Filename conflicts exist in module banners.")

env.AutoInstall(
    target='$PREFIX',
    source=env.get('MODULE_BANNERS', []),
    AIB_COMPONENT='common',
    AIB_COMPONENTS_EXTRA=['dist', 'dist-test'],
    AIB_ROLE='base',
)

# Set the download url to the right place
compass_type = 'compass-community'
if 'enterprise' in env['MONGO_MODULES']:
    compass_type = 'compass'

compass_script = "install_compass.in"
if env.TargetOSIs('windows'):
    compass_script = "Install-Compass.ps1.in"

compass_python_interpreter = '/usr/bin/env python2'
if env.TargetOSIs('darwin'):
    compass_python_interpreter = '/usr/bin/env python'

compass_installer = env.Substfile(
  target="$BUILD_DIR/mongo/installer/compass/" + compass_script[:-3],
  source='installer/compass/' + compass_script,
  SUBST_DICT=[
    ('@compass_type@', compass_type),
    ('@python_interpreter@', compass_python_interpreter),
  ],
)

if env.TargetOSIs('posix'):
    env.AddPostAction(compass_installer, Chmod('$TARGET', 0o755))

env.AutoInstall(
    target='$PREFIX_BINDIR',
    source=[
        compass_installer,
    ],
    AIB_COMPONENT='dist',
    AIB_ROLE='runtime',
)