# -*- mode: python -*-

Import('env')

# Contains only the core ConnectionString functionality, *not* the ability to call connect()
# and return a DBClientBase* back. For that you need to link against the 'clientdriver' library.
env.Library(
    target='connection_string',
    source=[
        'connection_string.cpp',
        'mongo_uri.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/net/hostandport',
    ]
)

env.CppUnitTest(
    target='connection_string_test',
    source=[
        'connection_string_test.cpp',
        'mongo_uri_test.cpp',
    ],
    LIBDEPS=[
        'connection_string',
    ]
)

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

env.CppUnitTest(
    target=[
        'read_preference_test',
    ],
    source=[
        'read_preference_test.cpp',
    ],
    LIBDEPS=[
        'read_preference',
    ]
)

saslClientEnv = env.Clone()
saslLibs = []
saslClientSource = [
    'native_sasl_client_session.cpp',
    'sasl_client_authenticate.cpp',
    'sasl_client_authenticate_impl.cpp',
    'sasl_client_conversation.cpp',
    'sasl_client_session.cpp',
    'sasl_plain_client_conversation.cpp',
    'sasl_scramsha1_client_conversation.cpp',
]

# Add in actual sasl dependencies if sasl is enabled, otherwise
# leave library empty so other targets can link to it unconditionally
# without needing to first test MONGO_BUILD_SASL_CLIENT.
if env['MONGO_BUILD_SASL_CLIENT']:
    saslClientSource.extend([
        'cyrus_sasl_client_session.cpp',
        'sasl_sspi.cpp',
        'sasl_sspi_options.cpp',
    ])

    saslLibs.extend(['sasl2'])
    if env.TargetOSIs('windows'):
        saslLibs.extend(['secur32'])

saslClientEnv.Library(
    target='sasl_client',
    source=saslClientSource,
    LIBDEPS=[
        '$BUILD_DIR/mongo/bson/util/bson_extract',
        '$BUILD_DIR/mongo/crypto/scramauth',
        '$BUILD_DIR/mongo/executor/remote_command',
        '$BUILD_DIR/mongo/rpc/command_status',
        '$BUILD_DIR/mongo/rpc/metadata',
        '$BUILD_DIR/mongo/util/foundation',
        '$BUILD_DIR/mongo/util/md5',
        '$BUILD_DIR/mongo/util/net/network',
    ],
    SYSLIBDEPS=saslLibs
)

env.Library(
    target='authentication',
    source=[
        'authenticate.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/bson/util/bson_extract',
        '$BUILD_DIR/mongo/executor/remote_command',
        'sasl_client'
    ]
)

env.CppUnitTest(
    target=[
        'authenticate_test',
    ],
    source=[
        'authenticate_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/rpc/command_status',
        '$BUILD_DIR/mongo/util/net/hostandport',
        '$BUILD_DIR/mongo/util/md5',
        'authentication',
    ]
)

env.Library(
    target='clientdriver',
    source=[
        'connection_string_connect.cpp',
        'mongo_uri_connect.cpp',
        'connpool.cpp',
        'dbclient.cpp',
        'dbclient_rs.cpp',
        'dbclientcursor.cpp',
        'global_conn_pool.cpp',
        'replica_set_monitor.cpp',
        'replica_set_monitor_manager.cpp',
        'syncclusterconnection.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/auth/authcommon',
        '$BUILD_DIR/mongo/db/commands/test_commands_enabled',
        '$BUILD_DIR/mongo/db/dbmessage',
        '$BUILD_DIR/mongo/executor/connection_pool_stats',
        '$BUILD_DIR/mongo/rpc/command_status',
        '$BUILD_DIR/mongo/rpc/rpc',
        '$BUILD_DIR/mongo/util/net/network',
        '$BUILD_DIR/mongo/util/md5',
        'authentication',
        'connection_string',
        'read_preference',
    ],
    LIBDEPS_TAGS=[
        # Depends on mongo::inShutdown
        'incomplete'
    ],

)

env.Library(
    target='connection_pool',
    source=[
        'connection_pool.cpp',
    ],
    LIBDEPS=[
        'clientdriver',
        '$BUILD_DIR/mongo/db/auth/authcommon',
        '$BUILD_DIR/mongo/db/auth/authorization_manager_global',
    ]
)

env.Library(
    target='remote_command_runner_impl',
    source=[
        'remote_command_runner_impl.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/executor/downconvert_find_and_getmore_commands',
        '$BUILD_DIR/mongo/executor/task_executor_interface',
        '$BUILD_DIR/mongo/rpc/metadata',
        '$BUILD_DIR/mongo/util/net/hostandport',
        'connection_pool',
    ],
    LIBDEPS_TAGS=[
        # Needs things from coredb in Command, but this would be circular through the
        # libsharding_client
        'incomplete',
    ],
)

env.Library(
    target='remote_command_targeter',
    source=[
        'remote_command_targeter.cpp',
        'remote_command_targeter_factory_impl.cpp',
        'remote_command_targeter_rs.cpp',
        'remote_command_targeter_standalone.cpp',
    ],
    LIBDEPS=[
        'clientdriver',
    ]
)

env.Library(
    target='remote_command_targeter_mock',
    source=[
        'remote_command_targeter_mock.cpp',
        'remote_command_targeter_factory_mock.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/net/hostandport',
    ]
)

env.CppUnitTest(
    target='replica_set_monitor_test',
    source=[
        'replica_set_monitor_node_test.cpp',
        'replica_set_monitor_read_preference_test.cpp',
        'replica_set_monitor_test.cpp',
    ],
    LIBDEPS=[
        'clientdriver'
    ]
)

env.CppUnitTest('dbclient_rs_test',
                ['dbclient_rs_test.cpp'],
                LIBDEPS=['clientdriver', '$BUILD_DIR/mongo/dbtests/mocklib'])

env.CppUnitTest(
    target='scoped_db_conn_test',
    source=[
        'scoped_db_conn_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
        '$BUILD_DIR/mongo/util/net/message_server_port',
        '$BUILD_DIR/mongo/s/coreshard',
        '$BUILD_DIR/mongo/s/mongoscore',
        '$BUILD_DIR/mongo/util/ntservice_mock',
    ],
    NO_CRUTCH=True,
)

env.Library(
    target='parallel',
    source=[
        'parallel.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/s/catalog/catalog_manager',
        '$BUILD_DIR/mongo/s/coreshard',
        'clientdriver',
    ],
)

env.Library(
    target='fetcher',
    source=[
        'fetcher.cpp',
        'query_fetcher.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/executor/task_executor_interface',
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/namespace_string',
        '$BUILD_DIR/mongo/rpc/command_status',
    ],
)

env.CppUnitTest(
    target='fetcher_test',
    source='fetcher_test.cpp',
    LIBDEPS=[
        'fetcher',
        '$BUILD_DIR/mongo/db/repl/replication_executor_test_fixture',
    ],
)
