# -*- mode: python -*-

Import("env")
Import("has_option")
Import("wiredtiger")
Import("inmemory")

env = env.Clone()

# Ideally 's2' would be scoped narrowly but it is spammed in all over the place by
# db/geo unfortunately.
env.InjectThirdPartyIncludePaths(libraries=[
    's2',
])

if has_option('audit'):
    env.SConscript(dirs='audit', exports='env')

env.SConscript(
    dirs=[
        'auth',
        'backup',
        'bson',
        'catalog',
        'commands',
        'concurrency',
        'encryption',
        'exec',
        'free_mon',
        'fts',
        'ftdc',
        'geo',
        'index',
        'ldap',
        'matcher',
        'ops',
        'pipeline',
        'query',
        'repl',
        's',
        'sorter',
        'stats',
        'storage',
        'update',
        'views',
    ],
    exports=[
        'env',
    ],
)

#
# The db/'common' lib has the abstractions that are shared by components of the
# server. Ideally, many of the object in 'coredb' should be moved here when their dependencies
# get resolved.
#

env.Library(
    target= 'common',
    source= [
        'field_ref.cpp',
        'field_ref_set.cpp',
        'field_parser.cpp',
        'keypattern.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/index_names',
        '$BUILD_DIR/mongo/db/write_concern_options',
    ]
)

