Skip to content

Commit 8058391

Browse files
committed
[DRAFT] allow configuring pipelines via optional toolchain
1 parent fa47c0d commit 8058391

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

rules/android_binary/impl.bzl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# limitations under the License.
1414
"""Implementation."""
1515

16+
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
17+
load("@rules_java//java/common:java_common.bzl", "java_common")
18+
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
19+
load("@rules_java//java/common:java_plugin_info.bzl", "JavaPluginInfo")
1620
load("//providers:providers.bzl", "AndroidDexInfo", "AndroidFeatureFlagSet", "AndroidIdlInfo", "AndroidInstrumentationInfo", "AndroidLibraryResourceClassJarProvider", "AndroidOptimizationInfo", "AndroidPreDexJarInfo", "ApkInfo", "BaselineProfileProvider", "DataBindingV2Info", "ProguardMappingInfo", "StarlarkAndroidDexInfo", "StarlarkAndroidResourcesInfo", "StarlarkApkInfo")
1721
load("//rules:acls.bzl", "acls")
1822
load("//rules:apk_packaging.bzl", _apk_packaging = "apk_packaging")
@@ -38,17 +42,14 @@ load("//rules:proguard.bzl", "proguard")
3842
load("//rules:resources.bzl", _resources = "resources")
3943
load(
4044
"//rules:utils.bzl",
45+
"ANDROID_PIPELINE_TOOLCHAIN_TYPE",
4146
"ANDROID_TOOLCHAIN_TYPE",
4247
"compilation_mode",
4348
"get_android_sdk",
4449
"get_android_toolchain",
4550
"utils",
4651
)
4752
load("//rules:visibility.bzl", "PROJECT_VISIBILITY")
48-
load("@rules_java//java/common:java_common.bzl", "java_common")
49-
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
50-
load("@rules_java//java/common:java_plugin_info.bzl", "JavaPluginInfo")
51-
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
5253
load(":r8.bzl", "process_r8", "process_resource_shrinking_r8")
5354

5455
visibility(PROJECT_VISIBILITY)
@@ -1100,7 +1101,7 @@ PROCESSORS = dict(
11001101
CoverageProcessor = _process_coverage,
11011102
)
11021103

