Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc22418a authored by Jared Duke's avatar Jared Duke Committed by Android (Google) Code Review
Browse files

Merge "Use output file arg for systemfeatures-lookup-gen tool" into main

parents e0c3296a 54edd1c5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ java_binary_host {

genrule {
    name: "systemfeatures-lookup-srcs",
    cmd: "$(location systemfeatures-lookup-gen-tool) $(in) > $(out)",
    cmd: "$(location systemfeatures-lookup-gen-tool) $(in) $(out)",
    out: ["SystemFeaturesLookup.java"],
    srcs: [
        ":non-updatable-current.txt",
+24 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.squareup.javapoet.MethodSpec
import com.squareup.javapoet.TypeSpec
import java.io.File
import javax.lang.model.element.Modifier
import kotlin.system.exitProcess

/*
 * Simple Java code generator that takes as input a list of Metalava API files and generates an
@@ -31,6 +32,9 @@ import javax.lang.model.element.Modifier
 * declared PackageManager variable names. This is needed for host tooling that cannot depend
 * directly on the base framework lib/srcs.
 *
 * The main function expects arguments in the format:
 * <input_api_files...> <output_java_file>
 *
 * <pre>
 * package com.android.systemfeatures;
 * public final class SystemFeaturesLookup {
@@ -42,10 +46,29 @@ import javax.lang.model.element.Modifier
 */
object SystemFeaturesLookupGenerator {

    private fun usage() {
        println("Usage: SystemFeaturesLookupGenerator <input_api_files...> <output_java_file>")
    }

    /** Main entrypoint for system feature constant lookup codegen. */
    @JvmStatic
    fun main(args: Array<String>) {
        generate(args.asIterable(), System.out)
        if (args.size < 2) {
            usage()
            exitProcess(1)
        }

        val outputFilePath = args.last()
        val apiFilePaths = args.dropLast(1)

        runCatching {
            File(outputFilePath).bufferedWriter().use { writer ->
                generate(apiFilePaths, writer)
            }
        }.onFailure {
            System.err.println("Error writing to output file '$outputFilePath': ${it.message}")
            exitProcess(1)
        }
    }

    /**