# -*- mode: python -*-

Import("env")
Import("has_option")

env.Library(
    target="test_commands_enabled",
    source=[
        "test_commands_enabled.cpp",
    ]
)

env.Library(
    target='server_status_core',
    source=[
        'server_status_internal.cpp',
        'server_status_metric.cpp',
        ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/net/network',
        '$BUILD_DIR/mongo/base'
        ]
    )

env.Library(
    target="core",
    source=[
        "authentication_commands.cpp",
        "conn_pool_stats.cpp",
        "conn_pool_sync.cpp",
        "connection_status.cpp",
        "copydb_common.cpp",
        "fail_point_cmd.cpp",
        "feature_compatibility_version_command_parser.cpp",
        "find_and_modify_common.cpp",
        "hashcmd.cpp",
        "isself.cpp",
        "mr_common.cpp",
        "rename_collection_common.cpp",
        "server_status.cpp",
        "parameters.cpp",
        "user_management_commands_common.cpp",
        "write_commands/write_commands_common.cpp",
        "generic.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/client/clientdriver',
        '$BUILD_DIR/mongo/db/audit',
        '$BUILD_DIR/mongo/db/auth/authcommon',
        '$BUILD_DIR/mongo/db/auth/authorization_manager_global',
        '$BUILD_DIR/mongo/db/auth/serverauth',
        '$BUILD_DIR/mongo/db/commands',
        '$BUILD_DIR/mongo/db/commands/test_commands_enabled',
        '$BUILD_DIR/mongo/db/common',
        '$BUILD_DIR/mongo/db/curop',
        '$BUILD_DIR/mongo/db/exec/working_set',
        '$BUILD_DIR/mongo/db/index/key_generator',
        '$BUILD_DIR/mongo/db/index_names',
        '$BUILD_DIR/mongo/db/lasterror',
        '$BUILD_DIR/mongo/db/log_process_details',
        '$BUILD_DIR/mongo/db/matcher/expressions',
        '$BUILD_DIR/mongo/db/matcher/expressions_geo',
        '$BUILD_DIR/mongo/db/repl/isself',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_global',
        '$BUILD_DIR/mongo/db/server_options',
        '$BUILD_DIR/mongo/db/server_parameters',
        '$BUILD_DIR/mongo/db/startup_warnings_common',
        '$BUILD_DIR/mongo/db/stats/counters',
        '$BUILD_DIR/mongo/db/stats/timer_stats',
        '$BUILD_DIR/mongo/db/views/views',
        '$BUILD_DIR/mongo/logger/parse_log_component_settings',
        '$BUILD_DIR/mongo/s/client/sharding_client',
        '$BUILD_DIR/mongo/s/coreshard',
        '$BUILD_DIR/mongo/s/write_ops/batch_write_types',
        '$BUILD_DIR/mongo/scripting/scripting_common',
        '$BUILD_DIR/mongo/transport/message_compressor',
        '$BUILD_DIR/mongo/transport/transport_layer_common',
        '$BUILD_DIR/mongo/util/cmdline_utils/cmdline_utils',
        '$BUILD_DIR/mongo/util/ntservice',
        '$BUILD_DIR/mongo/util/processinfo',
        'server_status_core',
    ],
)

