// Copyright 2024 Google Inc. All rights reserved.
//
// 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 {
    default_applicable_licenses: ["Android-Apache-2.0"],
    default_team: "trendy_team_android_media_reliability",
}

genrule {
    name: "applied_backported_fixes",
    tools: ["applied_backported_fixes_main"],
    srcs: [":applied_backported_fix_binpbs"],
    out: ["applied_backported_fixes.prop"],
    cmd: "$(location applied_backported_fixes_main)" +
        " -p $(location applied_backported_fixes.prop)" +
        " $(in)",
}

java_library {
    name: "backported_fixes_proto",
    srcs: [
        "backported_fixes.proto",
    ],
    host_supported: true,
}

java_library {
    name: "backported_fixes_common",
    srcs: ["src/java/com/android/build/backportedfixes/common/*.java"],
    static_libs: [
        "backported_fixes_proto",
        "guava",
    ],
    host_supported: true,
}

java_test_host {
    name: "backported_fixes_common_test",
    srcs: ["tests/java/com/android/build/backportedfixes/common/*.java"],
    static_libs: [
        "backported_fixes_common",
        "backported_fixes_proto",
        "junit",
        "truth",
        "truth-liteproto-extension",
        "truth-proto-extension",
    ],
    test_options: {
        unit_test: true,
    },
    test_suites: ["general-tests"],
}

java_library {
    name: "applied_backported_fixes_lib",
    srcs: ["src/java/com/android/build/backportedfixes/*.java"],
    static_libs: [
        "backported_fixes_common",
        "backported_fixes_proto",
        "jcommander",
        "guava",
    ],
    host_supported: true,
}

java_binary_host {
    name: "applied_backported_fixes_main",
    main_class: "com.android.build.backportedfixes.Main",
    static_libs: [
        "applied_backported_fixes_lib",
    ],
}

java_test_host {
    name: "applied_backported_fixes_test",
    srcs: ["tests/java/com/android/build/backportedfixes/*.java"],
    static_libs: [
        "applied_backported_fixes_lib",
        "backported_fixes_proto",
        "junit",
        "truth",
    ],
    test_options: {
        unit_test: true,
    },
    test_suites: ["general-tests"],
}

gensrcs {
    name: "applied_backported_fix_binpbs",
    tools: ["aprotoc"],
    srcs: [
        "applied_fixes/*.txtpb",
    ],
    tool_files: [
        "backported_fixes.proto",
    ],
    output_extension: "binpb",
    cmd: "$(location aprotoc)  " +
        " --encode=com.android.build.backportedfixes.BackportedFix" +
        "  $(location backported_fixes.proto)" +
        " < $(in)" +
        " > $(out); echo $(out)",
}
