# -*- mode: python -*-

Import("env")
Import("get_option")

env = env.Clone()

# These commands are registered with both the router and shard command registries.
# This library is currently also linked into mongoqd
env.Library(
    target='sharded_cluster_sharding_commands',
    source=[
        'flush_router_config_cmd.cpp',
        'get_shard_map_cmd.cpp',
        'sharding_expressions.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/index_key_validate',
        '$BUILD_DIR/mongo/db/commands',
        '$BUILD_DIR/mongo/db/fts/base_fts',
        '$BUILD_DIR/mongo/db/index/expression_params',
        '$BUILD_DIR/mongo/db/index/index_access_method',
        '$BUILD_DIR/mongo/db/shard_role_api',
        '$BUILD_DIR/mongo/s/grid',
    ],
)

# These commands are registered only with the router-role.
# They are also available on mongoqd.
env.Library(
    target='cluster_commands',
    source=[
        'cluster_abort_move_collection_cmd.cpp',
        'cluster_abort_reshard_collection_cmd.cpp',
        'cluster_abort_unshard_collection_cmd.cpp',
        'cluster_abort_transaction_cmd_s.cpp',
        'cluster_analyze_cmd.cpp',
        'cluster_auto_split_vector_cmd.cpp',
        'cluster_build_info.cpp',
        'cluster_bulk_write_cmd_s.cpp',
        'cluster_cleanup_reshard_collection_cmd.cpp',
        'cluster_coll_stats_cmd.cpp',
        'cluster_collection_mod_cmd.cpp',
        'cluster_commands.idl',
        'cluster_commit_reshard_collection_cmd.cpp',
        'cluster_commit_transaction_cmd_s.cpp',
        'cluster_compact_cmd.cpp',
        'cluster_convert_to_capped_cmd.cpp',
        'cluster_coordinate_commit_txn.cpp',
        'cluster_count_cmd_s.cpp',
        'cluster_create_cmd.cpp',
        'cluster_create_indexes_cmd.cpp',
        'cluster_current_op.cpp',
        'cluster_data_size_cmd.cpp',
        'cluster_db_stats_cmd.cpp',
        'cluster_distinct_cmd.cpp',
        'cluster_drop_collection_cmd.cpp',
        'cluster_drop_database_cmd.cpp',
        'cluster_drop_indexes_cmd.cpp',
        'cluster_enable_sharding_cmd.cpp',
        'cluster_explain_cmd.cpp',
        'cluster_filemd5_cmd.cpp',
        'cluster_find_and_modify_cmd.cpp',
        'cluster_find_cmd_s.cpp',
        'cluster_fle2_cleanup_cmd.cpp',
        'cluster_fle2_compact_cmd.cpp',
        'cluster_fle2_get_count_info_cmd.cpp',
        'cluster_fsync_cmd.cpp',
        'cluster_fsync_unlock_cmd.cpp',
        'cluster_fsync_unlock_cmd.idl',
        'cluster_ftdc_commands.cpp',
        'cluster_get_cluster_parameter_cmd.cpp',
        'cluster_get_database_version_cmd.cpp',
        'cluster_get_shard_version_cmd.cpp',
        'cluster_getmore_cmd_s.cpp',
        'cluster_hello_cmd.cpp',
        'cluster_index_filter_cmd.cpp',
        'cluster_is_db_grid_cmd.cpp',
        'cluster_kill_op.cpp',
        'cluster_killcursors_cmd.cpp',
        'cluster_killoperations_cmd.cpp',
        'cluster_list_collections_cmd.cpp',
        'cluster_list_databases_cmd.cpp',
        'cluster_list_indexes_cmd.cpp',
        'cluster_lock_info_cmd.cpp',
        'cluster_map_reduce_agg.cpp',
        'cluster_map_reduce_cmd.cpp',
        'cluster_move_collection_cmd.cpp',
        'cluster_multicast_cmd.cpp',
        'cluster_netstat_cmd.cpp',
        'cluster_oplog_note_cmd.cpp',
        'cluster_pipeline_cmd_s.cpp',
        'cluster_plan_cache_clear_cmd.cpp',
        'cluster_profile_cmd.cpp',
        'cluster_query_without_shard_key_cmd.cpp',
        'cluster_refine_collection_shard_key_cmd.cpp',
        'cluster_rename_collection_cmd.cpp',
        'cluster_repair_sharded_collection_chunks_history_cmd.cpp',
        'cluster_repl_set_get_status_cmd.cpp',
        'cluster_reset_placement_history_cmd.cpp',
        'cluster_reshard_collection_cmd.cpp',
        'cluster_rwc_defaults_commands.cpp',
        'cluster_set_allow_migrations_cmd.cpp',
        'cluster_set_cluster_parameter_cmd.cpp',
        'cluster_set_feature_compatibility_version_cmd.cpp',
        'cluster_set_index_commit_quorum_cmd.cpp',
        'cluster_set_user_write_block_mode_command.cpp',
        'cluster_shard_collection_cmd.cpp',
        'cluster_shutdown_cmd.cpp',
        'cluster_transition_from_dedicated_config_server_cmd.cpp',
        'cluster_transition_to_dedicated_config_server_cmd.cpp',
        'cluster_unshard_collection_cmd.cpp',
        'cluster_untrack_unsplittable_collection.cpp',
        'cluster_validate_cmd.cpp',
        'cluster_validate_db_metadata_cmd.cpp',
        'cluster_whats_my_uri_cmd.cpp',
        'cluster_write_cmd_s.cpp',
        'cluster_write_without_shard_key_cmd.cpp',
        'internal_transactions_test_command_s.cpp',
        'refine_collection_shard_key.idl',
        's_read_write_concern_defaults_server_status.cpp',
        'shard_collection.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/api_parameters',
        '$BUILD_DIR/mongo/db/auth/auth_checks',
        '$BUILD_DIR/mongo/db/catalog/collection_uuid_mismatch_info',
        '$BUILD_DIR/mongo/db/change_stream_options_manager',
        '$BUILD_DIR/mongo/db/coll_mod_command_idl',
        '$BUILD_DIR/mongo/db/commands/bulk_write_common',
        '$BUILD_DIR/mongo/db/commands/bulk_write_parser',
        '$BUILD_DIR/mongo/db/commands/cluster_server_parameter_cmds_idl',
        '$BUILD_DIR/mongo/db/commands/cluster_server_parameter_commands_invocation',
        '$BUILD_DIR/mongo/db/commands/core',
        '$BUILD_DIR/mongo/db/commands/create_command',
        '$BUILD_DIR/mongo/db/commands/current_op_common',
        '$BUILD_DIR/mongo/db/commands/kill_common',
        '$BUILD_DIR/mongo/db/commands/list_databases_command',
        '$BUILD_DIR/mongo/db/commands/lock_info_command',
        '$BUILD_DIR/mongo/db/commands/map_reduce_parser',
        '$BUILD_DIR/mongo/db/commands/profile_common',
        '$BUILD_DIR/mongo/db/commands/rename_collection_idl',
        '$BUILD_DIR/mongo/db/commands/rwc_defaults_commands',
        '$BUILD_DIR/mongo/db/commands/search_index_commands',
        '$BUILD_DIR/mongo/db/commands/servers',
        '$BUILD_DIR/mongo/db/commands/set_cluster_parameter_impl',
        '$BUILD_DIR/mongo/db/commands/set_feature_compatibility_version_idl',
        '$BUILD_DIR/mongo/db/commands/set_index_commit_quorum_idl',
        '$BUILD_DIR/mongo/db/commands/set_user_write_block_mode_idl',
        '$BUILD_DIR/mongo/db/commands/shutdown_idl',
        '$BUILD_DIR/mongo/db/commands/test_commands_enabled',
        '$BUILD_DIR/mongo/db/commands/validate_db_metadata_command',
        '$BUILD_DIR/mongo/db/dbcommands_idl',
        '$BUILD_DIR/mongo/db/fle_crud',
        '$BUILD_DIR/mongo/db/ftdc/ftdc_server',
        '$BUILD_DIR/mongo/db/index_commands_idl',
        '$BUILD_DIR/mongo/db/internal_transactions_feature_flag',
        '$BUILD_DIR/mongo/db/matcher/expressions_mongod_only',
        '$BUILD_DIR/mongo/db/ops/parsed_update',
        '$BUILD_DIR/mongo/db/query/command_request_response',
        '$BUILD_DIR/mongo/db/query/cursor_response_idl',
        '$BUILD_DIR/mongo/db/query/map_reduce_output_format',
        '$BUILD_DIR/mongo/db/query/query_settings/utils',
        '$BUILD_DIR/mongo/db/query/query_shape/query_shape',
        '$BUILD_DIR/mongo/db/query/search/search_index_process_router',
        '$BUILD_DIR/mongo/db/read_write_concern_defaults',
        '$BUILD_DIR/mongo/db/repl/hello_auth',
        '$BUILD_DIR/mongo/db/repl/hello_command',
        '$BUILD_DIR/mongo/db/repl/repl_server_parameters',
        '$BUILD_DIR/mongo/db/server_base',
        '$BUILD_DIR/mongo/db/server_feature_flags',
        '$BUILD_DIR/mongo/db/shard_role',
        '$BUILD_DIR/mongo/db/shared_request_handling',
        '$BUILD_DIR/mongo/db/stats/api_version_metrics',
        '$BUILD_DIR/mongo/db/stats/counters',
        '$BUILD_DIR/mongo/db/timeseries/timeseries_conversion_util',
        '$BUILD_DIR/mongo/db/timeseries/timeseries_options',
        '$BUILD_DIR/mongo/db/transaction/transaction_api',
        '$BUILD_DIR/mongo/db/validate_api_parameters',
        '$BUILD_DIR/mongo/db/views/views',
        '$BUILD_DIR/mongo/executor/async_multicaster',
        '$BUILD_DIR/mongo/executor/async_request_executor',
        '$BUILD_DIR/mongo/executor/inline_executor',
        '$BUILD_DIR/mongo/idl/cluster_server_parameter_refresher',
        '$BUILD_DIR/mongo/rpc/rewrite_state_change_errors',
        '$BUILD_DIR/mongo/s/grid',
        '$BUILD_DIR/mongo/s/load_balancer_support',
        '$BUILD_DIR/mongo/s/mongos_topology_coordinator',
        '$BUILD_DIR/mongo/s/query/cluster_aggregate',
        '$BUILD_DIR/mongo/s/query/cluster_query',
        '$BUILD_DIR/mongo/s/sharding_api',
        '$BUILD_DIR/mongo/transport/message_compressor',
        '$BUILD_DIR/mongo/transport/transport_layer_common',
        'cluster_commands_common',
    ],
)

