Skip to content

Commit

Permalink
Generate Constants.java based on constants from the build graph
Browse files Browse the repository at this point in the history
This will eliminate another source of build config vs tool implementation inconsistency.

This change also bumps up Constants.MIN_API_LEVEL from 19 to 21.

PiperOrigin-RevId: 723511855
Change-Id: Ic1d9087199131fc37fef24027db7d165b641170f
  • Loading branch information
ted-xie authored and copybara-github committed Feb 5, 2025
1 parent b2efded commit c9de3dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
24 changes: 24 additions & 0 deletions src/tools/java/com/google/devtools/build/android/r8/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Collection of dex utilities used in the bazel android actions.

load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("//rules:min_sdk_version.bzl", "min_sdk_version")

filegroup(
name = "srcs",
Expand Down Expand Up @@ -30,6 +31,7 @@ java_library(
"//src/tools/java/com/google/devtools/build/android/desugar/dependencies",
],
deps = [
":constants",
"//src/tools/java/com/google/devtools/build/android:android_options_utils",
"//tools/android:autovalue",
"@bazel_worker_java//src/main/java/com/google/devtools/build/lib/worker:work_request_handlers",
Expand Down Expand Up @@ -128,3 +130,25 @@ java_binary(
":r8",
],
)

java_library(
name = "constants",
srcs = [":Constants_java"],
visibility = [":__pkg__"],
)

genrule(
name = "Constants_java",
outs = ["Constants.java"],
cmd = """
cat > $@ << EOF
package com.google.devtools.build.android.r8;
/** Constants shared by desugaring and dexing. */
public class Constants {
public static final String MIN_API_LEVEL = "%s";
private Constants() {}
}
EOF
""" % str(min_sdk_version.DEPOT_FLOOR),
visibility = [":__pkg__"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static class Options {
@Parameter(
names = "--min-sdk-version",
description = "Minimum Android API level compatibility.")
public int minApiLevel = 19; // Same as Constants.MIN_API_LEVEL.
public int minApiLevel = Integer.parseInt(Constants.MIN_API_LEVEL);

@Parameter(names = "--input-list", description = "File listing input files.")
public String inputList;
Expand Down
21 changes: 0 additions & 21 deletions src/tools/java/com/google/devtools/build/android/r8/Constants.java

This file was deleted.

0 comments on commit c9de3dc

Please sign in to comment.