1103-
_PROCESSING_PIPELINE = processing_pipeline.make_processing_pipeline(
1104+
PROCESSING_PIPELINE = processing_pipeline.make_processing_pipeline(
11041105
processors = PROCESSORS,
11051106
finalize = finalize,
11061107
)
@@ -1115,4 +1116,5 @@ def impl(ctx):
11151116
A list of providers.
11161117
"""
11171118
java_package = java.resolve_package_from_label(ctx.label, ctx.attr.custom_package)
1118-
return processing_pipeline.run(ctx, java_package, _PROCESSING_PIPELINE)
1119+
pipeline = ctx.toolchains[ANDROID_PIPELINE_TOOLCHAIN_TYPE]
1120+
return processing_pipeline.run(ctx, java_package, pipeline or PROCESSING_PIPELINE)

rules/android_binary/rule.bzl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
# limitations under the License.
1414
"""Starlark Android Binary for Android Rules."""
1515

16+
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
1617
load("//providers:providers.bzl", "ApkInfo")
1718
load("//rules:acls.bzl", "acls")
1819
load(
1920
"//rules:attrs.bzl",
2021
_attrs = "attrs",
2122
)
22-
load("//rules:utils.bzl", "ANDROID_SDK_TOOLCHAIN_TYPE")
23+
load("//rules:utils.bzl", "ANDROID_PIPELINE_TOOLCHAIN_TYPE", "ANDROID_SDK_TOOLCHAIN_TYPE", "ANDROID_TOOLCHAIN_TYPE")
2324
load("//rules:visibility.bzl", "PROJECT_VISIBILITY")
24-
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
2525
load(":attrs.bzl", "ATTRS")
2626
load(":impl.bzl", "impl")
2727

@@ -74,7 +74,11 @@ def make_rule(
7474
implementation = implementation,
7575
provides = provides,
7676
toolchains = [
77-
"//toolchains/android:toolchain_type",
77+
config_common.toolchain_type(
78+
ANDROID_PIPELINE_TOOLCHAIN_TYPE,
79+
mandatory = False,
80+
),
81+
ANDROID_TOOLCHAIN_TYPE,
7882
ANDROID_SDK_TOOLCHAIN_TYPE,
7983
"@bazel_tools//tools/jdk:toolchain_type",
8084
] + additional_toolchains,

rules/android_library/impl.bzl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
# limitations under the License.
1414
"""Implementation."""
1515

16+
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
17+
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
18+
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
19+
load("@rules_java//java/common:java_plugin_info.bzl", "JavaPluginInfo")
20+
load("@rules_java//java/common:proguard_spec_info.bzl", "ProguardSpecInfo")
1621
load("//providers:providers.bzl", "AndroidCcLinkParamsInfo", "AndroidIdlInfo", "AndroidLibraryAarInfo", "AndroidLintRulesInfo", "AndroidNativeLibsInfo", "BaselineProfileProvider", "DataBindingV2Info", "StarlarkAndroidResourcesInfo", "StarlarkApkInfo")
1722
load("//rules:acls.bzl", "acls")
1823
load("//rules:attrs.bzl", _attrs = "attrs")
@@ -28,14 +33,9 @@ load(
2833
)
2934
load("//rules:proguard.bzl", _proguard = "proguard")
3035
load("//rules:resources.bzl", _resources = "resources")
31-
load("//rules:utils.bzl", "get_android_sdk", "get_android_toolchain", "log", "utils")
36+
load("//rules:utils.bzl", "ANDROID_PIPELINE_TOOLCHAIN_TYPE", "get_android_sdk", "get_android_toolchain", "log", "utils")
3237
load("//rules:visibility.bzl", "PROJECT_VISIBILITY")
3338
load("//rules/flags:flags.bzl", _flags = "flags")
34-
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
35-
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
36-
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
37-
load("@rules_java//java/common:java_plugin_info.bzl", "JavaPluginInfo")
38-
load("@rules_java//java/common:proguard_spec_info.bzl", "ProguardSpecInfo")
3939

4040
visibility(PROJECT_VISIBILITY)
4141

@@ -585,7 +585,7 @@ def finalize(
585585
])
586586
return providers
587587

588-
_PROCESSING_PIPELINE = processing_pipeline.make_processing_pipeline(
588+
PROCESSING_PIPELINE = processing_pipeline.make_processing_pipeline(
589589
processors = PROCESSORS,
590590
finalize = finalize,
591591
)
@@ -600,4 +600,5 @@ def impl(ctx):
600600
A legacy struct provider.
601601
"""
602602
java_package = _java.resolve_package_from_label(ctx.label, ctx.attr.custom_package)
603-
return processing_pipeline.run(ctx, java_package, _PROCESSING_PIPELINE)
603+
pipeline = ctx.toolchains[ANDROID_PIPELINE_TOOLCHAIN_TYPE]
604+
return processing_pipeline.run(ctx, java_package, pipeline or PROCESSING_PIPELINE)

rules/android_library/rule.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
# limitations under the License.
1414
"""android_library rule."""
1515

16+
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
1617
load("//providers:providers.bzl", "AndroidCcLinkParamsInfo", "AndroidIdeInfo", "AndroidIdlInfo", "AndroidLibraryResourceClassJarProvider", "AndroidNativeLibsInfo")
1718
load(
1819
"//rules:attrs.bzl",
1920
_attrs = "attrs",
2021
)
21-
load("//rules:utils.bzl", "ANDROID_SDK_TOOLCHAIN_TYPE")
22+
load("//rules:utils.bzl", "ANDROID_PIPELINE_TOOLCHAIN_TYPE", "ANDROID_SDK_TOOLCHAIN_TYPE")
2223
load("//rules:visibility.bzl", "PROJECT_VISIBILITY")
23-
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
2424
load(":attrs.bzl", _ATTRS = "ATTRS")
2525
load(":impl.bzl", _impl = "impl")
2626

@@ -172,6 +172,10 @@ def make_rule(
172172
toolchains = [
173173
"//toolchains/android:toolchain_type",
174174
"@bazel_tools//tools/jdk:toolchain_type",
175+
config_common.toolchain_type(
176+
ANDROID_PIPELINE_TOOLCHAIN_TYPE,
177+
mandatory = False,
178+
),
175179
ANDROID_SDK_TOOLCHAIN_TYPE,
176180
] + additional_toolchains,
177181
_skylark_testable = True,

rules/utils.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ visibility(PROJECT_VISIBILITY)
2020

2121
ANDROID_TOOLCHAIN_TYPE = Label("//toolchains/android:toolchain_type")
2222
ANDROID_SDK_TOOLCHAIN_TYPE = Label("//toolchains/android_sdk:toolchain_type")
23+
ANDROID_PIPELINE_TOOLCHAIN_TYPE = Label("//toolchains/pipeline:toolchain_type")
2324

2425
_CUU = "\033[A"
2526
_EL = "\033[K"

toolchains/pipeline/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
toolchain_type(
2+
name = "toolchain_type",
3+
visibility = ["//visibility:public"],
4+
)

toolchains/pipeline/toolchain.bzl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
load(
2+
"//rules/android_binary:impl.bzl",
3+
binary_pipeline = "PROCESSING_PIPELINE",
4+
)
5+
load(
6+
"//rules/android_library:impl.bzl",
7+
library_pipeline = "PROCESSING_PIPELINE",
8+
)
9+
10+
def _impl(ctx):
11+
return [
12+
platform_common.ToolchainInfo(
13+
library = library_pipeline,
14+
binary = binary_pipeline,
15+
),
16+
]
17+
18+
android_toolchain = rule(
19+
implementation = _impl,
20+
attrs = {},
21+
)

0 commit comments

Comments
 (0)