env.Library(
    target='cluster_commands_common',
    source=[
        'cluster_explain.cpp',
        'cluster_write_cmd.cpp',
        'document_shard_key_update_util.cpp',
        'strategy.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/commands/core',
        '$BUILD_DIR/mongo/db/default_max_time_ms_cluster_parameter',
        '$BUILD_DIR/mongo/db/fle_crud',
        '$BUILD_DIR/mongo/db/internal_transactions_feature_flag',
        '$BUILD_DIR/mongo/db/operation_time_tracker',
        '$BUILD_DIR/mongo/db/read_write_concern_defaults',
        '$BUILD_DIR/mongo/db/repl/repl_server_parameters',
        '$BUILD_DIR/mongo/db/service_request_common',
        '$BUILD_DIR/mongo/db/shared_request_handling',
        '$BUILD_DIR/mongo/db/stats/api_version_metrics',
        '$BUILD_DIR/mongo/db/stats/counters',
        '$BUILD_DIR/mongo/db/transaction/transaction_api',
        '$BUILD_DIR/mongo/db/validate_api_parameters',
        '$BUILD_DIR/mongo/executor/inline_executor',
        '$BUILD_DIR/mongo/rpc/metadata',
        '$BUILD_DIR/mongo/rpc/rewrite_state_change_errors',
        '$BUILD_DIR/mongo/s/load_balancer_support',
        '$BUILD_DIR/mongo/s/mongos_topology_coordinator',
        '$BUILD_DIR/mongo/s/query/cluster_aggregate',
        '$BUILD_DIR/mongo/s/sharding_api',
        '$BUILD_DIR/mongo/transport/message_compressor',
        '$BUILD_DIR/mongo/transport/service_executor',
        '$BUILD_DIR/mongo/transport/transport_layer_common',
    ],
)

