-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce toolchain helper (#194)
This is not final yet, I just want to test out with rules_python first. Welcome to review though. Also due to bazelbuild/bazel#20297 i can't write unit tests for the incompatible flag. I'll look for a workaround.
- Loading branch information
Showing
6 changed files
with
103 additions
and
0 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
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
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,3 @@ | ||
load(":toolchains.bzl", "unittest_toolchains") | ||
|
||
unittest_toolchains() |
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,51 @@ | ||
"unit tests for proto_common.toolchains" | ||
|
||
load("@bazel_skylib//lib:partial.bzl", "partial") | ||
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") | ||
load("//proto:proto_common.bzl", "toolchains") | ||
|
||
def _test_toolchains_without_incompatible_flag(ctx): | ||
env = unittest.begin(ctx) | ||
|
||
asserts.equals(env, {}, toolchains.if_legacy_toolchain({})) | ||
asserts.equals(env, None, toolchains.if_legacy_toolchain(None)) | ||
asserts.equals(env, False, toolchains.if_legacy_toolchain(False)) | ||
|
||
return unittest.end(env) | ||
|
||
toolchains_without_incompatible_flags_test = unittest.make(_test_toolchains_without_incompatible_flag) | ||
|
||
def _test_toolchains_with_incompatible_flag(ctx): | ||
env = unittest.begin(ctx) | ||
|
||
asserts.equals(env, {}, toolchains.if_legacy_toolchain({})) | ||
asserts.equals(env, {}, toolchains.if_legacy_toolchain(None)) | ||
asserts.equals(env, {}, toolchains.if_legacy_toolchain(False)) | ||
toolchain = toolchains.use_toolchain("//nonexistent:toolchain_type") | ||
asserts.equals(env, 1, len(toolchain)) | ||
asserts.equals(env, False, toolchain[0].mandatory) | ||
asserts.equals(env, str(Label("//nonexistent:toolchain_type")), str(toolchain[0].toolchain_type)) | ||
|
||
return unittest.end(env) | ||
|
||
toolchains_with_incompatible_flag_test = unittest.make(_test_toolchains_with_incompatible_flag) | ||
|
||
# buildifier: disable=unnamed-macro | ||
def unittest_toolchains(): | ||
unittest.suite( | ||
"test_toolchains", | ||
partial.make( | ||
toolchains_without_incompatible_flags_test, | ||
target_compatible_with = select({ | ||
"//tests:incompatible_enable_proto_toolchain_resolution": ["@platforms//:incompatible"], | ||
"//conditions:default": [], | ||
}), | ||
), | ||
partial.make( | ||
toolchains_with_incompatible_flag_test, | ||
target_compatible_with = select({ | ||
"//tests:incompatible_enable_proto_toolchain_resolution": [], | ||
"//conditions:default": ["@platforms//:incompatible"], | ||
}), | ||
), | ||
) |