forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add constraint_setting and constraint_value rules, to enable defining
platform-related constraints and values. Part of ongoing work on bazelbuild#2219.
- Loading branch information
Showing
13 changed files
with
409 additions
and
6 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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/google/devtools/build/lib/rules/platform/BUILD
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,25 @@ | ||
# Description: | ||
# Rules to define Platforms and related Constraints. | ||
|
||
package( | ||
default_visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
java_library( | ||
name = "platform", | ||
srcs = glob(["*.java"]), | ||
deps = [ | ||
"//src/main/java/com/google/devtools/build/lib:build-base", | ||
"//src/main/java/com/google/devtools/build/lib:concurrent", | ||
"//src/main/java/com/google/devtools/build/lib:packages-internal", | ||
"//src/main/java/com/google/devtools/build/lib:util", | ||
"//third_party:auto_value", | ||
"//third_party:guava", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
testonly = 0, # All srcs should be not test only, overwrite package default. | ||
srcs = glob(["**"]), | ||
) |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSetting.java
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,44 @@ | ||
// Copyright 2017 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. | ||
|
||
package com.google.devtools.build.lib.rules.platform; | ||
|
||
import com.google.devtools.build.lib.analysis.ConfiguredTarget; | ||
import com.google.devtools.build.lib.analysis.FileProvider; | ||
import com.google.devtools.build.lib.analysis.FilesToRunProvider; | ||
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; | ||
import com.google.devtools.build.lib.analysis.RuleContext; | ||
import com.google.devtools.build.lib.analysis.RunfilesProvider; | ||
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; | ||
|
||
/** | ||
* Defines a category of constraint that can be fulfilled by a constraint_value rule in a platform | ||
* definition. | ||
*/ | ||
public class ConstraintSetting implements RuleConfiguredTargetFactory { | ||
|
||
@Override | ||
public ConfiguredTarget create(RuleContext ruleContext) | ||
throws InterruptedException, RuleErrorException { | ||
|
||
return new RuleConfiguredTargetBuilder(ruleContext) | ||
.addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) | ||
.addProvider(FileProvider.class, FileProvider.EMPTY) | ||
.addProvider(FilesToRunProvider.class, FilesToRunProvider.EMPTY) | ||
.addProvider( | ||
ConstraintSettingProvider.class, | ||
ConstraintSettingProvider.create(ruleContext.getLabel())) | ||
.build(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingProvider.java
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,31 @@ | ||
// Copyright 2017 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. | ||
|
||
package com.google.devtools.build.lib.rules.platform; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
|
||
/** Provider for a platform constraint setting that is available to be fulfilled. */ | ||
@AutoValue | ||
@Immutable | ||
public abstract class ConstraintSettingProvider implements TransitiveInfoProvider { | ||
public abstract Label constraint(); | ||
|
||
public static ConstraintSettingProvider create(Label constraint) { | ||
return new AutoValue_ConstraintSettingProvider(constraint); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingRule.java
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,55 @@ | ||
// Copyright 2017 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. | ||
|
||
package com.google.devtools.build.lib.rules.platform; | ||
|
||
import static com.google.devtools.build.lib.packages.Attribute.attr; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.devtools.build.lib.analysis.BaseRuleClasses; | ||
import com.google.devtools.build.lib.analysis.RuleDefinition; | ||
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; | ||
import com.google.devtools.build.lib.packages.RuleClass; | ||
import com.google.devtools.build.lib.syntax.Type; | ||
|
||
/** Rule definition for {@link ConstraintSetting}. */ | ||
public class ConstraintSettingRule implements RuleDefinition { | ||
public static final String RULE_NAME = "constraint_setting"; | ||
|
||
@Override | ||
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) { | ||
return builder | ||
.override( | ||
attr("tags", Type.STRING_LIST) | ||
// No need to show up in ":all", etc. target patterns. | ||
.value(ImmutableList.of("manual")) | ||
.nonconfigurable("low-level attribute, used in platform configuration")) | ||
.exemptFromConstraintChecking("this rule *defines* a constraint") | ||
.build(); | ||
} | ||
|
||
@Override | ||
public RuleDefinition.Metadata getMetadata() { | ||
return RuleDefinition.Metadata.builder() | ||
.name(RULE_NAME) | ||
.ancestors(BaseRuleClasses.RuleBase.class) | ||
.factoryClass(ConstraintSetting.class) | ||
.build(); | ||
} | ||
} | ||
/*<!-- #BLAZE_RULE (NAME = constraint_setting, TYPE = OTHER, FAMILY = Platform)[GENERIC_RULE] --> | ||
<p>This rule defines a type of constraint that can be used to define an execution platform.</p> | ||
<!-- #END_BLAZE_RULE -->*/ |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValue.java
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,48 @@ | ||
// Copyright 2017 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. | ||
|
||
package com.google.devtools.build.lib.rules.platform; | ||
|
||
import com.google.devtools.build.lib.analysis.ConfiguredTarget; | ||
import com.google.devtools.build.lib.analysis.FileProvider; | ||
import com.google.devtools.build.lib.analysis.FilesToRunProvider; | ||
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; | ||
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; | ||
import com.google.devtools.build.lib.analysis.RuleContext; | ||
import com.google.devtools.build.lib.analysis.RunfilesProvider; | ||
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; | ||
|
||
/** Defines a potential value of a constraint. */ | ||
public class ConstraintValue implements RuleConfiguredTargetFactory { | ||
|
||
@Override | ||
public ConfiguredTarget create(RuleContext ruleContext) | ||
throws InterruptedException, RuleErrorException { | ||
|
||
ConstraintSettingProvider constraint = | ||
ruleContext.getPrerequisite( | ||
ConstraintValueRule.PARENT_CONSTRAINT_ATTR, | ||
Mode.DONT_CHECK, | ||
ConstraintSettingProvider.class); | ||
|
||
return new RuleConfiguredTargetBuilder(ruleContext) | ||
.addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) | ||
.addProvider(FileProvider.class, FileProvider.EMPTY) | ||
.addProvider(FilesToRunProvider.class, FilesToRunProvider.EMPTY) | ||
.addProvider( | ||
ConstraintValueProvider.class, | ||
ConstraintValueProvider.create(constraint, ruleContext.getLabel())) | ||
.build(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueProvider.java
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,33 @@ | ||
// Copyright 2017 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. | ||
|
||
package com.google.devtools.build.lib.rules.platform; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
|
||
/** Provider for a platform constraint value that fulfills a {@link ConstraintSettingProvider}. */ | ||
@AutoValue | ||
@Immutable | ||
public abstract class ConstraintValueProvider implements TransitiveInfoProvider { | ||
public abstract ConstraintSettingProvider constraint(); | ||
|
||
public abstract Label value(); | ||
|
||
public static ConstraintValueProvider create(ConstraintSettingProvider constraint, Label value) { | ||
return new AutoValue_ConstraintValueProvider(constraint, value); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueRule.java
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,70 @@ | ||
// Copyright 2017 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. | ||
|
||
package com.google.devtools.build.lib.rules.platform; | ||
|
||
import static com.google.devtools.build.lib.packages.Attribute.attr; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.devtools.build.lib.analysis.BaseRuleClasses; | ||
import com.google.devtools.build.lib.analysis.RuleDefinition; | ||
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; | ||
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; | ||
import com.google.devtools.build.lib.packages.BuildType; | ||
import com.google.devtools.build.lib.packages.RuleClass; | ||
import com.google.devtools.build.lib.syntax.Type; | ||
import com.google.devtools.build.lib.util.FileTypeSet; | ||
|
||
/** Rule definition for {@link ConstraintValue}. */ | ||
public class ConstraintValueRule implements RuleDefinition { | ||
public static final String RULE_NAME = "constraint_value"; | ||
public static final String PARENT_CONSTRAINT_ATTR = "constraint"; | ||
|
||
@Override | ||
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) { | ||
return builder | ||
.override( | ||
attr("tags", Type.STRING_LIST) | ||
// No need to show up in ":all", etc. target patterns. | ||
.value(ImmutableList.of("manual")) | ||
.nonconfigurable("low-level attribute, used in platform configuration")) | ||
|
||
/* <!-- #BLAZE_RULE(constraint_value).ATTRIBUTE(constraint) --> | ||
The constraint_setting rule this value is applied to. | ||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||
.add( | ||
attr(PARENT_CONSTRAINT_ATTR, BuildType.LABEL) | ||
.mandatory() | ||
.allowedFileTypes(FileTypeSet.NO_FILE) | ||
.mandatoryNativeProviders( | ||
ImmutableList.<Class<? extends TransitiveInfoProvider>>of( | ||
ConstraintSettingProvider.class))) | ||
.exemptFromConstraintChecking("this rule *defines* a constraint") | ||
.build(); | ||
} | ||
|
||
@Override | ||
public Metadata getMetadata() { | ||
return Metadata.builder() | ||
.name(RULE_NAME) | ||
.ancestors(BaseRuleClasses.RuleBase.class) | ||
.factoryClass(ConstraintValue.class) | ||
.build(); | ||
} | ||
} | ||
/*<!-- #BLAZE_RULE (NAME = constraint_value, TYPE = OTHER, FAMILY = Platform)[GENERIC_RULE] --> | ||
<p>This rule defines a specific value of a constraint, which can be used to define execution platforms. | ||
<!-- #END_BLAZE_RULE -->*/ |
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
Oops, something went wrong.