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 (#14726).

Closes #14825.

PiperOrigin-RevId: 428865799
  • Loading branch information
katre authored and copybara-github committed Feb 15, 2022
1 parent e6a44f8 commit 3550a2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
/** 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 3550a2a

Please sign in to comment.