-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Let use_target_platform_constraints copy unmatched constraints #30688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ public record DeclaredToolchainInfo( | |
| ToolchainTypeInfo toolchainType, | ||
| ConstraintCollection execConstraints, | ||
| ConstraintCollection targetConstraints, | ||
| boolean useTargetPlatformConstraints, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an |
||
| ImmutableList<ConfigMatchingProvider> targetSettings, | ||
| Label targetLabel, | ||
| Label resolvedToolchainLabel) | ||
|
|
@@ -58,27 +59,15 @@ public record DeclaredToolchainInfo( | |
| } | ||
|
|
||
| public boolean hasTargetToExecConstraints() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can just be dropped/inlined |
||
| // This needs to check identity as the special ConstraintCollection is otherwise equal to the | ||
| // empty one. This avoids adding a new field or making ConstraintCollection more complex. | ||
| return execConstraints == USE_TARGET_PLATFORM_CONSTRAINTS | ||
| && targetConstraints == USE_TARGET_PLATFORM_CONSTRAINTS; | ||
| } | ||
|
|
||
| private static final ConstraintCollection USE_TARGET_PLATFORM_CONSTRAINTS; | ||
|
|
||
| static { | ||
| try { | ||
| USE_TARGET_PLATFORM_CONSTRAINTS = ConstraintCollection.builder().build(); | ||
| } catch (ConstraintCollection.DuplicateConstraintException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| return useTargetPlatformConstraints; | ||
| } | ||
|
|
||
| /** Builder class to assist in creating {@link DeclaredToolchainInfo} instances. */ | ||
| public static class Builder { | ||
| private ToolchainTypeInfo toolchainType; | ||
| private final ConstraintCollection.Builder execConstraints = ConstraintCollection.builder(); | ||
| private final ConstraintCollection.Builder targetConstraints = ConstraintCollection.builder(); | ||
| private boolean useTargetPlatformConstraints = false; | ||
| private final ImmutableList.Builder<ConfigMatchingProvider> targetSettings = | ||
| new ImmutableList.Builder<>(); | ||
| private Label targetLabel; | ||
|
|
@@ -117,6 +106,13 @@ public Builder addTargetConstraints(ConstraintValueInfo... constraints) { | |
| return addTargetConstraints(ImmutableList.copyOf(constraints)); | ||
| } | ||
|
|
||
| /** Sets the flag to add unmatched target platform constraints as exec constraints. */ | ||
| @CanIgnoreReturnValue | ||
| public Builder useTargetPlatformConstraints(boolean enabled) { | ||
| this.useTargetPlatformConstraints = enabled; | ||
| return this; | ||
| } | ||
|
|
||
| @CanIgnoreReturnValue | ||
| public Builder addTargetSettings(Iterable<ConfigMatchingProvider> targetSettings) { | ||
| this.targetSettings.addAll(targetSettings); | ||
|
|
@@ -164,16 +160,7 @@ public DeclaredToolchainInfo build() throws DuplicateConstraintException { | |
| toolchainType, | ||
| execConstraints, | ||
| targetConstraints, | ||
| targetSettings.build(), | ||
| targetLabel, | ||
| resolvedToolchainLabel); | ||
| } | ||
|
|
||
| public DeclaredToolchainInfo buildWithTargetToExecConstraints() { | ||
| return new DeclaredToolchainInfo( | ||
| toolchainType, | ||
| USE_TARGET_PLATFORM_CONSTRAINTS, | ||
| USE_TARGET_PLATFORM_CONSTRAINTS, | ||
| useTargetPlatformConstraints, | ||
| targetSettings.build(), | ||
| targetLabel, | ||
| resolvedToolchainLabel); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -757,6 +757,144 @@ def _some_test_impl(ctx): | |
| assertThat(testAction.getExecProperties()).containsExactly("os", targetOs, "cpu", targetCpu); | ||
| } | ||
|
|
||
| /** | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to see a test that verifies that |
||
| * With the default test toolchain, a test action should run on a platform that matches all | ||
| * constraints of the target platform. | ||
| */ | ||
| @Test | ||
| public void testExecPlatformMatchesTargetConstraintsWithDefaultTestToolchainFRME() throws Exception { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name doesn't match the content (and FRME is probably not meant to be there either ;-)) |
||
| scratch.file( | ||
| "some_test.bzl", | ||
| """ | ||
| def _some_test_impl(ctx): | ||
| script = ctx.actions.declare_file(ctx.attr.name + ".sh") | ||
| ctx.actions.write(script, "shell script goes here", is_executable = True) | ||
| return [ | ||
| DefaultInfo(executable = script), | ||
| ] | ||
|
|
||
| some_test = rule( | ||
| implementation = _some_test_impl, | ||
| test = True, | ||
| exec_groups = { | ||
| "test": exec_group( | ||
| toolchains = [Label(":my_test_toolchain_type")], | ||
| ), | ||
| }, | ||
| ) | ||
| """); | ||
| scratch.file( | ||
| "BUILD", | ||
| """ | ||
| load(":some_test.bzl", "some_test") | ||
|
|
||
| toolchain_type(name = "my_test_toolchain_type") | ||
|
|
||
| constraint_setting(name = "exec") | ||
| constraint_value( | ||
| name = "is_exec", | ||
| constraint_setting = ":exec", | ||
| ) | ||
|
|
||
| constraint_setting(name = "target") | ||
| constraint_value( | ||
| name = "is_device", | ||
| constraint_setting = ":target", | ||
| ) | ||
|
|
||
| platform( | ||
| name = "target_on_device", | ||
| constraint_values = [ | ||
| "%1$sos:linux", | ||
| "%1$scpu:aarch64", | ||
| ":is_device", | ||
| ], | ||
| ) | ||
|
|
||
| toolchain( | ||
| name = "aarch64_test_toolchain", | ||
| target_compatible_with = [ | ||
| "%1$scpu:aarch64", | ||
| "%1$sos:linux", | ||
| ], | ||
| exec_compatible_with = [ | ||
| "%1$scpu:aarch64", | ||
| "//:is_exec", | ||
| ], | ||
| toolchain_type = ":my_test_toolchain_type", | ||
| use_target_platform_constraints = True, | ||
| toolchain = "%2$s//tools/test:empty_toolchain", | ||
| ) | ||
|
|
||
| # Default test toolchain will require exec platform with: | ||
| # :linux | ||
| # :aarch64 | ||
| # :is_device | ||
| # linux_gpu_test_toolchain will require exec platform with: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment needs to be adapted to this test case, there is no |
||
| # :aarch64 - Toolchain exec_compatible_with (and target_compatible with). | ||
| # :is_device - Requirement from target platform (use_target_platform_constraints). | ||
| # :is_exec - Toolchain exec_compatible_with. | ||
|
|
||
| platform( | ||
| name = "exec_missing_aarch64", | ||
| constraint_values = [ | ||
| "%1$sos:linux", | ||
| ":is_exec", | ||
| ":is_device", | ||
| ], | ||
| exec_properties = {"key": "bad"}, | ||
| ) | ||
|
|
||
| platform( | ||
| name = "exec_missing_is_device", | ||
| constraint_values = [ | ||
| "%1$sos:linux", | ||
| "%1$scpu:aarch64", | ||
| ":is_exec", | ||
| ], | ||
| exec_properties = {"key": "bad"}, | ||
| ) | ||
|
|
||
| platform( | ||
| name = "exec_missing_is_exec", | ||
| constraint_values = [ | ||
| "%1$sos:linux", | ||
| "%1$scpu:aarch64", | ||
| ":is_device", | ||
| ], | ||
| exec_properties = {"key": "bad"}, | ||
| ) | ||
|
|
||
| platform( | ||
| name = "exec_expected", | ||
| constraint_values = [ | ||
| "%1$scpu:aarch64", | ||
| ":is_exec", | ||
| ":is_device", | ||
| # macos is not needed: Toolchain target_compatible_with Linux, not exec_compatible_with any os. | ||
| "%1$sos:macos", | ||
| ], | ||
| exec_properties = {"key": "good"}, | ||
| ) | ||
|
|
||
| some_test(name = "some_test") | ||
| """ | ||
| .formatted(TestConstants.CONSTRAINTS_PACKAGE_ROOT, TestConstants.TOOLS_REPOSITORY.getCanonicalForm())); | ||
| useConfiguration( | ||
| String.format( | ||
| "--%s//tools/test:incompatible_use_default_test_toolchain", | ||
| TestConstants.TOOLS_REPOSITORY.getCanonicalForm()), | ||
| "--platforms=//:target_on_device", | ||
| "--extra_toolchains=//:aarch64_test_toolchain", | ||
| "--extra_execution_platforms=//:exec_missing_aarch64,//:exec_missing_is_device,//:exec_missing_is_exec,//:exec_expected"); | ||
| ImmutableList<Artifact.DerivedArtifact> testStatusList = getTestStatusArtifacts("//:some_test"); | ||
| assertThat(testStatusList).hasSize(1); | ||
| TestRunnerAction testAction = (TestRunnerAction) getGeneratingAction(testStatusList.get(0)); | ||
| assertThat(testAction.getExecutionPlatform().label()) | ||
| .isEqualTo(Label.parseCanonicalUnchecked("//:exec_expected")); | ||
| assertThat(testAction.getExecProperties()).containsExactly("key", "good"); | ||
| } | ||
|
|
||
| /** | ||
| * With the default test toolchain, a failure to find a suitable execution platform will result in | ||
| * a toolchain resolution error. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be preexisting, but I think that
parenton aplatformisn't handled correctly by this as well as the "target to exec" logic. Could you add a test exercising that behavior and fix it if needed?