-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.3.0] Add a new provider for passing dex related artifacts in andro…
…id_binary (#18899) * Creates an AndroidDexInfo provider to pass dex related artifacts from Starlark to Native Bazel. PiperOrigin-RevId: 515061110 Change-Id: Ieefe430582c01264fb510de3ac1017d3332f51aa * Enable android_binary to use AndroidDexInfo from its application_resources attribute. android_binary will use the dexes, jar resources, and deploy jar from AndroidDexInfo if it is present. RELNOTES: None. PiperOrigin-RevId: 531000013 Change-Id: I67c3457d131041aa4bab5db0892cdc0f0584f2dc --------- Co-authored-by: Zhaoqing Xu <zhaoqxu@google.com> Co-authored-by: Googler <ahumesky@google.com> Co-authored-by: Ian (Hee) Cha <heec@google.com>
- Loading branch information
1 parent
3c4b936
commit ab35c6f
Showing
6 changed files
with
242 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/com/google/devtools/build/lib/rules/android/AndroidDexInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2023 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// 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.devtools.build.lib.actions.Artifact; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
import com.google.devtools.build.lib.packages.BuiltinProvider; | ||
import com.google.devtools.build.lib.packages.NativeInfo; | ||
import com.google.devtools.build.lib.starlarkbuildapi.android.AndroidDexInfoApi; | ||
import javax.annotation.Nullable; | ||
import net.starlark.java.eval.EvalException; | ||
|
||
/** A provider for Android Dex artifacts */ | ||
@Immutable | ||
public class AndroidDexInfo extends NativeInfo implements AndroidDexInfoApi<Artifact> { | ||
|
||
public static final String PROVIDER_NAME = "AndroidDexInfo"; | ||
public static final Provider PROVIDER = new Provider(); | ||
|
||
private final Artifact deployJar; | ||
private final Artifact finalClassesDexZip; | ||
private final Artifact javaResourceJar; | ||
|
||
public AndroidDexInfo(Artifact deployJar, Artifact finalClassesDexZip, Artifact javaResourceJar) { | ||
this.deployJar = deployJar; | ||
this.finalClassesDexZip = finalClassesDexZip; | ||
this.javaResourceJar = javaResourceJar; | ||
} | ||
|
||
@Override | ||
public Provider getProvider() { | ||
return PROVIDER; | ||
} | ||
|
||
@Override | ||
public Artifact getDeployJar() { | ||
return deployJar; | ||
} | ||
|
||
@Override | ||
public Artifact getFinalClassesDexZip() { | ||
return finalClassesDexZip; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public Artifact getJavaResourceJar() { | ||
return javaResourceJar; | ||
} | ||
|
||
/** Provider for {@link AndroidDexInfo}. */ | ||
public static class Provider extends BuiltinProvider<AndroidDexInfo> | ||
implements AndroidDexInfoApi.Provider<Artifact> { | ||
|
||
private Provider() { | ||
super(PROVIDER_NAME, AndroidDexInfo.class); | ||
} | ||
|
||
public String getName() { | ||
return PROVIDER_NAME; | ||
} | ||
|
||
@Override | ||
public AndroidDexInfo createInfo( | ||
Artifact deployJar, Artifact finalClassesDexZip, Object javaResourceJar) | ||
throws EvalException { | ||
|
||
return new AndroidDexInfo( | ||
deployJar, finalClassesDexZip, fromNoneable(javaResourceJar, Artifact.class)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/AndroidDexInfoApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2023 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.starlarkbuildapi.android; | ||
|
||
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.EvalException; | ||
import net.starlark.java.eval.NoneType; | ||
|
||
/** An Info that can provides dex artifacts. */ | ||
@StarlarkBuiltin( | ||
name = "AndroidDexInfo", | ||
doc = | ||
"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) | ||
public interface AndroidDexInfoApi<FileT extends FileApi> extends StructApi { | ||
|
||
/** Name of this info object. */ | ||
String NAME = "AndroidDexInfo"; | ||
|
||
@StarlarkMethod( | ||
name = "deploy_jar", | ||
doc = "The deploy jar.", | ||
documented = false, | ||
structField = true) | ||
FileT getDeployJar(); | ||
|
||
@StarlarkMethod( | ||
name = "final_classes_dex_zip", | ||
doc = "The zip file containing the final dex classes.", | ||
documented = false, | ||
structField = true) | ||
FileT getFinalClassesDexZip(); | ||
|
||
@Nullable | ||
@StarlarkMethod( | ||
name = "java_resource_jar", | ||
doc = "The final Java resource jar.", | ||
documented = false, | ||
structField = true, | ||
allowReturnNones = true) | ||
FileT getJavaResourceJar(); | ||
|
||
/** Provider for {@link AndroidDexInfoApi}. */ | ||
@StarlarkBuiltin( | ||
name = "Provider", | ||
doc = | ||
"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 Provider<FileT extends FileApi> extends ProviderApi { | ||
|
||
@StarlarkMethod( | ||
name = NAME, | ||
doc = "The <code>AndroidDexInfo</code> constructor.", | ||
documented = false, | ||
parameters = { | ||
@Param( | ||
name = "deploy_jar", | ||
allowedTypes = { | ||
@ParamType(type = FileApi.class), | ||
}, | ||
named = true, | ||
doc = "The \"_deploy\" jar suitable for deployment."), | ||
@Param( | ||
name = "final_classes_dex_zip", | ||
allowedTypes = { | ||
@ParamType(type = FileApi.class), | ||
}, | ||
named = true, | ||
doc = "The zip file containing the final dex classes."), | ||
@Param( | ||
name = "java_resource_jar", | ||
allowedTypes = { | ||
@ParamType(type = FileApi.class), | ||
@ParamType(type = NoneType.class), | ||
}, | ||
named = true, | ||
doc = "The final Java resource jar."), | ||
}, | ||
selfCall = true) | ||
@StarlarkConstructor | ||
AndroidDexInfoApi<FileT> createInfo( | ||
FileT deployJar, FileT finalClassesDexZip, Object javaResourceJar) throws EvalException; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters