Skip to content

Commit b7404c9

Browse files
ted-xiecopybara-github
authored andcommitted
Open-source mobile_install/providers.bzl
Part of #12 PiperOrigin-RevId: 582151127 Change-Id: Idd28f519e21a72d16593e46b1ec4256a51de252e
1 parent 256c220 commit b7404c9

File tree

1 file changed

+233
-0
lines changed

1 file changed

+233
-0
lines changed

mobile_install/providers.bzl

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# Copyright 2018 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# Copyright 2018 The Bazel Authors. All rights reserved.
15+
#
16+
# Licensed under the Apache License, Version 2.0 (the "License");
17+
# you may not use this file except in compliance with the License.
18+
# You may obtain a copy of the License at
19+
#
20+
# http://www.apache.org/licenses/LICENSE-2.0
21+
#
22+
# Unless required by applicable law or agreed to in writing, software
23+
# distributed under the License is distributed on an "AS IS" BASIS,
24+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
# See the License for the specific language governing permissions and
26+
# limitations under the License.
27+
28+
"""Bazel mobile-install providers."""
29+
30+
MIAppInfo = provider(
31+
doc = "A provider with all relevant details about an app",
32+
fields = dict(
33+
manifest_package_name = "A file containing the manifest package name",
34+
package = "Name of the package",
35+
app_name = "Name of the App",
36+
shell_apk = "The shell.apk file for the app",
37+
splits = "The split apk files for the app",
38+
r_dex = "The R dex files",
39+
merged_manifest = "The Merged manifest file",
40+
merged_dex_shards = "The Merged dex shards",
41+
dex_shards = "The dex files for the app",
42+
native_zip = "The native zip file",
43+
apk = "The generated android.apk path for the app",
44+
instrumented_app = "The MIAppInfo provider of binary_under_test to be instrumented",
45+
),
46+
)
47+
48+
MIAppLaunchInfo = provider(
49+
doc = "A provider with launching details about an app",
50+
fields = dict(
51+
launcher = "The launcher file",
52+
launcher_flags = "The flagfile for the app",
53+
runfiles = "The list of files needed to launch an app",
54+
sync = "Sync.pb for one or many apps",
55+
),
56+
)
57+
58+
MIAndroidAarNativeLibsInfo = provider(
59+
doc = "Provides Android AAR native libs information",
60+
fields = dict(
61+
transitive_native_libs = (
62+
"A depset containing the native libs provided by all the " +
63+
"aar_import rules within the transitive closure of the target."
64+
),
65+
),
66+
)
67+
68+
MIAndroidAssetsInfo = provider(
69+
doc = "Provider Android Assets information",
70+
fields = dict(
71+
transitive_assets = (
72+
"A depset of assets in the transitive closure of the target."
73+
),
74+
transitive_assets_dirs = (
75+
"A depset of assets dirs in the transitive closure of the target."
76+
),
77+
),
78+
)
79+
80+
MIAndroidDexInfo = provider(
81+
doc = "Provides Android Dex information",
82+
fields = dict(
83+
transitive_dex_shards = (
84+
"A list of depsets each containing all of the shard level " +
85+
"dexes in the transitive closure of the target."
86+
),
87+
),
88+
)
89+
90+
MIAndroidResourcesInfo = provider(
91+
doc = "Provider Android Resources information",
92+
fields = dict(
93+
resources_graph = (
94+
"Build up a resource graph so that it may be orderd in a bfs" +
95+
"manner (and deps list order)."
96+
),
97+
transitive_packages = (
98+
"A depset of package names in the transitive closure of the target."
99+
),
100+
r_java_info = "The JavaInfo for an R.jar",
101+
transitive_r_pbs = "The transitive R.pb files.",
102+
),
103+
)
104+
105+
MIAndroidSdkInfo = provider(
106+
doc = "Provides android_sdk rule information",
107+
fields = dict(
108+
aidl_lib = "The aidl_lib attribute of an android_sdk rule.",
109+
),
110+
)
111+
112+
MIJavaResourcesInfo = provider(
113+
doc = "Provider Java Resources information",
114+
fields = dict(
115+
transitive_java_resources = (
116+
"A depset of all the Java resources in the transitive closure of " +
117+
"the target."
118+
),
119+
),
120+
)
121+
122+
def _collect(provider_type, *all_deps):
123+
providers = []
124+
for deps in all_deps:
125+
for dep in deps:
126+
if provider_type in dep:
127+
providers.append(dep[provider_type])
128+
return providers
129+
130+
def _make_mi_android_aar_native_libs_info(
131+
native_libs = None,
132+
deps = []):
133+
transitive_native_libs = [native_libs] if native_libs else []
134+
for info in deps:
135+
transitive_native_libs.append(info.transitive_native_libs)
136+
137+
return MIAndroidAarNativeLibsInfo(
138+
transitive_native_libs = depset(transitive = transitive_native_libs),
139+
)
140+
141+
def _make_mi_android_assets_info(
142+
assets = depset(),
143+
assets_dir = None,
144+
deps = []):
145+
transitive_assets = []
146+
transitive_assets_dirs = []
147+
for info in deps:
148+
transitive_assets.append(info.transitive_assets)
149+
transitive_assets_dirs.append(info.transitive_assets_dirs)
150+
return MIAndroidAssetsInfo(
151+
transitive_assets = depset(
152+
transitive = [assets] + transitive_assets,
153+
),
154+
transitive_assets_dirs = depset(
155+
([assets_dir] if assets_dir else []),
156+
transitive = transitive_assets_dirs,
157+
),
158+
)
159+
160+
def _make_mi_android_dex_info(
161+
dex_shards = [],
162+
deps = []):
163+
dex_buckets = dict()
164+
for shards in dex_shards:
165+
for idx, shard in enumerate(shards):
166+
dex_buckets.setdefault(idx, []).append(shard)
167+
168+
transitive_dexes_per_shard = dict()
169+
for info in deps:
170+
if not info.transitive_dex_shards:
171+
continue
172+
for idx, dex_shard in enumerate(info.transitive_dex_shards):
173+
transitive_dexes_per_shard.setdefault(idx, []).append(dex_shard)
174+
175+
transitive_dex_shards = []
176+
for idx in range(len(dex_buckets) or len(transitive_dexes_per_shard)):
177+
transitive_dex_shards.append(
178+
depset(
179+
dex_buckets.get(idx, []),
180+
transitive = transitive_dexes_per_shard.get(idx, []),
181+
order = "preorder",
182+
),
183+
)
184+
185+
return MIAndroidDexInfo(transitive_dex_shards = transitive_dex_shards)
186+
187+
def _make_mi_android_resources_info(
188+
package = None,
189+
label = None,
190+
r_pb = None,
191+
resources = depset(),
192+
deps = []):
193+
resources_subgraphs = []
194+
transitive_packages = []
195+
transitive_r_pbs = []
196+
for info in deps:
197+
resources_subgraphs.append(info.resources_graph)
198+
transitive_packages.append(info.transitive_packages)
199+
transitive_r_pbs.append(info.transitive_r_pbs)
200+
return MIAndroidResourcesInfo(
201+
resources_graph = (label, resources, resources_subgraphs),
202+
transitive_packages = depset(
203+
([package] if package else []),
204+
transitive = transitive_packages,
205+
),
206+
transitive_r_pbs = depset(
207+
([r_pb] if r_pb else []),
208+
transitive = transitive_r_pbs,
209+
),
210+
)
211+
212+
def _make_mi_java_resources_info(
213+
java_resources = [],
214+
deps = []):
215+
transitive_java_resources = []
216+
for info in deps:
217+
transitive_java_resources.append(info.transitive_java_resources)
218+
219+
return MIJavaResourcesInfo(
220+
transitive_java_resources = depset(
221+
java_resources,
222+
transitive = transitive_java_resources,
223+
),
224+
)
225+
226+
providers = struct(
227+
collect = _collect,
228+
make_mi_android_aar_native_libs_info = _make_mi_android_aar_native_libs_info,
229+
make_mi_android_assets_info = _make_mi_android_assets_info,
230+
make_mi_android_dex_info = _make_mi_android_dex_info,
231+
make_mi_android_resources_info = _make_mi_android_resources_info,
232+
make_mi_java_resources_info = _make_mi_java_resources_info,
233+
)

0 commit comments

Comments
 (0)