-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathandroid.bzl
155 lines (143 loc) · 5.3 KB
/
android.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
load(
"@rules_android//android:rules.bzl",
_android_library = "android_library",
_android_local_test = "android_local_test",
)
# Copyright 2018 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.
load(
"//kotlin/internal/jvm:jvm.bzl",
_kt_jvm_library = "kt_jvm_library",
)
_ANDROID_SDK_JAR = "%s" % Label("//third_party:android_sdk")
def _kt_android_artifact(
name,
srcs = [],
deps = [],
resources = [],
plugins = [],
associates = [],
kotlinc_opts = None,
javac_opts = None,
enable_data_binding = False,
tags = [],
exec_properties = None,
resource_files = None,
assets = None,
assets_dir = None,
**kwargs):
"""Delegates Android related build attributes to the native rules but uses the Kotlin builder to compile Java and
Kotlin srcs. Returns a sequence of labels that a wrapping macro should export.
"""
base_name = name + "_base"
kt_name = name + "_kt"
# TODO(bazelbuild/rules_kotlin/issues/273): This should be retrieved from a provider.
base_deps = [_ANDROID_SDK_JAR] + deps
manifest_only = not resource_files and not assets
if 'kt_prune_transitive_deps_incompatible' in tags or manifest_only:
# TODO(bazelbuild/rules_kotlin/issues/556): replace with starlark
# buildifier: disable=native-android
_android_library(
name = base_name,
resource_files = resource_files,
exports = base_deps,
deps = deps if enable_data_binding else [],
enable_data_binding = enable_data_binding,
tags = tags,
assets = assets,
assets_dir = assets_dir,
visibility = ["//visibility:private"],
**kwargs
)
else:
_android_library(
name = base_name,
resource_files = resource_files,
deps = deps,
custom_package = kwargs.get("custom_package", default = None),
manifest = kwargs.get("manifest", default = None),
assets = assets,
assets_dir = assets_dir,
enable_data_binding = enable_data_binding,
tags = tags,
visibility = ["//visibility:private"],
)
_kt_jvm_library(
name = kt_name,
srcs = srcs,
deps = [base_name] + base_deps,
resources = resources,
plugins = plugins,
associates = associates,
testonly = kwargs.get("testonly", default = False),
visibility = ["//visibility:public"],
kotlinc_opts = kotlinc_opts,
javac_opts = javac_opts,
tags = tags,
exec_properties = exec_properties,
)
return [base_name, kt_name]
def kt_android_library(name, exports = [], visibility = None, exec_properties = None, **kwargs):
"""Creates an Android sandwich library.
`srcs`, `deps`, `plugins` are routed to `kt_jvm_library` the other android
related attributes are handled by the native `android_library` rule.
"""
_android_library(
name = name,
exports = exports + _kt_android_artifact(name, exec_properties = exec_properties, **kwargs),
visibility = visibility,
tags = kwargs.get("tags", default = None),
testonly = kwargs.get("testonly", default = 0),
exec_properties = exec_properties,
)
def kt_android_local_test(
name,
jvm_flags = None,
manifest = None,
manifest_values = None,
test_class = None,
size = None,
data = None,
timeout = None,
flaky = False,
shard_count = None,
visibility = None,
testonly = True,
exec_properties = None,
nocompress_extensions = None,
**kwargs):
"""Creates a testable Android sandwich library.
`srcs`, `deps`, `plugins`, `associates` are routed to `kt_jvm_library` the other android
related attributes are handled by the native `android_library` rule while the test attributes
are picked out and handled by the `android_local_test` rule.
"""
_android_local_test(
name = name,
deps = kwargs.get("deps", []) + _kt_android_artifact(name = name, manifest = manifest, testonly = testonly, exec_properties = exec_properties, **kwargs),
jvm_flags = jvm_flags,
test_class = test_class,
visibility = visibility,
size = size,
data = data,
timeout = timeout,
flaky = flaky,
shard_count = shard_count,
custom_package = kwargs.get("custom_package", default = None),
manifest = manifest,
manifest_values = manifest_values,
tags = kwargs.get("tags", default = None),
testonly = testonly,
exec_properties = exec_properties,
nocompress_extensions = nocompress_extensions,
)