Skip to content
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

Add non-Starlark optional toolchain API #14770

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,15 @@ java_library(
],
)

java_library(
name = "config/toolchain_type_requirement",
srcs = ["config/ToolchainTypeRequirement.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//third_party:auto_value",
],
)

java_library(
name = "config/transition_factories",
srcs = ["config/TransitionFactories.java"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2022 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.analysis.config;

import com.google.auto.value.AutoValue;
import com.google.devtools.build.lib.cmdline.Label;

/**
* Describes a requirement on a specific toolchain type.
*/
@AutoValue
public abstract class ToolchainTypeRequirement {
/** Returns a builder for a new {@Link ToolchainTypeRequirement}. */
public static Builder builder() {
return new AutoValue_ToolchainTypeRequirement.Builder()
.mandatory(true);
}

/** Returns the label of the toolchain type that is requested. */
public abstract Label toolchainType();

/**
* Returns whether the toolchain type is mandatory or optional. An optional toolchain type which
* cannot be found will be skipped, but a mandatory toolchain type which cannot be found will stop
* the build with an error.
*/
public abstract boolean mandatory();

/** A builder for a new {@link ToolchainTypeRequirement}. */
@AutoValue.Builder
public interface Builder {
/** Sets the toolchain type. */
Builder toolchainType(Label toolchainType);
/** Sets whether the toolchain type is mandatory. */
Builder mandatory(boolean mandatory);

/** Returns the newly built {@link ToolchainTypeRequirement}. */
ToolchainTypeRequirement build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2022 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.analysis.testing;

import static com.google.common.truth.Truth.assertAbout;

import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.cmdline.Label;

/** A Truth {@link Subject} for {@link ToolchainTypeRequirement}. */
public class ToolchainTypeRequirementSubject extends Subject {
// Static data.

/** Entry point for test assertions related to {@link ToolchainTypeRequirement}. */
public static ToolchainTypeRequirementSubject assertThat(
ToolchainTypeRequirement toolchainTypeRequirement) {
return assertAbout(ToolchainTypeRequirementSubject::new).that(toolchainTypeRequirement);
}

/** Static method for getting the subject factory (for use with assertAbout()). */
public static Subject.Factory<ToolchainTypeRequirementSubject, ToolchainTypeRequirement>
toolchainTypeRequirements() {
return ToolchainTypeRequirementSubject::new;
}

// Instance fields.

private final ToolchainTypeRequirement actual;

protected ToolchainTypeRequirementSubject(
FailureMetadata failureMetadata, ToolchainTypeRequirement subject) {
super(failureMetadata, subject);
this.actual = subject;
}

public ComparableSubject<Label> toolchainType() {
return check("toolchainType").that(actual.toolchainType());
}

public void isMandatory() {
check("mandatory").that(actual.mandatory()).isTrue();
}

public void isOptional() {
check("mandatory").that(actual.mandatory()).isFalse();
}
}