Skip to content

Commit

Permalink
Add useful factory methods for ToolchainTypeRequirement.
Browse files Browse the repository at this point in the history
Part of Optional Toolchains (bazelbuild#14726).
  • Loading branch information
katre committed Feb 15, 2022
1 parent 34f20a1 commit 28c92b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
/** Describes a requirement on a specific toolchain type. */
@AutoValue
public abstract class ToolchainTypeRequirement {

/** Returns a new {@link ToolchainTypeRequirement}. */
public static ToolchainTypeRequirement create(Label toolchainType) {
return builder(toolchainType).build();
}

/** Returns a builder for a new {@link ToolchainTypeRequirement}. */
public static Builder builder(Label toolchainType) {
return builder()
.toolchainType(toolchainType);
}

/** Returns a builder for a new {@link ToolchainTypeRequirement}. */
public static Builder builder() {
return new AutoValue_ToolchainTypeRequirement.Builder().mandatory(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public interface Builder {
default Builder requiredToolchains(ImmutableSet<Label> toolchainTypes) {
ImmutableSet<ToolchainTypeRequirement> toolchainTypeRequirements =
toolchainTypes.stream()
.map(label -> ToolchainTypeRequirement.builder().toolchainType(label).build())
.map(label -> ToolchainTypeRequirement.create(label))
.collect(toImmutableSet());
return this.toolchainTypes(toolchainTypeRequirements);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ default Builder requiredToolchainTypeLabels(Label... requiredToolchainTypeLabels
default Builder requiredToolchainTypeLabels(ImmutableSet<Label> requiredToolchainTypeLabels) {
ImmutableSet<ToolchainTypeRequirement> toolchainTypeRequirements =
requiredToolchainTypeLabels.stream()
.map(label -> ToolchainTypeRequirement.builder().toolchainType(label).build())
.map(label -> ToolchainTypeRequirement.create(label))
.collect(toImmutableSet());
return this.toolchainTypes(toolchainTypeRequirements);
}
Expand Down

0 comments on commit 28c92b5

Please sign in to comment.