Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.1.0] Expose the ApkInfo provider constructor to Starlark. #21588

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -43,7 +43,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;
}
}
Loading