Skip to content

Commit

Permalink
Expose the ApkInfo provider constructor to Starlark.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 579971552
Change-Id: I8de99d8875ee3cdd6bbd56d4b931377657fa33e2
  • Loading branch information
Zhaoqing Xu authored and copybara-github committed Nov 6, 2023
1 parent a18a6d5 commit 067b0ea
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -123,15 +124,32 @@ public String getSigningMinV3RotationApiVersion() {

/** Provider for {@link ApkInfo}. */
public static class ApkInfoProvider extends BuiltinProvider<ApkInfo>
implements ApkInfoApiProvider {
implements ApkInfoApiProvider<Artifact> {

private ApkInfoProvider() {
super(STARLARK_NAME, ApkInfo.class);
}

@Override
public ApkInfoApi<?> createInfo(Dict<String, Object> kwargs) throws EvalException {
throw Starlark.errorf("'%s' cannot be constructed from Starlark", getPrintableName());
public ApkInfoApi<Artifact> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AndroidBootstrap implements Bootstrap {

public AndroidBootstrap(
AndroidStarlarkCommonApi<?, ?, ?, ?, ?> androidCommon,
ApkInfoApiProvider apkInfoProvider,
ApkInfoApiProvider<?> apkInfoProvider,
AndroidInstrumentationInfoApiProvider<?> androidInstrumentationInfoProvider,
AndroidDeviceBrokerInfoApiProvider androidDeviceBrokerInfoProvider,
AndroidResourcesInfoApiProvider<?, ?, ?> androidResourcesInfoProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -120,15 +123,73 @@ public interface ApkInfoApi<FileT extends FileApi> 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<FileT extends FileApi> extends ProviderApi {

@StarlarkMethod(
name = "ApkInfo",
// This is left undocumented as it throws a "not-implemented in Starlark" error when
// invoked.
doc = "The <code>ApkInfo<code> 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<String, Object> kwargs) throws EvalException;
@StarlarkConstructor
ApkInfoApi<FileT> createInfo(
FileT signedApk,
FileT unsignedApk,
FileT deployJar,
Object coverageMetadata,
FileT mergedManifest,
Sequence<?> signingKeys, // <Artifact> expected
Object signingLineage,
Object signingMinV3RotationApiVersion)
throws EvalException;
}
}

0 comments on commit 067b0ea

Please sign in to comment.