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

Commit 54edd1c5 authored by Jared Duke's avatar Jared Duke
Browse files

Use output file arg for systemfeatures-lookup-gen tool

Prefer using an explicit output file as the target for generated code,
rather than piping from stdout. This avoids issues with spurious JDK
stdout logs leaking into the generated source file.

Bug: 421912364
Test: atest systemfeatures-gen-tests
Flag: EXEMPT trivial tooling bug fix
Change-Id: Ic70caf6fd123e77458c0ba27889617129378e309
parent c09fcab1
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)
        }
    }

    /**