package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

rust_defaults {
    name: "aconfig.defaults",
    edition: "2021",
    clippy_lints: "android",
    lints: "android",
    srcs: ["src/main.rs"],
    rustlibs: [
        "libaconfig_protos",
        "libaconfig_storage_file",
        "libanyhow",
        "libclap",
        "libitertools",
        "libprotobuf",
        "libserde",
        "libserde_json",
        "libtinytemplate",
    ],
}

rust_binary_host {
    name: "aconfig",
    defaults: ["aconfig.defaults"],
}

rust_test_host {
    name: "aconfig.test",
    defaults: ["aconfig.defaults"],
    rustlibs: [
        "libitertools",
    ],
    test_suites: ["general-tests"],
}

// integration tests: general

aconfig_declarations {
    name: "aconfig.test.flags",
    package: "com.android.aconfig.test",
    container: "system",
    srcs: ["tests/test.aconfig"],
}

aconfig_declarations {
    name: "aconfig.test.exported.flags",
    package: "com.android.aconfig.test.exported",
    exportable: true,
    container: "system",
    srcs: ["tests/test_exported.aconfig"],
}

aconfig_declarations {
    name: "aconfig.test.forcereadonly.flags",
    package: "com.android.aconfig.test.forcereadonly",
    container: "system",
    srcs: ["tests/test_force_read_only.aconfig"],
}

aconfig_values {
    name: "aconfig.test.flag.values",
    package: "com.android.aconfig.test",
    srcs: [
        "tests/first.values",
        "tests/second.values",
    ],
}

aconfig_value_set {
    name: "aconfig.test.flag.value_set",
    values: [
        "aconfig.test.flag.values",
    ],
}

// integration tests: java

java_aconfig_library {
    name: "aconfig_test_java_library",
    aconfig_declarations: "aconfig.test.flags",
}

java_aconfig_library {
    name: "aconfig_test_java_library_exported",
    aconfig_declarations: "aconfig.test.exported.flags",
    mode: "exported",
}

java_aconfig_library {
    name: "aconfig_test_java_library_forcereadonly",
    aconfig_declarations: "aconfig.test.forcereadonly.flags",
    mode: "force-read-only",
}

android_test {
    name: "aconfig.test.java",
    srcs: [
        "tests/AconfigTest.java",
    ],
    manifest: "tests/AndroidManifest.xml",
    certificate: "platform",
    static_libs: [
        "aconfig_test_java_library",
        "aconfig_test_java_library_exported",
        "aconfig_test_java_library_forcereadonly",
        "androidx.test.rules",
        "testng",
    ],
    test_suites: ["general-tests"],
}

java_aconfig_library {
    name: "aconfig_host_test_java_library",
    aconfig_declarations: "aconfig.test.flags",
    host_supported: true,
    mode: "test",
}

java_test_host {
    name: "AconfigJavaHostTest",
    srcs: [
        "tests/AconfigHostTest.java",
    ],
    static_libs: [
        "aconfig_host_test_java_library",
        "junit",
    ],
    test_suites: ["general-tests"],
}

// integration tests: C++

cc_aconfig_library {
    name: "aconfig_test_cpp_library",
    aconfig_declarations: "aconfig.test.flags",
}

cc_aconfig_library {
    name: "aconfig_test_cpp_library_test_variant",
    aconfig_declarations: "aconfig.test.flags",
    mode: "test",
}

cc_aconfig_library {
    name: "aconfig_test_cpp_library_force_read_only_variant",
    aconfig_declarations: "aconfig.test.flags",
    mode: "force-read-only",
}

cc_test {
    name: "aconfig.test.cpp",
    srcs: [
        "tests/aconfig_test.cpp",
    ],
    static_libs: [
        "aconfig_test_cpp_library",
        "libgmock",
    ],
    shared_libs: [
        "server_configurable_flags",
    ],
    defaults: [
        "aconfig_lib_cc_static_link.defaults",
    ],
    test_suites: ["general-tests"],
}

cc_test {
    name: "aconfig.test.cpp.test_mode",
    srcs: [
        "tests/aconfig_test_test_variant.cpp",
    ],
    static_libs: [
        "aconfig_test_cpp_library_test_variant",
        "libgmock",
    ],
    shared_libs: [
        "server_configurable_flags",
    ],
    defaults: [
        "aconfig_lib_cc_static_link.defaults",
    ],
    test_suites: ["general-tests"],
}

// TODO(327420679): Enable export mode for native flag library
/*
cc_aconfig_library {
    name: "aconfig_test_cpp_library_exported_variant",
    aconfig_declarations: "aconfig.test.flags",
    mode: "exported",
}

cc_test {
    name: "aconfig.test.cpp.exported_mode",
    srcs: [
        "tests/aconfig_exported_mode_test.cpp",
    ],
    static_libs: [
        "aconfig_test_cpp_library_exported_variant",
        "libgmock",
    ],
    shared_libs: [
        "server_configurable_flags",
    ],
    defaults: [
        "aconfig_lib_cc_static_link.defaults",
    ],
    test_suites: ["general-tests"],
}
*/

cc_test {
    name: "aconfig.test.cpp.force_read_only_mode",
    srcs: [
        "tests/aconfig_force_read_only_mode_test.cpp",
    ],
    static_libs: [
        "aconfig_test_cpp_library_force_read_only_variant",
        "libgmock",
    ],
    shared_libs: [
        "server_configurable_flags",
    ],
    defaults: [
        "aconfig_lib_cc_static_link.defaults",
    ],
    test_suites: ["general-tests"],
}

rust_aconfig_library {
    name: "libaconfig_test_rust_library",
    crate_name: "aconfig_test_rust_library",
    aconfig_declarations: "aconfig.test.flags",
}

rust_test {
    name: "aconfig.prod_mode.test.rust",
    srcs: [
        "tests/aconfig_prod_mode_test.rs",
    ],
    rustlibs: [
        "libaconfig_test_rust_library",
    ],
    test_suites: ["general-tests"],
}

rust_aconfig_library {
    name: "libaconfig_test_rust_library_with_test_mode",
    crate_name: "aconfig_test_rust_library",
    aconfig_declarations: "aconfig.test.flags",
    mode: "test",
}

rust_test {
    name: "aconfig.test_mode.test.rust",
    srcs: [
        "tests/aconfig_test_mode_test.rs",
    ],
    rustlibs: [
        "libaconfig_test_rust_library_with_test_mode",
    ],
    test_suites: ["general-tests"],
}

// TODO(327420679): Enable export mode for native flag library
/*
rust_aconfig_library {
    name: "libaconfig_test_rust_library_with_exported_mode",
    crate_name: "aconfig_test_rust_library",
    aconfig_declarations: "aconfig.test.flags",
    mode: "exported",
}

rust_test {
    name: "aconfig.exported_mode.test.rust",
    srcs: [
        "tests/aconfig_exported_mode_test.rs",
    ],
    rustlibs: [
        "libaconfig_test_rust_library_with_exported_mode",
    ],
    test_suites: ["general-tests"],
}
*/

rust_aconfig_library {
    name: "libaconfig_test_rust_library_with_force_read_only_mode",
    crate_name: "aconfig_test_rust_library",
    aconfig_declarations: "aconfig.test.flags",
    mode: "force-read-only",
}

rust_test {
    name: "aconfig.force_read_only_mode.test.rust",
    srcs: [
        "tests/aconfig_force_read_only_mode_test.rs",
    ],
    rustlibs: [
        "libaconfig_test_rust_library_with_force_read_only_mode",
    ],
    test_suites: ["general-tests"],
}
