# -*- mode: python; -*-

Import([
    'env',
    'get_option'
])

env = env.Clone()

env.Library(
    target='benchrun',
    source=[
        'bench.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/client/clientdriver_minimal',
        '$BUILD_DIR/mongo/db/logical_session_id',
        '$BUILD_DIR/mongo/scripting/bson_template_evaluator',
    ]
)

generateJSErrorCodes = env.Command(
    target=['error_codes.js'],
    source=[
        '$BUILD_DIR/mongo/base/generate_error_codes.py',
        '$BUILD_DIR/mongo/base/error_codes.yml',
        'error_codes.tpl.js',
    ],
    action=['$PYTHON ${SOURCES[0]} ${SOURCES[1]} ${SOURCES[2]} ${TARGETS[0]}'])
env.Alias('generated-sources', generateJSErrorCodes)

# Files added here need to be added in scripting/engine.cpp and buildscripts/vcxproj.header as well.
js_header = env.JSHeader(
    target="mongo.cpp",
    source=[
        "assert.js",
        "bulk_api.js",
        "check_log.js",
        "collection.js",
        "crud_api.js",
        "db.js",
        "error_codes.js",
        "explainable.js",
        "explain_query.js",
        "mongo.js",
        "query.js",
        "session.js",
        "types.js",
        "utils_auth.js",
        "utils.js",
        "utils_sh.js",
    ]
)

env.Alias('generated-sources', js_header)

# Files added here need to be added in shell/shell_utils.cpp as well.
env.JSHeader(
    target="mongo-server.cpp",
    source=[
        "servers.js",
        "shardingtest.js",
        "servers_misc.js",
        "replsettest.js",
        "data_consistency_checker.js",
        "bridge.js",
        "keyvault.js",
        "feature_compatibility_version.js",
    ],
)

env.Alias('generated-sources', "mongo-server.cpp")

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

env.Library(
    target='shell_options_storage',
    source=[
        'shell_options_storage.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/client/connection_string',
        '$BUILD_DIR/mongo/util/cmdline_utils/cmdline_utils',
    ],
)

env.Library(
    target='shell_options_register',
    source=[
        env.Idlc('shell_options.idl')[0],
    ],
    LIBDEPS=[
        'shell_options_storage',
        '$BUILD_DIR/mongo/base',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/util/options_parser/options_parser',
    ],
)

env.Library(
    target='shell_utils',
    source=[
        'mongo-server.cpp',
        'shell_options.cpp',
        'shell_utils.cpp',
        'shell_utils_extended.cpp',
        'shell_utils_launcher.cpp',
    ],
    LIBDEPS=[
        'benchrun',
        '$BUILD_DIR/mongo/base/environment_buffer',
        '$BUILD_DIR/mongo/client/clientdriver_network',
        '$BUILD_DIR/mongo/db/mongohasher',
        '$BUILD_DIR/mongo/db/traffic_reader',
        '$BUILD_DIR/mongo/scripting/scripting',
        '$BUILD_DIR/mongo/transport/message_compressor',
        '$BUILD_DIR/mongo/util/password',
        'shell_options_storage',
    ]
)

kmsEnv = env.Clone()

kmsEnv.InjectThirdParty(libraries=['kms-message'])

kmsEnv.Library(
    target="kms",
    source=[
        "kms.cpp",
        "kms_aws.cpp",
        "kms_local.cpp",
        kmsEnv.Idlc("kms.idl")[0],
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base/secure_allocator',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/crypto/aead_encryption',
        '$BUILD_DIR/mongo/db/commands/test_commands_enabled',
        '$BUILD_DIR/mongo/util/net/network',
        '$BUILD_DIR/mongo/util/net/socket',
        '$BUILD_DIR/mongo/util/net/ssl_manager',
        '$BUILD_DIR/mongo/util/net/ssl_options',
        '$BUILD_DIR/third_party/shim_kms_message',
    ],
)

env.Library(
    target="kms_shell",
    source=[
        "kms_shell.cpp",
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/shell_core',
        'kms',
    ],
)

scriptingEnv = env.Clone()
scriptingEnv.InjectMozJS()

scriptingEnv.Library(
    target="encrypted_dbclient",
    source=[
        "encrypted_dbclient_base.cpp",
        scriptingEnv.Idlc("fle_shell_options.idl")[0],
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/crypto/aead_encryption',
        '$BUILD_DIR/mongo/crypto/symmetric_crypto',
        '$BUILD_DIR/mongo/client/clientdriver_minimal',
        '$BUILD_DIR/mongo/scripting/scripting',
        '$BUILD_DIR/mongo/shell/shell_options_register',
        '$BUILD_DIR/third_party/shim_mozjs',
        'kms',
    ],
)

env.CppUnitTest(
    target='shell_test',
    source=[
        'kms_test.cpp' if get_option('ssl') == 'on' else [],
        'shell_options_test.cpp',
        'shell_utils_test.cpp'
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/signal_handlers',
        'kms' if get_option('ssl') == 'on' else [],
        'shell_options_register',
        'shell_utils',
    ],
)
