// Copyright (C) 2020 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.

package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "art_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["art_license"],
}

soong_config_module_type_import {
    from: "art/build/SoongConfig.bp",
    module_types: [
        "art_module_sdk",
        "art_module_exports",
    ],
}

// Additional visibility to add to the prebuilt modules that are part of
// the snapshots of the ART sdk/module_exports to ensure that they are
// visible to each other.
prebuilt_visibility = [
    // TODO(b/155921753): Restrict this when prebuilts are in their proper
    // locations.
    "//prebuilts:__subpackages__",
]

// The SDK for the art module apex.
art_module_sdk {
    name: "art-module-sdk",
    host_supported: true,

    // Enable if SOONG_CONFIG_art_module_source_build is true.
    enabled: false,
    soong_config_variables: {
        source_build: {
            enabled: true,
        },
    },

    prebuilt_visibility: prebuilt_visibility,

    target: {
        // Both android and host linux but not windows or darwin.
        linux: {
            native_header_libs: [
                "jni_headers",
                "libartpalette-headers",
                "libnativehelper_header_only",
                "libopenjdkjvmti_headers",
            ],

            native_shared_libs: [
                "libandroidio",
                "libdexfile",
                "libnativebridge",
                "libnativehelper",
                "libnativeloader",
                "libsigchain",
            ],

            native_static_libs: [
                "libdexfile_support",
                "libdexfile_static",
                "libnativehelper_lazy",
            ],
        },

        android: {
            bootclasspath_fragments: [
                // Adds the fragment and its contents to the sdk.
                "art-bootclasspath-fragment",
            ],

            compat_configs: [
                "libcore-platform-compat-config",
            ],

            java_header_libs: [
                // Needed by any module that builds against any non-numeric
                // sdk_version other than "none".
                //
                // This is actually only used for compiling Java 8 and kotlin.
                // Java 9 uses system modules which encapsulates this
                // internally.
                "core-lambda-stubs",

                // Needed by any module that builds against any non-numeric
                // sdk_version other than "none" or "core_platform".
                //
                // This is actually only used for compiling Java 8 and kotlin.
                // Java 9 uses system modules which encapsulates this
                // internally.
                "core.current.stubs",

                // Needed by any module that builds against an sdk_version of
                // "core_platform".
                //
                // This is actually only used for compiling Java 8 and kotlin.
                // Java 9 uses system modules which encapsulates this
                // internally.
                "legacy.core.platform.api.stubs",
                "stable.core.platform.api.stubs",
            ],

            java_sdk_libs: [
                "art.module.public.api",
            ],

            java_system_modules: [
                "art-module-public-api-stubs-system-modules",
                "art-module-intra-core-api-stubs-system-modules",
                "legacy-art-module-platform-api-stubs-system-modules",
                "stable-art-module-platform-api-stubs-system-modules",
                "core-current-stubs-system-modules",
                "legacy-core-platform-api-stubs-system-modules",
                "stable-core-platform-api-stubs-system-modules",
            ],
            native_header_libs: [
                "libnativeloader-headers",
            ],
            native_shared_libs: [
                "libnativebridge_lazy",
                "libnativehelper_compat_libc++",
                "libnativeloader_lazy",
            ],
        },

        linux_bionic: {
            enabled: false,
        },
        darwin: {
            enabled: false,
        },
    },
}

// Exported host tools and libraries.
art_module_exports {
    name: "art-module-host-exports",
    host_supported: true,

    // Enable if SOONG_CONFIG_art_module_source_build is true.
    enabled: false,
    soong_config_variables: {
        source_build: {
            enabled: true,
        },
    },

    prebuilt_visibility: prebuilt_visibility,

    target: {
        host: {
            // Set in target.host because the top level compile_multilib
            // property is fixed to "both" in the sdk/module_exports
            // implementation and cannot be overridden any other way.
            compile_multilib: "64",

            java_libs: [
                "art.module.api.annotations",

                // Needed for grpc-grpc-java
                "okhttp-norepackage",
            ],
            native_binaries: [
                "dex2oat",
                "dex2oatd",
                "dexdump",
                "hiddenapi",
                "oatdump",
                "profman",
                "veridex",
            ],
            native_libs: [
                "libartpalette", // libdexfile dependency
                "libartbase", // libdexfile dependency
            ],
        },

        linux_bionic: {
            enabled: false,
        },
        darwin: {
            enabled: false,
        },
        windows: {
            enabled: false,
        },
    },
}

// Exported tests and supporting libraries
art_module_exports {
    name: "art-module-test-exports",

    // Enable if SOONG_CONFIG_art_module_source_build is true.
    enabled: false,
    soong_config_variables: {
        source_build: {
            enabled: true,
        },
    },

    prebuilt_visibility: prebuilt_visibility,

    java_libs: [
        "core-compat-test-rules",
        "core-test-rules",
        "core-tests-support",
        "okhttp-tests-nojarjar",

        // Needed for CtsJvmtiDeviceRunTestAppBase.
        "art_cts_jvmti_test_library",
        "expected_cts_outputs",

        // Needed for robolectric.
        "core-libart-for-host",
        "okhttp-for-host",

        // Needed for CtsLibcore...TestCases
        "libcore-expectations-knownfailures-jar",
        "libcore-expectations-virtualdeviceknownfailures-jar",

        // Needed for CtsLibcoreOkHttpTestCases
        "okhttp-nojarjar",
    ],

    java_tests: [
        // Needed for CtsJdwpTestCases.
        "apache-harmony-jdwp-tests",

        "libcore-crypto-tests",

        // Needed for CtsLibcoreOjTestCases
        "core-ojtests-public",

        // Needed for CtsLibcoreJsr166TestCases
        "jsr166-tests",

        // Needed for CtsLibcoreTestCases
        "apache-harmony-tests",
        "core-tests",
    ],

    native_shared_libs: [
        "libjavacoretests",
    ],
    native_static_libs: [
        // TODO(b/187288515): Providing this as a prebuilt introduces an issue
        // with sdk_version propagation. Temporarily use the source library
        // instead.
        //"libctstiagent",
    ],
}
