Skip to content

Commit

Permalink
Move DEFAULT_EXEC_GROUP_NAME from ToolchainCollection to ExecGroup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 372342837
  • Loading branch information
katre committed Jul 13, 2021
1 parent 08ef30b commit dc140d0
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ java_library(
deps = [
"toolchain_collection",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:exec_group",
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
Expand Down Expand Up @@ -1066,6 +1067,7 @@ java_library(
":toolchain_context",
"//src/main/java/com/google/devtools/build/lib/analysis/platform",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/packages:exec_group",
"//third_party:auto_value",
"//third_party:guava",
],
Expand Down Expand Up @@ -1651,10 +1653,10 @@ java_library(
":config/transitions/patch_transition",
":config/transitions/transition_factory",
":platform_options",
":toolchain_collection",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:exec_group",
"//src/main/java/com/google/devtools/build/lib/rules/config:feature_flag_value",
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi",
"//third_party:guava",
Expand Down Expand Up @@ -2152,6 +2154,7 @@ java_library(
":resolved_toolchain_context",
":starlark/starlark_toolchain_context",
":toolchain_collection",
"//src/main/java/com/google/devtools/build/lib/packages:exec_group",
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/platform",
"//src/main/java/net/starlark/java/eval",
"//src/main/java/net/starlark/java/syntax",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.packages.AspectClass;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.ExecGroup;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -97,7 +98,7 @@ public AspectClass getOwningAspect() {

/** Returns a {@link DependencyKind} for the given execution group. */
static DependencyKind forExecGroup(String execGroupName) {
if (ToolchainCollection.DEFAULT_EXEC_GROUP_NAME.equals(execGroupName)) {
if (ExecGroup.DEFAULT_EXEC_GROUP_NAME.equals(execGroupName)) {
return defaultExecGroupToolchain();
}
return new AutoValue_DependencyKind_ToolchainDependencyKind(execGroupName, false);
Expand All @@ -106,7 +107,7 @@ static DependencyKind forExecGroup(String execGroupName) {
/** Returns a {@link DependencyKind} for the default execution group. */
static DependencyKind defaultExecGroupToolchain() {
return new AutoValue_DependencyKind_ToolchainDependencyKind(
ToolchainCollection.DEFAULT_EXEC_GROUP_NAME, true);
ExecGroup.DEFAULT_EXEC_GROUP_NAME, true);
}

/** Predicate to check if a dependency represents a toolchain. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package com.google.devtools.build.lib.analysis;

import static com.google.devtools.build.lib.analysis.ToolchainCollection.DEFAULT_EXEC_GROUP_NAME;
import static com.google.devtools.build.lib.packages.ExecGroup.DEFAULT_EXEC_GROUP_NAME;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
import static com.google.common.collect.ImmutableSet.toImmutableSet;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.ExecGroup;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -34,15 +34,11 @@
@AutoValue
public abstract class ToolchainCollection<T extends ToolchainContext> {

// This is intentionally a string that would fail {@code Identifier.isValid} so that
// users can't create a group with the same name.
@VisibleForTesting public static final String DEFAULT_EXEC_GROUP_NAME = "default-exec-group";

/** A map of execution group names to toolchain contexts. */
public abstract ImmutableMap<String, T> getContextMap();

public T getDefaultToolchainContext() {
return getContextMap().get(DEFAULT_EXEC_GROUP_NAME);
return getContextMap().get(ExecGroup.DEFAULT_EXEC_GROUP_NAME);
}

public boolean hasToolchainContext(String execGroup) {
Expand Down Expand Up @@ -87,7 +83,7 @@ public static final class Builder<T extends ToolchainContext> {
private final Map<String, T> toolchainContexts = new HashMap<>();

public ToolchainCollection<T> build() {
Preconditions.checkArgument(toolchainContexts.containsKey(DEFAULT_EXEC_GROUP_NAME));
Preconditions.checkArgument(toolchainContexts.containsKey(ExecGroup.DEFAULT_EXEC_GROUP_NAME));
return new AutoValue_ToolchainCollection<T>(ImmutableMap.copyOf(toolchainContexts));
}

Expand All @@ -100,7 +96,7 @@ public void addContext(String execGroup, T context) {
}

public Builder<T> addDefaultContext(T context) {
addContext(DEFAULT_EXEC_GROUP_NAME, context);
addContext(ExecGroup.DEFAULT_EXEC_GROUP_NAME, context);
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package com.google.devtools.build.lib.analysis.actions;

import static com.google.devtools.build.lib.analysis.ToolchainCollection.DEFAULT_EXEC_GROUP_NAME;
import static com.google.devtools.build.lib.packages.ExecGroup.DEFAULT_EXEC_GROUP_NAME;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CharMatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.google.devtools.build.lib.analysis.config;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.devtools.build.lib.analysis.ToolchainCollection.DEFAULT_EXEC_GROUP_NAME;
import static com.google.devtools.build.lib.packages.ExecGroup.DEFAULT_EXEC_GROUP_NAME;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.analysis.starlark;

import static com.google.devtools.build.lib.analysis.ToolchainCollection.DEFAULT_EXEC_GROUP_NAME;
import static com.google.devtools.build.lib.packages.ExecGroup.DEFAULT_EXEC_GROUP_NAME;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/google/devtools/build/lib/packages/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi",
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.google.devtools.build.lib.packages;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.starlarkbuildapi.ExecGroupApi;
Expand All @@ -28,6 +29,10 @@ public abstract class ExecGroup implements ExecGroupApi {
public static final ExecGroup COPY_FROM_RULE_EXEC_GROUP =
createCopied(ImmutableSet.of(), ImmutableSet.of());

// This is intentionally a string that would fail {@code Identifier.isValid} so that
// users can't create a group with the same name.
@VisibleForTesting public static final String DEFAULT_EXEC_GROUP_NAME = "default-exec-group";

// Create an exec group that is marked as copying from the rule.
public static ExecGroup createCopied(
Set<Label> requiredToolchains, Set<Label> execCompatibleWith) {
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:test/analysis_failure_info",
"//src/main/java/com/google/devtools/build/lib/analysis:test/test_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:test/test_trimming_transition_factory",
"//src/main/java/com/google/devtools/build/lib/analysis:toolchain_collection",
"//src/main/java/com/google/devtools/build/lib/analysis:top_level_artifact_context",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:view_creation_failed_exception",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.google.devtools.build.lib.analysis;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.analysis.ToolchainCollection.DEFAULT_EXEC_GROUP_NAME;
import static com.google.devtools.build.lib.packages.ExecGroup.DEFAULT_EXEC_GROUP_NAME;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis/platform",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/cmdline:cmdline-primitives",
"//src/main/java/com/google/devtools/build/lib/packages:exec_group",
"//src/main/java/net/starlark/java/eval",
"//third_party:guava",
"//third_party:truth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.truth.IterableSubject;
import com.google.common.truth.Subject;
import com.google.devtools.build.lib.analysis.ToolchainCollection;
import com.google.devtools.build.lib.packages.ExecGroup;

/** A Truth {@link Subject} for {@link ToolchainCollection}. */
public class ToolchainCollectionSubject extends Subject {
Expand Down Expand Up @@ -51,7 +52,7 @@ private ToolchainCollectionSubject(

public void hasDefaultExecGroup() {
check("hasToolchainContext()")
.that(actual.hasToolchainContext(ToolchainCollection.DEFAULT_EXEC_GROUP_NAME))
.that(actual.hasToolchainContext(ExecGroup.DEFAULT_EXEC_GROUP_NAME))
.isTrue();
}

Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/google/devtools/build/lib/starlark/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/analysis:test/analysis_failure_info",
"//src/main/java/com/google/devtools/build/lib/analysis:test/analysis_test_result_info",
"//src/main/java/com/google/devtools/build/lib/analysis:test/instrumented_files_info",
"//src/main/java/com/google/devtools/build/lib/analysis:toolchain_collection",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_collection",
"//src/main/java/com/google/devtools/build/lib/analysis:view_creation_failed_exception",
"//src/main/java/com/google/devtools/build/lib/cmdline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.devtools.build.lib.analysis.ToolchainCollection.DEFAULT_EXEC_GROUP_NAME;
import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
import static com.google.devtools.build.lib.packages.ExecGroup.DEFAULT_EXEC_GROUP_NAME;
import static org.junit.Assert.assertThrows;

import com.google.common.base.Joiner;
Expand Down

0 comments on commit dc140d0

Please sign in to comment.