# Commands that should only be present in mongod
env.Library(
    target="dcommands",
    source=[
        "apply_ops_cmd.cpp",
        "clone.cpp",
        "clone_collection.cpp",
        "collection_to_capped.cpp",
        "dbcommands.cpp",
        "compact.cpp",
        "copydb.cpp",
        "copydb_start_commands.cpp",
        "count_cmd.cpp",
        "create_indexes.cpp",
        "current_op.cpp",
        "dbhash.cpp",
        "distinct.cpp",
        "driverHelpers.cpp",
        "drop_indexes.cpp",
        "eval.cpp",
        "explain_cmd.cpp",
        "feature_compatibility_version.cpp",
        "find_and_modify.cpp",
        "find_cmd.cpp",
        "fsync.cpp",
        "geo_near_cmd.cpp",
        "get_last_error.cpp",
        "getmore_cmd.cpp",
        "group_cmd.cpp",
        "haystack.cpp",
        "index_filter_commands.cpp",
        "kill_op.cpp",
        "killcursors_cmd.cpp",
        "list_collections.cpp",
        "list_databases.cpp",
        "list_indexes.cpp",
        "lock_info.cpp",
        "mr.cpp",
        "oplog_note.cpp",
        "parallel_collection_scan.cpp",
        "pipeline_command.cpp",
        "plan_cache_commands.cpp",
        "rename_collection_cmd.cpp",
        "repair_cursor.cpp",
        "resize_oplog.cpp",
        "set_feature_compatibility_version_command.cpp",
        "snapshot_management.cpp",
        "test_commands.cpp",
        "top_command.cpp",
        "touch.cpp",
        "user_management_commands.cpp",
        "validate.cpp",
        "write_commands/write_commands.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/client/clientdriver',
        '$BUILD_DIR/mongo/db/auth/authmongod',
        '$BUILD_DIR/mongo/db/catalog/index_key_validate',
        '$BUILD_DIR/mongo/db/commands',
        '$BUILD_DIR/mongo/db/index/index_access_methods',
        '$BUILD_DIR/mongo/db/lasterror',
        '$BUILD_DIR/mongo/db/ops/write_ops',
        '$BUILD_DIR/mongo/db/ops/write_ops_parsers',
        '$BUILD_DIR/mongo/db/pipeline/serveronly',
        '$BUILD_DIR/mongo/db/repl/isself',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_impl',
        '$BUILD_DIR/mongo/db/server_options_core',
        '$BUILD_DIR/mongo/db/stats/serveronly',
        '$BUILD_DIR/mongo/db/storage/mmap_v1/storage_mmapv1',
        '$BUILD_DIR/mongo/s/client/parallel',
        '$BUILD_DIR/mongo/util/uuid',
        'apply_ops_cmd_common',
        'core',
        'killcursors_common',
    ],
    LIBDEPS_TAGS=[
        # TODO: There are many libraries missing from LIBDEPS
        'incomplete'
    ]
)

env.Library(
    target='killcursors_common',
    source=[
        'killcursors_common.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/audit',
        '$BUILD_DIR/mongo/db/commands',
        '$BUILD_DIR/mongo/db/auth/authorization_manager_global',
        '$BUILD_DIR/mongo/db/query/command_request_response',
    ],
)

env.Library(
    target='apply_ops_cmd_common',
    source=[
        'apply_ops_cmd_common.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/catalog/document_validation',
        '$BUILD_DIR/mongo/db/commands',
        '$BUILD_DIR/mongo/db/auth/authcore',
        '$BUILD_DIR/mongo/db/namespace_string',
        '$BUILD_DIR/mongo/db/service_context',
    ],
)


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

env.CppUnitTest(
    target="list_collections_filter_test",
    source=[
        "list_collections_filter_test.cpp"
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/commands/list_collections_filter',
    ],
)

env.CppUnitTest(
    target="index_filter_commands_test",
    source=[
        "index_filter_commands_test.cpp",
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/db/query/query_test_service_context",
        "$BUILD_DIR/mongo/db/serveronly",
    ],
)

env.CppUnitTest(
    target="mr_test",
    source=[
        "mr_test.cpp",
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/db/serveronly",
    ],
)

env.CppUnitTest(
    target="plan_cache_commands_test",
    source=[
        "plan_cache_commands_test.cpp",
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/db/query/query_test_service_context",
        "$BUILD_DIR/mongo/db/serveronly",
    ],
)

if has_option('use-cpu-profiler'):
    profEnv = env.Clone()
    profEnv.InjectThirdPartyIncludePaths('gperftools')
    profEnv.Library('cpuprofiler',
        source=[
            'cpuprofile.cpp',
        ],
        LIBDEPS=[
        ],
        LIBDEPS_TAGS=[
            'incomplete'
        ],
    )