# These commands are registered with the router role only.
# This library is currently also linked into mongoqd, but contains
# commands that should not be used in serverless mode.
env.Library(
    target='sharded_cluster_commands',
    source=[
        'cluster_add_shard_cmd.cpp',
        'cluster_add_shard_to_zone_cmd.cpp',
        'cluster_analyze_shard_key_cmd.cpp',
        'cluster_balancer_collection_status_cmd.cpp',
        'cluster_change_primary_cmd.cpp',
        'cluster_check_metadata_consistency_cmd.cpp',
        'cluster_clear_jumbo_flag_cmd.cpp',
        'cluster_configure_collection_balancing.cpp',
        'cluster_configure_query_analyzer_cmd.cpp',
        'cluster_control_balancer_cmd.cpp',
        'cluster_create_unsplittable_collections_command.cpp',
        'cluster_list_shards_cmd.cpp',
        'cluster_merge_all_chunks_on_shard_cmd.cpp',
        'cluster_merge_chunks_cmd.cpp',
        'cluster_move_chunk_cmd.cpp',
        'cluster_move_range_cmd.cpp',
        'cluster_move_primary_cmd.cpp',
        'cluster_remove_shard_cmd.cpp',
        'cluster_remove_shard_from_zone_cmd.cpp',
        'cluster_split_cmd.cpp',
        'cluster_split_vector_cmd.cpp',
        'cluster_update_zone_key_range_cmd.cpp',
        'cluster_user_management_commands.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/audit',
        '$BUILD_DIR/mongo/db/auth/address_restriction',
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/auth/auth_checks',
        '$BUILD_DIR/mongo/db/auth/builtin_roles',
        '$BUILD_DIR/mongo/db/auth/saslauth',
        '$BUILD_DIR/mongo/db/commands',
        '$BUILD_DIR/mongo/db/commands/servers',
        '$BUILD_DIR/mongo/db/metadata_consistency_types_idl',
        '$BUILD_DIR/mongo/db/server_base',
        '$BUILD_DIR/mongo/rpc/client_metadata',
        '$BUILD_DIR/mongo/rpc/rewrite_state_change_errors',
        '$BUILD_DIR/mongo/s/analyze_shard_key_common',
        '$BUILD_DIR/mongo/s/grid',
        '$BUILD_DIR/mongo/s/mongos_topology_coordinator',
        '$BUILD_DIR/mongo/s/sharding_api',
        '$BUILD_DIR/mongo/transport/transport_layer_common',
        'cluster_commands',
        'cluster_commands_common',
    ],
)

