package {
    default_applicable_licenses: ["external_fmtlib_license"],
}

// Added automatically by a large-scale-change that took the approach of
// 'apply every license found to every target'. While this makes sure we respect
// every license restriction, it may not be entirely correct.
//
// e.g. GPL in an MIT project might only apply to the contrib/ directory.
//
// Please consider splitting the single license below into multiple licenses,
// taking care not to lose any license_kind information, and overriding the
// default license using the 'licenses: [...]' property on targets as needed.
//
// For unused files, consider creating a 'fileGroup' with "//visibility:private"
// to attach the license to, and including a comment whether the files may be
// used in the current project.
//
// large-scale-change included anything that looked like it might be a license
// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
//
// Please consider removing redundant or irrelevant files from 'license_text:'.
// See: http://go/android-license-faq
license {
    name: "external_fmtlib_license",
    visibility: [":__subpackages__"],
    license_kinds: [
        "SPDX-license-identifier-BSD",
        "SPDX-license-identifier-CC0-1.0",
        "SPDX-license-identifier-MIT",
        "SPDX-license-identifier-PSF-2.0",
        "legacy_unencumbered",
    ],
    license_text: [
        "LICENSE.rst",
        "NOTICE",
    ],
}

cc_defaults {
    name: "fmtlib-non-test-defaults",
    cflags: [
        "-fno-exceptions",
        // If built without exceptions, libfmt uses assert.
        // The tests *require* exceptions, so we can't win here.
        // (This is also why we have two cc_defaults in this file.)
        // Unless proven to be a bad idea, let's at least have some run-time
        // checking.
        "-UNDEBUG",
    ],
    srcs: ["src/format.cc"],
    local_include_dirs: ["include"],
    export_include_dirs: ["include"],
    visibility: ["//system/libbase"],
    min_sdk_version: "29",
}

cc_library_headers {
    name: "fmtlib_headers",
    export_include_dirs: ["include"],

    vendor_available: true,
    product_available: true,
    ramdisk_available: true,
    vendor_ramdisk_available: true,
    recovery_available: true,
    host_supported: true,
    native_bridge_supported: true,
    target: {
        linux_bionic: {
            enabled: true,
        },
        windows: {
            enabled: true,
        },
    },
    visibility: ["//system/libbase"],
    min_sdk_version: "29",
    apex_available: [
        "//apex_available:anyapex",
        "//apex_available:platform",
    ],
}

// This is built into libbase.  If you want to use this library, link to libbase instead.
cc_library_static {
    name: "fmtlib",
    defaults: ["fmtlib-non-test-defaults"],

    vendor_available: true,
    product_available: true,
    ramdisk_available: true,
    vendor_ramdisk_available: true,
    recovery_available: true,
    host_supported: true,
    native_bridge_supported: true,
    target: {
        linux_bionic: {
            enabled: true,
        },
        windows: {
            enabled: true,
        },
    },
    apex_available: [
        "//apex_available:anyapex",
        "//apex_available:platform",
    ],
    min_sdk_version: "29",
}

cc_library_static {
    name: "fmtlib_ndk",
    defaults: ["fmtlib-non-test-defaults"],
    sdk_version: "current",
    stl: "c++_static",
}

cc_defaults {
    name: "fmtlib-test-defaults",
    srcs: [
        "src/format.cc",
        "src/os.cc",
        "test/gtest-extra.cc",
        "test/util.cc",
    ],
    local_include_dirs: ["include"],
    host_supported: true,
    test_suites: ["general-tests"],
    // The tests require exceptions and RTTI.
    cflags: ["-fexceptions"],
    rtti: true,
    // The usual "gtest *and* gmock, please" dance...
    gtest: false,
    include_dirs: [
        "external/googletest/googlemock/include/gmock",
        "external/googletest/googletest/include/gtest",
    ],
    static_libs: [
        "libgmock",
        "libgtest",
        "libgtest_main",
    ],
}

// Most of the fmtlib tests.
cc_test {
    name: "fmtlib_test",
    defaults: ["fmtlib-test-defaults"],
    srcs: [
        "test/chrono-test.cc",
        "test/color-test.cc",
        "test/core-test.cc",
        "test/format-test.cc",
        // Some of the os-test tests deliberately try to do bad things with
        // file descriptors, but Android's fdsan won't let them.
        // "test/os-test.cc",
        "test/printf-test.cc",
        "test/ranges-test.cc",
        "test/scan-test.cc",
    ],
}

// This one needs to be separate because some of the test names overlap with
// other tests.
cc_test {
    name: "fmtlib_ostream_test",
    defaults: ["fmtlib-test-defaults"],
    srcs: ["test/ostream-test.cc"],
}
