diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApkInfo.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApkInfo.java index cdf53ddd058ec0..81f572944388fd 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ApkInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApkInfo.java @@ -13,6 +13,8 @@ // limitations under the License. package com.google.devtools.build.lib.rules.android; +import static com.google.devtools.build.lib.rules.android.AndroidStarlarkData.fromNoneable; + import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; @@ -21,9 +23,8 @@ import com.google.devtools.build.lib.starlarkbuildapi.android.ApkInfoApi; import java.util.List; import javax.annotation.Nullable; -import net.starlark.java.eval.Dict; import net.starlark.java.eval.EvalException; -import net.starlark.java.eval.Starlark; +import net.starlark.java.eval.Sequence; /** A provider for targets that produce an apk file. */ @Immutable @@ -123,15 +124,32 @@ public String getSigningMinV3RotationApiVersion() { /** Provider for {@link ApkInfo}. */ public static class ApkInfoProvider extends BuiltinProvider - implements ApkInfoApiProvider { + implements ApkInfoApiProvider { private ApkInfoProvider() { super(STARLARK_NAME, ApkInfo.class); } @Override - public ApkInfoApi createInfo(Dict kwargs) throws EvalException { - throw Starlark.errorf("'%s' cannot be constructed from Starlark", getPrintableName()); + public ApkInfoApi createInfo( + Artifact apk, + Artifact unsignedApk, + Artifact deployJar, + Object coverageMetadata, + Artifact mergedManifest, + Sequence signingKeys, + Object signingLineage, + Object signingMinV3RotationApiVersion) + throws EvalException { + return new ApkInfo( + apk, + unsignedApk, + deployJar, + fromNoneable(coverageMetadata, Artifact.class), + mergedManifest, + Sequence.cast(signingKeys, Artifact.class, "signing_keys"), + fromNoneable(signingLineage, Artifact.class), + fromNoneable(signingMinV3RotationApiVersion, String.class)); } } } diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/AndroidBootstrap.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/AndroidBootstrap.java index cf54b73428bc4a..2b7052ee3f8649 100644 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/AndroidBootstrap.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/AndroidBootstrap.java @@ -43,7 +43,7 @@ public class AndroidBootstrap implements Bootstrap { public AndroidBootstrap( AndroidStarlarkCommonApi androidCommon, - ApkInfoApiProvider apkInfoProvider, + ApkInfoApiProvider apkInfoProvider, AndroidInstrumentationInfoApiProvider androidInstrumentationInfoProvider, AndroidDeviceBrokerInfoApiProvider androidDeviceBrokerInfoProvider, AndroidResourcesInfoApiProvider androidResourcesInfoProvider, diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/ApkInfoApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/ApkInfoApi.java index 644a5df1bd5f8d..15dec6b9def70c 100644 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/ApkInfoApi.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/ApkInfoApi.java @@ -15,15 +15,18 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.build.docgen.annot.DocCategory; +import com.google.devtools.build.docgen.annot.StarlarkConstructor; import com.google.devtools.build.lib.starlarkbuildapi.FileApi; import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi; import com.google.devtools.build.lib.starlarkbuildapi.core.StructApi; import javax.annotation.Nullable; import net.starlark.java.annot.Param; +import net.starlark.java.annot.ParamType; import net.starlark.java.annot.StarlarkBuiltin; import net.starlark.java.annot.StarlarkMethod; -import net.starlark.java.eval.Dict; import net.starlark.java.eval.EvalException; +import net.starlark.java.eval.NoneType; +import net.starlark.java.eval.Sequence; /** A provider for targets that produce an apk file. */ @StarlarkBuiltin( @@ -120,15 +123,73 @@ public interface ApkInfoApi extends StructApi { "Do not use this module. It is intended for migration purposes only. If you depend on " + "it, you will be broken when it is removed.", documented = false) - interface ApkInfoApiProvider extends ProviderApi { + interface ApkInfoApiProvider extends ProviderApi { @StarlarkMethod( name = "ApkInfo", - // This is left undocumented as it throws a "not-implemented in Starlark" error when - // invoked. + doc = "The ApkInfo constructor.", documented = false, - extraKeywords = @Param(name = "kwargs"), + parameters = { + @Param( + name = "signed_apk", + doc = "The signed APK file.", + allowedTypes = { + @ParamType(type = FileApi.class), + }, + named = true), + @Param( + name = "unsigned_apk", + doc = "The unsigned APK file.", + allowedTypes = { + @ParamType(type = FileApi.class), + }, + named = true), + @Param( + name = "deploy_jar", + doc = "The deploy jar file.", + allowedTypes = { + @ParamType(type = FileApi.class), + }, + named = true), + @Param( + name = "coverage_metadata", + doc = "The coverage metadata file generated in the transitive closure.", + allowedTypes = {@ParamType(type = FileApi.class), @ParamType(type = NoneType.class)}, + named = true), + @Param( + name = "merged_manifest", + doc = "The merged manifest file.", + allowedTypes = { + @ParamType(type = FileApi.class), + }, + named = true), + @Param( + name = "signing_keys", + doc = "The list of signing keys used to sign the APK.", + allowedTypes = {@ParamType(type = Sequence.class, generic1 = FileApi.class)}, + named = true), + @Param( + name = "signing_lineage", + doc = "The signing lineage file. If present, that was used to sign the APK", + allowedTypes = {@ParamType(type = FileApi.class), @ParamType(type = NoneType.class)}, + named = true), + @Param( + name = "signing_min_v3_rotation_api_version", + doc = "The minimum API version for signing the APK with key rotation.", + allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)}, + named = true), + }, selfCall = true) - ApkInfoApi createInfo(Dict kwargs) throws EvalException; + @StarlarkConstructor + ApkInfoApi createInfo( + FileT signedApk, + FileT unsignedApk, + FileT deployJar, + Object coverageMetadata, + FileT mergedManifest, + Sequence signingKeys, // expected + Object signingLineage, + Object signingMinV3RotationApiVersion) + throws EvalException; } }