env.Library(
    target='initialize_snmp',
    source= [
        'initialize_snmp.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
)

env.CppUnitTest(
    target= 'field_ref_test',
    source= 'field_ref_test.cpp',
    LIBDEPS=[
        'common',
    ],
)

env.CppUnitTest(
    target= 'field_ref_set_test',
    source = 'field_ref_set_test.cpp',
    LIBDEPS=[
        'common',
    ],
)

env.CppUnitTest(
    target= 'field_parser_test',
    source= 'field_parser_test.cpp',
    LIBDEPS=[
        'common',
    ],
)

env.CppUnitTest(
    target= 'hasher_test',
    source= [
        'hasher_test.cpp',
    ],
    LIBDEPS=[
        'common',
        '$BUILD_DIR/mongo/db/mongohasher',
    ],
)

env.CppUnitTest(
    target= 'keypattern_test',
    source= 'keypattern_test.cpp',
    LIBDEPS=[
        'common'
    ],
)

env.CppUnitTest(
    target= 'op_observer_registry_test',
    source= 'op_observer_registry_test.cpp',
    LIBDEPS=[
        'common',
        'op_observer',
        'service_context',
    ],
)

env.CppUnitTest(
    target='op_observer_impl_test',
    source='op_observer_impl_test.cpp',
    LIBDEPS=[
        'auth/authmocks',
        'common',
        'op_observer_impl',
        'repl/replmocks',
        'repl/storage_interface_impl',
        'service_context_d_test_fixture',
    ],
)

env.Library(
    target="dbmessage",
    source=[
        "dbmessage.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/server_options_core',
        '$BUILD_DIR/mongo/transport/transport_layer_common',
        '$BUILD_DIR/mongo/util/net/network',
    ]
)

env.CppUnitTest(
    target="dbmessage_test",
    source=[
        "dbmessage_test.cpp"
    ],
    LIBDEPS=[
        "dbmessage",
    ],
)
env.CppUnitTest('record_id_test', 'record_id_test.cpp', LIBDEPS=[])

env.Library(
    target='startup_warnings_common',
    source=[
        'startup_warnings_common.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/util/net/ssl_manager',
    ]
)

env.Library(
    target='startup_warnings_mongod',
    source=[
        'startup_warnings_mongod.cpp',
    ],
    LIBDEPS=[
        'startup_warnings_common',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        '$BUILD_DIR/mongo/util/processinfo',
    ]
)

env.CppUnitTest(
    target='startup_warnings_mongod_test',
    source=[
        'startup_warnings_mongod_test.cpp',
    ],
    LIBDEPS=[
        'startup_warnings_mongod',
    ],
)

env.Library(
    target='curop',
    source=[
        'curop.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/bson/mutable/mutable_bson',
        '$BUILD_DIR/mongo/db/commands',
        '$BUILD_DIR/mongo/db/concurrency/lock_manager',
        '$BUILD_DIR/mongo/db/service_context',
        '$BUILD_DIR/mongo/db/query/command_request_response',
        '$BUILD_DIR/mongo/rpc/client_metadata',
        '$BUILD_DIR/mongo/util/fail_point',
        '$BUILD_DIR/mongo/util/net/network',
        '$BUILD_DIR/mongo/util/progress_meter',
        'server_options',
    ],
)

env.CppUnitTest(
    target='curop_test',
    source=[
        'curop_test.cpp',
    ],
    LIBDEPS=[
        'curop',
    ],
)

env.Library(
    target='curop_failpoint_helpers',
    source=[
        'curop_failpoint_helpers.cpp',
    ],
    LIBDEPS=[
        'curop',
        '$BUILD_DIR/mongo/util/fail_point',
    ],
)

env.CppUnitTest(
    target='operation_context_test',
    source=[
        'operation_context_test.cpp',
    ],
    LIBDEPS=[
        'logical_session_id',
        'logical_session_id_helpers',
        'service_context',
        '$BUILD_DIR/mongo/db/auth/authmocks',
        '$BUILD_DIR/mongo/unittest/concurrency',
        '$BUILD_DIR/mongo/util/clock_source_mock',
    ],
)

env.CppUnitTest(
    target='operation_id_test',
    source=[
        'operation_id_test.cpp',
    ],
    LIBDEPS=[
        'service_context',
    ],
)

env.Library(
    target='index_names',
    source=[
        "index_names.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ]
)

env.Library(
    target='mongohasher',
    source=[
        "hasher.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/util/md5',
    ]
)

# Range arithmetic library, used by both mongod and mongos
env.Library(
    target='range_arithmetic',
    source=[
        'range_arithmetic.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
)

env.CppUnitTest(
    target='range_arithmetic_test',
    source=[
        'range_arithmetic_test.cpp',
    ],
    LIBDEPS=[
        'range_arithmetic',
    ],
)

env.Library(
    target='namespace_string',
    source=[
        'namespace_string.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/repl/optime',
    ],
)

env.CppUnitTest(
    target='namespace_string_test',
    source=[
        'namespace_string_test.cpp',
    ],
    LIBDEPS=[
        'namespace_string',
    ],
)

env.Library(
    target="server_parameters",
    source=[
        "server_parameters.cpp",
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/base",
    ],
)

env.CppUnitTest(
    target="server_parameters_test",
    source=[
        "server_parameters_test.cpp",
    ],
    LIBDEPS=[
        "server_parameters",
        '$BUILD_DIR/mongo/db/service_context',
    ],
)

env.Library(
    target='update_index_data',
    source=[
        'update_index_data.cpp'
    ],
    LIBDEPS=[
        'common',
    ],
)

env.CppUnitTest(
    target='update_index_data_test',
    source=[
        'update_index_data_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        'common',
        'update_index_data',
    ],
)

env.Library(
    target='collection_index_usage_tracker',
    source=[
        'collection_index_usage_tracker.cpp'
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
)

env.CppUnitTest(
    target='collection_index_usage_tracker_test',
    source=[
        'collection_index_usage_tracker_test.cpp',
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/util/clock_source_mock",
        'collection_index_usage_tracker',
    ],
)

# This library exists because some libraries, such as our networking library, need access to server
# options, but not to the helpers to set them from the command line.  libserver_options_core.a just
# has the structure for storing the server options, while libserver_options.a has the code to set
# them via the command line.
env.Library(
    target="server_options_core",
    source=[
        "server_options.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
)

env.Library(
    target="server_options",
    source=[
        "server_options_helpers.cpp",
        "redaction_parameter.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/util/cmdline_utils/cmdline_utils',
        '$BUILD_DIR/mongo/util/fail_point',
        '$BUILD_DIR/mongo/util/options_parser/options_parser',
        'ldap_options',
        'server_options_core',
        'server_parameters',
    ],
)

env.Library(
    target='ldap_options',
    source=[
        'ldap_options.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/server_parameters',
        '$BUILD_DIR/mongo/util/net/network',
        '$BUILD_DIR/mongo/util/options_parser/options_parser',
    ],
)

env.Clone().InjectModule("enterprise").Library(
    target="server_options_servers",
    source=[
        "server_options_server_helpers.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/transport/message_compressor',
        '$BUILD_DIR/mongo/util/net/network',
        # The dependency on net/ssl_manager is a temporary crutch that should go away once the
        # networking library has separate options
        '$BUILD_DIR/mongo/util/net/ssl_manager',
        'server_options',
    ],
)

env.CppUnitTest(
    target='server_options_test',
    source=[
        'server_options_test.cpp',
    ],
    LIBDEPS=[
        'server_options_servers',
    ],
)

# This library is linked into mongos and mongod only, not into the shell or any tools.
env.Library(
    target="mongodandmongos",
    source=[
        "initialize_server_global_state.cpp",
        "server_options_init.cpp",
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/client/clientdriver_network",
        "$BUILD_DIR/mongo/db/auth/auth",
        "$BUILD_DIR/mongo/rpc/command_reply",
        "$BUILD_DIR/mongo/rpc/command_request",
        "$BUILD_DIR/mongo/rpc/metadata",
        "$BUILD_DIR/mongo/util/processinfo",
        "$BUILD_DIR/mongo/util/signal_handlers",
        "auth/authorization_manager_global",
    ],
    LIBDEPS_PRIVATE=[
        "$BUILD_DIR/mongo/db/auth/internal_user_auth",
        "$BUILD_DIR/mongo/db/auth/security_key",
    ],
)

env.Library(
    target="global_settings",
    source=[
        "global_settings.cpp",
    ],
    LIBDEPS=[
        'encryption/encryption_options',
        'repl/repl_settings',
    ],
)

# mongod options
env.Library(
    target="mongod_options",
    source=[
        "mongod_options.cpp",
        "ratelimit_parameter.cpp",
        "mongod_ldap_parameters.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/storage/mmap_v1/mmap_v1_options',
        'repl/repl_settings',
        'repl/replica_set_messages',
        'server_options_servers',
        'storage/storage_options',
    ],
    LIBDEPS_PRIVATE=[
        'global_settings',
    ]
)

env.Library(
    target="write_concern_options",
    source=[
        "write_concern_options.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/bson/util/bson_extract',
    ],
)

env.CppUnitTest(
    target= 'write_concern_options_test',
    source= 'write_concern_options_test.cpp',
    LIBDEPS=[
        'write_concern_options',
    ],
)

env.Library(
    target='service_context',
    source=[
        'client.cpp',
        'multi_key_path_tracker.cpp',
        'operation_context.cpp',
        'operation_context_group.cpp',
        'operation_id.cpp',
        'service_context.cpp',
        'server_recovery.cpp',
        'unclean_shutdown.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/logical_session_id',
        '$BUILD_DIR/mongo/db/storage/write_unit_of_work',
        '$BUILD_DIR/mongo/transport/transport_layer_common',
        '$BUILD_DIR/mongo/util/clock_sources',
        '$BUILD_DIR/mongo/util/concurrency/spin_lock',
        '$BUILD_DIR/mongo/util/fail_point',
        '$BUILD_DIR/mongo/util/net/network',
        '$BUILD_DIR/mongo/util/periodic_runner',
    ],
)

env.Library(
    target='lasterror',
    source=[
        "lasterror.cpp",
    ],
    LIBDEPS=[
        'service_context',
    ],
)

env.Clone().InjectModule("enterprise").Library(
    target="audit",
    source=[
        "audit.cpp",
    ],
    LIBDEPS=[
    ],
)

env.Library(
    target="commands",
    source=[
        'commands.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/bson/mutable/mutable_bson',
        '$BUILD_DIR/mongo/rpc/rpc',
        '$BUILD_DIR/mongo/rpc/command_status',
        'audit',
        'command_generic_argument',
        'commands/server_status_core',
        'commands/test_commands_enabled',
        'namespace_string',
    ],
)

env.Library(
    target='command_generic_argument',
    source=[
        'command_generic_argument.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
)

env.Library(
    target='command_can_run_here',
    source=[
        'command_can_run_here.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/client/read_preference',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        'commands/test_commands_enabled',
        'service_context',
    ],
)


env.CppUnitTest(
    target="commands_test",
    source=[
        "commands_test.cpp",
        env.Idlc('commands_test_example.idl')[0],
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/idl/idl_parser',
        "commands",
        "auth/authmocks",
        "repl/replmocks",
        "service_context_test_fixture",
    ],
)

# TODO: This library should probably be folded into catalog_raii,
# with which it is currently circular.
env.Library(
    target='db_raii',
    source=[
        'db_raii.cpp',
    ],
    LIBDEPS=[
        'catalog_raii',
        'curop',
        's/sharding_api_d',
        'stats/top',
    ],
)

env.Library(
    target='catalog_raii',
    source=[
        'catalog_raii.cpp',
        'retryable_writes_stats.cpp',
        'server_transactions_metrics.cpp',
        'session.cpp',
        'session_catalog.cpp',
        'single_transaction_stats.cpp',
        'transaction_history_iterator.cpp',
        env.Idlc('session_txn_record.idl')[0],
        env.Idlc('transactions_stats.idl')[0],
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/idl/idl_parser',
        'catalog/collection',
        'catalog/database_holder',
        'catalog/database',
        'catalog/uuid_catalog',
        'commands/test_commands_enabled',
        'concurrency/lock_manager',
        'curop_failpoint_helpers',
        'curop_metrics',
        'dbdirectclient',
        'index/index_access_method',
        'logical_session_id',
        'namespace_string',
        'repl/oplog_entry',
        's/sharding_api_d',
        'stats/fill_locker_info',
        'stats/top',
        'views/views',
    ],
    LIBDEPS_PRIVATE=[
        'commands/server_status',
        'op_observer',
        'update/update_driver',
    ]
)

env.CppUnitTest(
    target='catalog_raii_test',
    source=[
        'catalog_raii_test.cpp',
    ],
    LIBDEPS=[
        'auth/authmocks',
        'catalog/database_holder_mock',
        'catalog_raii',
        'service_context_test_fixture',
        'stats/fill_locker_info',
    ],
)

env.Library(
    target='dbdirectclient',
    source=[
        'dbdirectclient.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/client/clientdriver_minimal',
        'curop',
        'lasterror',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
    ],
)

env.Library(
    target='dbhelpers',
    source=[
        'dbhelpers.cpp',
    ],
    LIBDEPS=[
        'query_exec',
        'db_raii',
        'index/index_access_method',
        'write_ops',
    ],
)

env.Library(
    target='system_index',
    source=[
        'system_index.cpp',
    ],
    LIBDEPS=[
        'db_raii',
        'catalog/index_create',
        'catalog/index_key_validate',
        'concurrency/write_conflict_exception',
    ],
    LIBDEPS_PRIVATE=[
        'index_d',
    ]
)

env.Library(
    target="service_context_d",
    source=[
        "service_entry_point_mongod.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/concurrency/lock_manager',
        '$BUILD_DIR/mongo/db/ops/write_ops_parsers',
        '$BUILD_DIR/mongo/db/s/sharding_runtime_d',
        '$BUILD_DIR/mongo/db/storage/storage_engine_common',
        '$BUILD_DIR/mongo/db/storage/storage_options',
        '$BUILD_DIR/mongo/db/storage/storage_engine_lock_file',
        '$BUILD_DIR/mongo/db/storage/storage_engine_metadata',
        '$BUILD_DIR/mongo/transport/service_entry_point',
        'command_can_run_here',
        'curop',
        'curop_metrics',
        'lasterror',
        'rw_concern_d',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/commands/fsync_locked',
        '$BUILD_DIR/mongo/db/service_entry_point_common',
    ],
)

env.Library(
    target="op_observer",
    source=[
        "op_observer.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        'server_parameters',
    ],
)

env.Library(
    target="op_observer_impl",
    source=[
        "op_observer_impl.cpp",
    ],
    LIBDEPS=[
        'catalog/collection_options',
        'op_observer',
        'repl/oplog',
        's/sharding_api_d',
        'views/views_mongod',
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/catalog/uuid_catalog',
        '$BUILD_DIR/mongo/s/coreshard',
        "$BUILD_DIR/mongo/s/grid",
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/commands/mongod_fcv',
        '$BUILD_DIR/mongo/db/repl/image_collection_entry',
    ],
)

env.Library(
    target="service_entry_point_common",
    source=[
        "service_entry_point_common.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
    LIBDEPS_PRIVATE=[
        'introspect',
        'lasterror',
        'logical_session_cache_impl',
        'query_exec',
        '$BUILD_DIR/mongo/db/audit',
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/auth/authprivilege',
        '$BUILD_DIR/mongo/db/command_can_run_here',
        '$BUILD_DIR/mongo/db/ops/write_ops_exec',
        '$BUILD_DIR/mongo/db/rw_concern_d',
        '$BUILD_DIR/mongo/db/s/sharding_api_d',
        '$BUILD_DIR/mongo/db/stats/counters',
        '$BUILD_DIR/mongo/db/stats/server_read_concern_write_concern_metrics',
        '$BUILD_DIR/mongo/db/stats/top',
        '$BUILD_DIR/mongo/db/storage/storage_engine_lock_file',
        '$BUILD_DIR/mongo/db/storage/storage_engine_metadata',
    ],
)

env.Library(
    target="background",
    source=[
        "background.cpp",
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/base",
    ],
)

env.Library(
    target="cloner",
    source=[
        "cloner.cpp",
    ],
    LIBDEPS=[
        'dbdirectclient',
        'repl/isself',
        'write_ops',
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/catalog/collection_options',
        '$BUILD_DIR/mongo/db/catalog/index_create',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/internal_user_auth',
        '$BUILD_DIR/mongo/db/commands/list_collections_filter',
    ],
)

env.Library(
    target="curop_metrics",
    source=[
        "curop_metrics.cpp",
    ],
    LIBDEPS_PRIVATE=[
        "commands/server_status_core",
        "curop",
    ]
)

env.Library(
    target="index_d",
    source=[
        "index_builder.cpp",
        "index_legacy.cpp",
        "index_rebuilder.cpp",
    ],
    LIBDEPS=[
        'db_raii',
        'index/index_access_methods',
        '$BUILD_DIR/mongo/db/catalog/index_catalog',
        '$BUILD_DIR/mongo/db/catalog/index_create',
    ],
    LIBDEPS_PRIVATE=[
        "logical_clock",
    ],
)

env.Library(
    target="introspect",
    source=[
        "introspect.cpp",
    ],
    LIBDEPS=[
        "db_raii",
    ],
)

env.Library(
    target='prefetch',
    source=[
        'prefetch.cpp',
    ],
    LIBDEPS=[
        'dbhelpers',
        'index/index_access_method',
        '$BUILD_DIR/mongo/db/stats/timer_stats',
        '$BUILD_DIR/mongo/db/storage/mmap_v1/mmap',
    ],
)

env.Library(
    target="rw_concern_d",
    source=[
        "read_concern.cpp",
        "write_concern.cpp",
    ],
    LIBDEPS=[
        "concurrency/lock_manager",
        "concurrency/write_conflict_exception",
        "curop",
        "repl/read_concern_args",
        "repl/repl_coordinator_interface",
        "stats/timer_stats",
        "storage/storage_options",
    ],
    LIBDEPS_PRIVATE=[
        "$BUILD_DIR/mongo/s/grid",
        "catalog_raii",
        "commands/server_status_core",
        "s/sharding_api_d",
    ],
)

env.Library(
    target="repair_database",
    source=[
        "repair_database.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/catalog/collection',
        '$BUILD_DIR/mongo/db/catalog/database',
        '$BUILD_DIR/mongo/db/storage/mmap_v1/repair_database_interface',
        'background',
        'logical_clock',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/document_validation',
        '$BUILD_DIR/mongo/db/catalog/index_create',
        '$BUILD_DIR/mongo/db/catalog/index_key_validate',
        '$BUILD_DIR/mongo/db/storage/storage_repair_observer',
        '$BUILD_DIR/mongo/db/repl/oplog',
    ],
)

env.Library(
    target="ttl_d",
    source=[
        "ttl.cpp",
    ],
    LIBDEPS=[
        'db_raii',
        'query_exec',
        'ttl_collection_cache',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/commands/fsync_locked',
        'write_ops',
    ]
)

env.Library(
    target='query_exec',
    source=[
        'clientcursor.cpp',
        'cursor_manager.cpp',
        'exec/and_hash.cpp',
        'exec/and_sorted.cpp',
        'exec/cached_plan.cpp',
        'exec/change_stream_proxy.cpp',
        'exec/collection_scan.cpp',
        'exec/count.cpp',
        'exec/count_scan.cpp',
        'exec/delete.cpp',
        'exec/distinct_scan.cpp',
        'exec/ensure_sorted.cpp',
        'exec/eof.cpp',
        'exec/fetch.cpp',
        'exec/geo_near.cpp',
        'exec/group.cpp',
        'exec/idhack.cpp',
        'exec/index_iterator.cpp',
        'exec/index_scan.cpp',
        'exec/keep_mutations.cpp',
        'exec/limit.cpp',
        'exec/merge_sort.cpp',
        'exec/multi_iterator.cpp',
        'exec/multi_plan.cpp',
        'exec/near.cpp',
        'exec/oplogstart.cpp',
        'exec/or.cpp',
        'exec/pipeline_proxy.cpp',
        'exec/plan_stage.cpp',
        'exec/projection.cpp',
        'exec/projection_exec.cpp',
        'exec/queued_data_stage.cpp',
        'exec/shard_filter.cpp',
        'exec/skip.cpp',
        'exec/sort.cpp',
        'exec/sort_key_generator.cpp',
        'exec/subplan.cpp',
        'exec/text.cpp',
        'exec/text_match.cpp',
        'exec/text_or.cpp',
        'exec/update.cpp',
        'exec/working_set_common.cpp',
        'exec/write_stage_common.cpp',
        'ops/parsed_delete.cpp',
        'ops/parsed_update.cpp',
        'ops/update_lifecycle_impl.cpp',
        'ops/update_result.cpp',
        'query/explain.cpp',
        'query/find.cpp',
        'pipeline/document_source_cursor.cpp',
        'pipeline/pipeline_d.cpp',
        'query/get_executor.cpp',
        'query/internal_plans.cpp',
        'query/plan_executor.cpp',
        'query/plan_ranker.cpp',
        'query/plan_yield_policy.cpp',
        'query/query_yield.cpp',
        'query/stage_builder.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/s/common_s',
        '$BUILD_DIR/mongo/scripting/scripting',
        '$BUILD_DIR/mongo/util/background_job',
        '$BUILD_DIR/mongo/util/elapsed_tracker',
        '$BUILD_DIR/third_party/s2/s2',
        'audit',
        'background',
        'bson/dotted_path_support',
        'catalog/collection_info_cache',
        'catalog/collection',
        'catalog/database',
        'catalog/document_validation',
        'catalog/index_catalog_entry',
        'catalog/index_catalog',
        'commands',
        'concurrency/write_conflict_exception',
        'curop_failpoint_helpers',
        'curop',
        'cursor_server_params',
        'db_raii',
        'dbdirectclient',
        'exec/scoped_timer',
        'exec/working_set',
        'fts/base_fts',
        'index/index_descriptor',
        'index/key_generator',
        'logical_session_cache',
        'matcher/expressions_mongod_only',
        'pipeline/pipeline',
        'query/query_common',
        'query/query_planner',
        'repl/repl_coordinator_interface',
        's/sharding_api_d',
        'stats/serveronly_stats',
        'storage/oplog_hack',
        'storage/storage_options',
        'update/update_driver',
    ],
)

env.Library(
    target="serveronly",
    source=[
        # DO NOT ADD ADDITIONAL FILES TO THIS LIST.
        # See the additional comments in instance.cpp for details.
        'instance.cpp'
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/executor/network_interface_factory",
        "$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl",
        "$BUILD_DIR/mongo/scripting/scripting_server",
        "$BUILD_DIR/mongo/util/clock_sources",
        "$BUILD_DIR/mongo/util/elapsed_tracker",
        "$BUILD_DIR/mongo/util/net/network",
        "$BUILD_DIR/third_party/shim_snappy",
        "background",
        "bson/dotted_path_support",
        "catalog/catalog_impl",
        "catalog/collection_options",
        "catalog/document_validation",
        "catalog/index_key_validate",
        "cloner",
        "collection_index_usage_tracker",
        "common",
        "concurrency/lock_manager",
        "concurrency/write_conflict_exception",
        "curop_metrics",
        "curop",
        "db_raii",
        "dbdirectclient",
        "dbhelpers",
        "exec/working_set",
        "ftdc/ftdc_mongod",
        "fts/ftsmongod",
        "index_d",
        "index/index_access_method",
        "index/index_descriptor",
        "introspect",
        "keys_collection_client_direct",
        "logical_time_metadata_hook",
        "matcher/expressions_mongod_only",
        "ops/write_ops_parsers",
        "pipeline/aggregation",
        "prefetch",
        "query_exec",
        "repair_database",
        "repl/bgsync",
        "repl/oplog_application",
        "repl/oplog_buffer_blocking_queue",
        "repl/oplog_buffer_collection",
        "repl/oplog_buffer_proxy",
        "repl/repl_coordinator_impl",
        "repl/repl_coordinator_interface",
        "repl/repl_settings",
        "repl/rs_rollback",
        "repl/rslog",
        "repl/serveronly_repl",
        "repl/storage_interface",
        "repl/topology_coordinator",
        "rw_concern_d",
        "s/op_observer_sharding_impl",
        "s/sharding_commands_d",
        "s/sharding_runtime_d",
        "startup_warnings_mongod",
        "stats/counters",
        "stats/serveronly_stats",
        "stats/top",
        "storage/devnull/storage_devnull",
        "storage/ephemeral_for_test/storage_ephemeral_for_test",
        "storage/inmemory/storage_inmemory" if inmemory else [],
        "storage/mmap_v1/file_allocator",
        "storage/mmap_v1/mmap",
        "storage/mmap_v1/storage_mmapv1",
        "storage/storage_engine_lock_file",
        "storage/storage_engine_metadata",
        "storage/storage_init_d",
        "storage/storage_options",
        "storage/wiredtiger/storage_wiredtiger" if wiredtiger else [],
        "ttl_collection_cache",
        "ttl_d",
        "update_index_data",
        "update/update_driver",
        "views/views_mongod",
    ],
)

env.Library(
    target="repair_database_and_check_version",
    source=[
        "repair_database_and_check_version.cpp",
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/catalog_helpers',
        '$BUILD_DIR/mongo/db/commands/mongod_fcv',
        'dbdirectclient',
        'dbhelpers',
        'repair_database',
        'repl/drop_pending_collection_reaper',
        'repl/repl_settings',
        'storage/storage_repair_observer',
    ],
)

env.Library(
    target='logical_session_id',
    source=[
        'logical_session_id.cpp',
        env.Idlc('logical_session_id.idl')[0],
        env.Idlc('refresh_sessions.idl')[0],
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/crypto/sha256_block',
        '$BUILD_DIR/mongo/crypto/sha_block_${MONGO_CRYPTO}',
        '$BUILD_DIR/mongo/idl/idl_parser',
        'server_parameters',
    ],
)

env.Library(
    target='logical_session_id_helpers',
    source=[
        'logical_session_id_helpers.cpp',
    ],
    LIBDEPS=[
        'logical_session_id',
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/auth/authprivilege',
    ],
)

env.Library(
    target='service_liaison',
    source=[
        'service_liaison.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/crypto/sha1_block',
        'keys_collection_document',
        'logical_clock',
        'logical_session_id',
    ],
)

envWithAsio = env.Clone()
envWithAsio.InjectThirdPartyIncludePaths(libraries=['asio'])

envWithAsio.CppUnitTest(
    target='logical_session_id_test',
    source=[
        'logical_session_id_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/auth/authmocks',
        '$BUILD_DIR/mongo/transport/transport_layer_mock',
        'logical_session_cache',
        'logical_session_cache_impl',
        'logical_session_id',
        'logical_session_id_helpers',
        'service_context_test_fixture',
        'service_liaison_mock',
        'sessions_collection_mock',
    ],
)

envWithAsio.Library(
    target='service_liaison_mock',
    source=[
        'service_liaison_mock.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/executor/async_timer_mock',
        '$BUILD_DIR/mongo/util/periodic_runner_factory',
        'kill_sessions',
        'service_liaison',
    ],
)

envWithAsio.Library(
    target='service_liaison_mongod',
    source=[
        'service_liaison_mongod.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/clock_sources',
        '$BUILD_DIR/mongo/util/periodic_runner',
        'query_exec',
        'service_context',
        'service_liaison',
    ],
)

env.Library(
    target='service_liaison_mongos',
    source=[
        'service_liaison_mongos.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/clock_sources',
        '$BUILD_DIR/mongo/util/periodic_runner',
        '$BUILD_DIR/mongo/s/coreshard',
        '$BUILD_DIR/mongo/s/query/cluster_cursor_manager',
        'service_context',
        'service_liaison',
    ],
)

env.Library(
    target='sessions_collection',
    source=[
        'sessions_collection.cpp',
        env.Idlc('create_indexes.idl')[0],
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/client/clientdriver_minimal',
        '$BUILD_DIR/mongo/s/write_ops/batch_write_types',
        'logical_session_id',
    ],
)

env.Library(
    target='sessions_collection_mock',
    source=[
        'sessions_collection_mock.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/logical_session_id',
        'sessions_collection',
    ],
)

env.Library(
    target='sessions_collection_rs',
    source=[
        'sessions_collection_rs.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/client/remote_command_targeter',
        '$BUILD_DIR/mongo/db/concurrency/lock_manager',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        'dbdirectclient',
        'sessions_collection',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/internal_user_auth',
    ],
)

env.Library(
    target='sessions_collection_standalone',
    source=[
        'sessions_collection_standalone.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        'dbdirectclient',
        'logical_session_id',
        'sessions_collection',
    ],
)

env.Library(
    target='sessions_collection_sharded',
    source=[
        'sessions_collection_sharded.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        'logical_session_id',
        'sessions_collection',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/s/sharding_api',
        'sessions_collection_rs',
    ],
)

env.Library(
    target='sessions_collection_config_server',
    source=[
        'sessions_collection_config_server.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/s/client/sharding_client',
        '$BUILD_DIR/mongo/s/coreshard',
        'dbdirectclient',
        'sessions_collection',
        'sessions_collection_sharded',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/s/commands/cluster_commands_helpers',
    ]
)

env.Library(
    target='logical_session_cache',
    source=[
        'logical_session_cache.cpp',
        env.Idlc('logical_session_cache_stats.idl')[0],
    ],
    LIBDEPS=[
        'logical_session_id',
        'service_context',
    ],
)

env.Library(
    target='logical_session_cache_impl',
    source=[
        'initialize_operation_session_info.cpp',
        'logical_session_cache_impl.cpp',
    ],
    LIBDEPS=[
        'logical_session_cache',
        'logical_session_id',
        'logical_session_id_helpers',
        'sessions_collection',
        'server_parameters',
        'service_liaison',
        'kill_sessions',
    ],
    LIBDEPS_PRIVATE=[
        's/sharding_api_d',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface'
    ]
)

env.Library(
    target='shared_request_handling',
    source=[
        'handle_request_response.cpp',
        'transaction_validation.cpp',
    ],
    LIBDEPS=[
        'logical_session_cache_impl',
    ],
)

envWithAsio.CppUnitTest(
    target='logical_session_cache_test',
    source=[
        'logical_session_cache_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/executor/async_timer_mock',
        '$BUILD_DIR/mongo/util/clock_source_mock',
        'auth/authmocks',
        'dbdirectclient',
        'keys_collection_document',
        'keys_collection_manager',
        'logical_clock',
        'logical_session_cache_impl',
        'logical_session_id_helpers',
        'logical_session_id',
        'repl/replmocks',
        'service_context_d_test_fixture',
        'service_liaison_mock',
        'sessions_collection_mock',
    ],
)

envWithAsio.Library(
    target='logical_session_cache_factory_mongod',
    source=[
        'logical_session_cache_factory_mongod.cpp',
    ],
    LIBDEPS=[
        'logical_session_cache_impl',
        'service_liaison_mongod',
        'sessions_collection_config_server',
        'sessions_collection_rs',
        'sessions_collection_sharded',
        'sessions_collection_standalone',
    ],
)

env.Library(
    target='logical_time',
    source=[
        'logical_time.cpp',
        'operation_time_tracker.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        'service_context',
    ],
)

env.Library(
    target='kill_sessions',
    source=[
        'kill_sessions.cpp',
        'kill_sessions_common.cpp',
        'session_killer.cpp',
        env.Idlc('kill_sessions.idl')[0],
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/auth/authprivilege',
        '$BUILD_DIR/mongo/idl/idl_parser',
    ],
)

env.Library(
    target='kill_sessions_local',
    source=[
        'kill_sessions_local.cpp',
    ],
    LIBDEPS=[
        'kill_sessions',
        'query_exec',
    ],
)

env.Library(
    target='periodic_runner_job_abort_expired_transactions',
    source=[
        'periodic_runner_job_abort_expired_transactions.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/periodic_runner',
        'kill_sessions_local',
    ],
)

env.Library(
    target='signed_logical_time',
    source=[
        'signed_logical_time.cpp',
    ],
    LIBDEPS=[
        'logical_time',
        '$BUILD_DIR/mongo/crypto/sha1_block',
    ],
)

env.Library(
    target='time_proof_service',
    source=[
        'time_proof_service.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/crypto/sha_block_${MONGO_CRYPTO}',
        'logical_time',
    ],
)

env.Library(
    target='keys_collection_document',
    source=[
        'keys_collection_document.cpp',
    ],
    LIBDEPS=[
        'logical_time',
        'time_proof_service'
    ],
)

env.Library(
    target='keys_collection_client_direct',
    source=[
        'keys_collection_client_direct.cpp',
    ],
    LIBDEPS=[
        'logical_clock',
        'keys_collection_document',
        'logical_time',
        '$BUILD_DIR/mongo/s/client/rs_local_client',
        '$BUILD_DIR/mongo/s/client/shard_interface',
    ],
)

env.Library(
    target='keys_collection_client_sharded',
    source=[
        'keys_collection_client_sharded.cpp',
    ],
    LIBDEPS=[
        'logical_clock',
        'keys_collection_document',
        'logical_time',
        '$BUILD_DIR/mongo/s/catalog/sharding_catalog_client',
    ],
)

env.Library(
    target='keys_collection_manager',
    source=[
        'keys_collection_manager.cpp',
        'keys_collection_cache.cpp',
        'key_generator.cpp',
    ],
    LIBDEPS=[
        'logical_clock',
        'keys_collection_document',
        'logical_time',
        'keys_collection_client_sharded',
    ],
)

env.Library(
    target='logical_clock',
    source=[
        'logical_clock.cpp',
    ],
    LIBDEPS=[
        'global_settings',
        'logical_time',
        'server_parameters',
        'service_context',
    ],
)

env.Library(
    target='logical_time_validator',
    source=[
        'logical_time_validator.cpp',
    ],
    LIBDEPS=[
        'keys_collection_manager',
        'service_context',
        'signed_logical_time',
        'time_proof_service',
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/auth/authprivilege',
    ],
)

env.CppUnitTest(
    target='keys_collection_document_test',
    source=[
        'keys_collection_document_test.cpp',
    ],
    LIBDEPS=[
        'keys_collection_document',
    ],
)

env.CppUnitTest(
    target='operation_time_tracker_test',
    source=[
        'operation_time_tracker_test.cpp',
    ],
    LIBDEPS=[
        'logical_time',
    ],
)

env.CppUnitTest(
    target='logical_time_test',
    source=[
        'logical_time_test.cpp',
    ],
    LIBDEPS=[
        'logical_time',
        'signed_logical_time',
        'time_proof_service',
    ],
)

env.CppUnitTest(
    target='logical_clock_test',
    source=[
        'logical_clock_test.cpp',
    ],
    LIBDEPS=[
        'logical_clock_test_fixture',
    ],
)

env.CppUnitTest(
    target='logical_time_validator_test',
    source=[
        'logical_time_validator_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/auth/authmocks',
        '$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock',
        '$BUILD_DIR/mongo/s/config_server_test_fixture',
        'keys_collection_manager',
        'logical_time_validator',
    ],
)

env.Library(
    target= 'logical_time_metadata_hook',
    source= [
        'logical_time_metadata_hook.cpp',
    ],
    LIBDEPS= [
        'logical_time_validator',
        'signed_logical_time',
        '$BUILD_DIR/mongo/rpc/metadata',
    ],
)

env.Library(
    target= 'logical_clock_test_fixture',
    source= [
        'logical_clock_test_fixture.cpp',
    ],
    LIBDEPS= [
        'logical_clock',
        'signed_logical_time',
        '$BUILD_DIR/mongo/db/auth/authmocks',
        '$BUILD_DIR/mongo/s/sharding_mongod_test_fixture',
        '$BUILD_DIR/mongo/util/clock_source_mock'
    ],
)

env.CppUnitTest(
    target='time_proof_service_test',
    source=[
        'time_proof_service_test.cpp',
    ],
    LIBDEPS=[
        'time_proof_service',
    ],
)

env.CppUnitTest(
    target='keys_collection_manager_sharding_test',
    source=[
        'key_generator_update_test.cpp',
        'keys_collection_cache_test.cpp',
        'keys_collection_manager_sharding_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/auth/authmocks',
        '$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock',
        '$BUILD_DIR/mongo/s/config_server_test_fixture',
        'keys_collection_manager',
    ],
)

env.Library(
    target='service_context_test_fixture',
    source=[
        'service_context_test_fixture.cpp',
    ],
    LIBDEPS=[
        'service_context',
        '$BUILD_DIR/mongo/unittest/unittest',
    ],
    LIBDEPS_PRIVATE=[
        'op_observer',
    ],
)

env.Library(
    target= 'service_context_d_test_fixture',
    source= [
        'service_context_d_test_fixture.cpp',
    ],
    LIBDEPS= [
        '$BUILD_DIR/mongo/db/commands/mongod',
        '$BUILD_DIR/mongo/db/serveronly',
        '$BUILD_DIR/mongo/db/storage/storage_options',
        '$BUILD_DIR/mongo/unittest/unittest',
        'service_context_d',
        'service_context_test_fixture',
    ],
)

env.Library(
    target='log_process_details',
    source=[
        'log_process_details.cpp',
    ],
    LIBDEPS=[
        'repl/repl_coordinator_interface',
        'repl/replica_set_messages',
        'server_options_servers',
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/util/net/network',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/util/processinfo',
    ],
)

env.Library(
    target='cursor_server_params',
    source=[
        'cursor_server_params.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/server_parameters',
    ],
)

env.Library(
    target='generic_cursor',
    source=[
        env.Idlc('generic_cursor.idl')[0],
    ],
    LIBDEPS=[
        'service_context',
        '$BUILD_DIR/mongo/idl/idl_parser',
    ],
)

env.Library(
    target='ttl_collection_cache',
    source=[
        'ttl_collection_cache.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/service_context',
    ],
)

env.Library(
    target='wire_version',
    source=[
        'wire_version.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
)

asioEnv = env.Clone()
asioEnv.InjectThirdPartyIncludePaths('asio')

asioEnv.CppIntegrationTest(
    target='nesting_depth_test',
    source=[
        'nesting_depth_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/executor/network_interface_fixture',
        '$BUILD_DIR/mongo/transport/transport_layer_egress_init',
    ],
)

env.Library(
    target='write_ops',
    source=[
        'ops/delete.cpp',
        'ops/find_and_modify_result.cpp',
        'ops/insert.cpp',
        'ops/update.cpp',
        'ops/write_ops_retryability.cpp',
        env.Idlc('ops/single_write_result.idl')[0],
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/repl/image_collection_entry',
        'catalog_raii',
        'catalog/collection_info_cache',
        'concurrency/lock_manager',
        'introspect',
        'matcher/expressions_mongod_only',
        'query_exec',
        'query/command_request_response',
        'repl/repl_coordinator_interface',
        'service_context',
        'update/update_driver',
    ],
)

env.CppUnitTest(
    target='sessions_test',
    source=[
        'session_catalog_reap_sessions_test.cpp',
        'session_catalog_test.cpp',
        'session_test.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/client/read_preference',
        '$BUILD_DIR/mongo/util/clock_source_mock',
        'auth/authmocks',
        'query_exec',
        'repl/mock_repl_coord_server_fixture',
        'sessions_collection_mock',
    ],
)

env.CppUnitTest(
    target='transaction_history_iterator_test',
    source=[
        'transaction_history_iterator_test.cpp',
    ],
    LIBDEPS_PRIVATE=[
        'auth/authmocks',
        'query_exec',
        'repl/mock_repl_coord_server_fixture',
        'service_context_d',
        'write_ops',
    ],
)

env.CppUnitTest(
    target='multi_key_path_tracker_test',
    source=[
        'multi_key_path_tracker_test.cpp',
    ],
    LIBDEPS_PRIVATE=[
        'service_context',
    ],
)
