//
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

cc_defaults {
    name: "aidl_defaults",
    cflags: [
        "-Wall",
        "-Werror",
        "-Wextra",
    ],
    whole_static_libs: ["libgtest_prod"],
    static_libs: [
        "libbase",
        "libcutils",
    ],
    target: {
        windows: {
            enabled: true,
        },
    },
}

// Logic shared between aidl and its unittests
cc_library_host_static {
    name: "libaidl-common",
    defaults: ["aidl_defaults"],

    clang_cflags: [
        // Tragically, the code is riddled with unused parameters.
        "-Wno-unused-parameter",

        // yacc dumps a lot of code *just in case*.
        "-Wno-unused-function",
        "-Wno-unneeded-internal-declaration",

        // yacc is a tool from a more civilized age.
        "-Wno-deprecated-register",

        // yacc also has a habit of using char* over const char*.
        "-Wno-writable-strings",
    ],

    srcs: [
        "aidl.cpp",
        "aidl_language.cpp",
        "aidl_language_l.ll",
        "aidl_language_y.yy",
        "ast_cpp.cpp",
        "ast_java.cpp",
        "code_writer.cpp",
        "generate_cpp.cpp",
        "generate_java.cpp",
        "generate_java_binder.cpp",
        "import_resolver.cpp",
        "line_reader.cpp",
        "io_delegate.cpp",
        "options.cpp",
        "type_cpp.cpp",
        "type_java.cpp",
        "type_namespace.cpp",
    ],
}

// aidl executable
cc_binary_host {
    name: "aidl",
    defaults: ["aidl_defaults"],
    srcs: ["main_java.cpp"],
    static_libs: [
        "libaidl-common",
        "libbase",
    ],
}

// aidl-cpp executable
cc_binary_host {
    name: "aidl-cpp",
    defaults: ["aidl_defaults"],
    srcs: ["main_cpp.cpp"],
    static_libs: [
        "libaidl-common",
        "libbase",
    ],
}

// Unit tests
cc_test_host {
    name: "aidl_unittests",

    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-g",
        "-DUNIT_TEST",
    ],
    // Tragically, the code is riddled with unused parameters.
    clang_cflags: ["-Wno-unused-parameter"],
    srcs: [
        "aidl_unittest.cpp",
        "ast_cpp_unittest.cpp",
        "ast_java_unittest.cpp",
        "generate_cpp_unittest.cpp",
        "io_delegate_unittest.cpp",
        "options_unittest.cpp",
        "tests/end_to_end_tests.cpp",
        "tests/fake_io_delegate.cpp",
        "tests/main.cpp",
        "tests/test_data_example_interface.cpp",
        "tests/test_data_ping_responder.cpp",
        "tests/test_data_string_constants.cpp",
        "tests/test_util.cpp",
        "type_cpp_unittest.cpp",
        "type_java_unittest.cpp",
    ],

    static_libs: [
        "libaidl-common",
        "libbase",
        "libcutils",
        "libgmock_host",
    ],
}

//
// Everything below here is used for integration testing of generated AIDL code.
//
cc_binary {
    name: "aidl_test_sentinel_searcher",
    srcs: ["tests/aidl_test_sentinel_searcher.cpp"],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-Wunused-parameter",
    ],
}

cc_defaults {
    name: "aidl_test_defaults",
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-Wunused-parameter",
    ],
    shared_libs: [
        "libbase",
        "libbinder",
        "liblog",
        "libutils",
    ],
}

cc_library_shared {
    name: "libaidl-integration-test",
    defaults: ["aidl_test_defaults"],
    aidl: {
        export_aidl_headers: true,
        local_include_dirs: ["tests"],
        include_dirs: ["frameworks/native/aidl/binder"],
    },
    srcs: [
        "tests/android/aidl/tests/ITestService.aidl",
        "tests/android/aidl/tests/INamedCallback.aidl",
        "tests/simple_parcelable.cpp",
    ],
}

cc_binary {
    name: "aidl_test_service",
    defaults: ["aidl_test_defaults"],
    shared_libs: ["libaidl-integration-test"],
    srcs: ["tests/aidl_test_service.cpp"],
}

cc_binary {
    name: "aidl_test_client",
    defaults: ["aidl_test_defaults"],
    shared_libs: ["libaidl-integration-test"],
    srcs: [
        "tests/aidl_test_client.cpp",
        "tests/aidl_test_client_file_descriptors.cpp",
        "tests/aidl_test_client_parcelables.cpp",
        "tests/aidl_test_client_nullables.cpp",
        "tests/aidl_test_client_primitives.cpp",
        "tests/aidl_test_client_utf8_strings.cpp",
        "tests/aidl_test_client_service_exceptions.cpp",
    ],
}