env.CppUnitTest(
    target='s_commands_test',
    source=[
        'cluster_aggregate_test.cpp',
        'cluster_bulk_write_test.cpp',
        'cluster_command_test_fixture.cpp',
        'cluster_delete_test.cpp',
        'cluster_distinct_test.cpp',
        'cluster_explain_test.cpp',
        'cluster_find_and_modify_test.cpp',
        'cluster_find_test.cpp',
        'cluster_insert_test.cpp',
        'cluster_update_test.cpp',
        'cluster_validate_db_metadata_cmd_test.cpp',
        'document_shard_key_update_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/auth/authmocks',
        '$BUILD_DIR/mongo/db/auth/saslauth',
        '$BUILD_DIR/mongo/db/pipeline/process_interface/mongos_process_interface_factory',
        '$BUILD_DIR/mongo/db/read_write_concern_defaults_mock',
        '$BUILD_DIR/mongo/db/service_context_non_d',
        '$BUILD_DIR/mongo/db/vector_clock',
        '$BUILD_DIR/mongo/s/query/cluster_aggregate',
        '$BUILD_DIR/mongo/s/sharding_mongos_test_fixture',
        '$BUILD_DIR/mongo/transport/service_executor',
        'cluster_commands',
        'cluster_commands_common',
    ],
)
