Skip to content

Commit

Permalink
Add --incompatible_use_cc_configure_from_rules_cc
Browse files Browse the repository at this point in the history
In this cl only add the flag. Installing the calls to
__do_not_use_fail_with_incompatible_use_cc_configure_from_rules_cc will be done
in a followup cl.

Progress towards #10134.

RELNOTES: None.
PiperOrigin-RevId: 280649623
  • Loading branch information
hlopko authored and copybara-github committed Nov 15, 2019
1 parent ae1cf49 commit 23f052f
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ public Object call(
@Override
public void failWithIncompatibleUseCcConfigureFromRulesCc(
Location location, StarlarkThread thread) throws EvalException {
// Noop until --incompatible_use_cc_configure_from_rules_cc is implemented.
if (thread.getSemantics().incompatibleUseCcConfigureFromRulesCc()) {
throw new EvalException(
location,
"Incompatible flag "
+ "--incompatible_use_cc_configure_from_rules_cc has been flipped. Please use "
+ "cc_configure and related logic from https://github.com/bazelbuild/rules_cc. "
+ "See https://github.com/bazelbuild/bazel/issues/10134 for details and migration "
+ "instructions.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses;
import com.google.devtools.build.lib.bazel.rules.sh.BazelShRuleClasses;
import com.google.devtools.build.lib.remote.options.RemoteOptions;
import com.google.devtools.build.lib.rules.cpp.CcSkyframeFdoSupportFunction;
Expand Down Expand Up @@ -413,11 +412,10 @@ public static class GraveyardOptions extends OptionsBase {
public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) {
builder.setToolsRepository(BazelRuleClassProvider.TOOLS_REPOSITORY);
BazelRuleClassProvider.setup(builder);

try {
// Load auto-configuration files, it is made outside of the rule class provider so that it
// will not be loaded for our Java tests.
builder.addWorkspaceFileSuffix(
ResourceFileLoader.loadResource(BazelCppRuleClasses.class, "cc_configure.WORKSPACE"));
builder.addWorkspaceFileSuffix(
ResourceFileLoader.loadResource(BazelRulesModule.class, "xcode_configure.WORKSPACE"));
builder.addWorkspaceFileSuffix(
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/google/devtools/build/lib/metrics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib:build-base",
"//src/main/java/com/google/devtools/build/lib:runtime",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/buildeventstream",
"//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto",
"//src/main/java/com/google/devtools/common/options",
"//third_party:guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,21 @@ public class StarlarkSemanticsOptions extends OptionsBase implements Serializabl
+ "See https://github.com/bazelbuild/bazel/issues/7670 for details.")
public boolean incompatibleDoNotSplitLinkingCmdline;

@Option(
name = "incompatible_use_cc_configure_from_rules_cc",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help =
"When true, Bazel will no longer allow using cc_configure from @bazel_tools. "
+ "Please see https://github.com/bazelbuild/bazel/issues/10134 for details and "
+ "migration instructions.")
public boolean incompatibleUseCcConfigureFromRulesCc;

@Option(
name = "incompatible_restrict_named_params",
defaultValue = "true",
Expand Down Expand Up @@ -652,6 +667,7 @@ public StarlarkSemantics toSkylarkSemantics() {
incompatibleVisibilityPrivateAttributesAtDefinition)
.internalSkylarkFlagTestCanary(internalSkylarkFlagTestCanary)
.incompatibleDoNotSplitLinkingCmdline(incompatibleDoNotSplitLinkingCmdline)
.incompatibleUseCcConfigureFromRulesCc(incompatibleUseCcConfigureFromRulesCc)
.incompatibleDepsetForLibrariesToLinkGetter(incompatibleDepsetForLibrariesToLinkGetter)
.incompatibleRestrictStringEscapes(incompatibleRestrictStringEscapes)
.incompatibleDisallowDictLookupUnhashableKeys(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Table;
import com.google.devtools.build.lib.analysis.PlatformConfiguration;
import com.google.devtools.build.lib.analysis.PlatformOptions;
Expand Down Expand Up @@ -521,10 +522,24 @@ private static String formatError(
/** Exception used when a toolchain type is required but no matching toolchain is found. */
static final class UnresolvedToolchainsException extends ToolchainException {
UnresolvedToolchainsException(List<Label> missingToolchainTypes) {
super(
String.format(
"no matching toolchains found for types %s",
missingToolchainTypes.stream().map(Label::toString).collect(joining(", "))));
super(getMessage(missingToolchainTypes));
}

private static String getMessage(List<Label> missingToolchainTypes) {
if (missingToolchainTypes.size() == 1
&& Iterables.getOnlyElement(missingToolchainTypes)
.toString()
.equals("@bazel_tools//tools/cpp:toolchain_type")) {
return "No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. "
+ "Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there "
+ "is no default C++ toolchain added in the WORKSPACE file? See "
+ "https://github.com/bazelbuild/bazel/issues/10134 for details and migration "
+ "instructions.";
}

return String.format(
"no matching toolchains found for types %s",
missingToolchainTypes.stream().map(Label::toString).collect(joining(", ")));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.syntax.ParserInput;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.StarlarkFile;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import com.google.devtools.build.lib.syntax.Statement;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -106,11 +107,37 @@ public SkyValue compute(SkyKey skyKey, Environment env)
throw resolvedValueError("Failed to parse WORKSPACE file");
}
}

StarlarkSemantics starlarkSemantics = PrecomputedValue.STARLARK_SEMANTICS.get(env);
if (env.valuesMissing()) {
return null;
}
String suffix;
if (resolvedFile.isPresent()) {
suffix = "";
} else if (starlarkSemantics == null) {
// Starlark semantics was not found, but Skyframe is happy. That means we're in the test
// that didn't provide complete Skyframe environment. Just move along.
suffix = ruleClassProvider.getDefaultWorkspaceSuffix();
// TODO(hlopko): Uncomment once Bazel tests pass with --all_incompatible_changes
// } else if (starlarkSemantics.incompatibleUseCcConfigureFromRulesCc()) {
// suffix = ruleClassProvider.getDefaultWorkspaceSuffix();
} else if (!ruleClassProvider.getDefaultWorkspaceSuffix().contains("sh_configure")) {
// It might look fragile to check for sh_configure in the WORKSPACE file, but it turns
// out its the best approximation. The problem is that some tests want the ruleClassProvider
// together with logic from BazelRulesModule, some tests only want the
// BazelRuleClassProvider and some only a subset of that.
suffix = ruleClassProvider.getDefaultWorkspaceSuffix();
} else {
suffix =
ruleClassProvider.getDefaultWorkspaceSuffix()
+ "\nload('@bazel_tools//tools/cpp:cc_configure.bzl', 'cc_configure')\n\n"
+ "cc_configure()";
}

file =
StarlarkFile.parseWithPrelude(
ParserInput.create(
resolvedFile.isPresent() ? "" : ruleClassProvider.getDefaultWorkspaceSuffix(),
PathFragment.create("/DEFAULT.WORKSPACE.SUFFIX")),
ParserInput.create(suffix, PathFragment.create("/DEFAULT.WORKSPACE.SUFFIX")),
file.getStatements());
if (!file.ok()) {
Event.replayEventsOn(env.getListener(), file.errors());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public boolean flagValue(FlagIdentifier flagIdentifier) {

public abstract boolean experimentalAllowTagsPropagation();

public abstract boolean incompatibleUseCcConfigureFromRulesCc();

@Memoized
@Override
public abstract int hashCode();
Expand Down Expand Up @@ -281,6 +283,7 @@ public static Builder builderWithDefaults() {
.incompatibleDepsetForLibrariesToLinkGetter(true)
.incompatibleRestrictStringEscapes(false)
.incompatibleDisallowDictLookupUnhashableKeys(false)
.incompatibleUseCcConfigureFromRulesCc(false)
.build();

/** Builder for {@link StarlarkSemantics}. All fields are mandatory. */
Expand Down Expand Up @@ -368,6 +371,8 @@ public abstract static class Builder {

public abstract Builder incompatibleDisallowDictLookupUnhashableKeys(boolean value);

public abstract Builder incompatibleUseCcConfigureFromRulesCc(boolean value);

public abstract StarlarkSemantics build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ private static StarlarkSemanticsOptions buildRandomOptions(Random rand) throws E
"--incompatible_visibility_private_attributes_at_definition=" + rand.nextBoolean(),
"--incompatible_restrict_string_escapes=" + rand.nextBoolean(),
"--incompatible_disallow_dict_lookup_unhashable_keys=" + rand.nextBoolean(),
"--incompatible_use_cc_configure_from_rules_cc=" + rand.nextBoolean(),
"--internal_skylark_flag_test_canary=" + rand.nextBoolean());
}

Expand Down Expand Up @@ -210,6 +211,7 @@ private static StarlarkSemantics buildRandomSemantics(Random rand) {
.incompatibleVisibilityPrivateAttributesAtDefinition(rand.nextBoolean())
.incompatibleRestrictStringEscapes(rand.nextBoolean())
.incompatibleDisallowDictLookupUnhashableKeys(rand.nextBoolean())
.incompatibleUseCcConfigureFromRulesCc(rand.nextBoolean())
.internalSkylarkFlagTestCanary(rand.nextBoolean())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ private SkyFunction.Environment getEnv() throws InterruptedException {
Mockito.when(
env.getValue(MockitoHamcrest.argThat(new SkyKeyMatchers(SkyFunctions.PRECOMPUTED))))
.thenReturn(new PrecomputedValue(Optional.<RootedPath>absent()));
Mockito.when(
env.getValue(
MockitoHamcrest.argThat(
new SkyKeyMatchers(SkyFunctions.PRECOMPUTED) {
@Override
public boolean matches(Object item) {
return super.matches(item)
&& item.toString().equals("PRECOMPUTED:skylark_semantics");
}
})))
.thenReturn(null);
return env;
}

Expand Down

0 comments on commit 23f052f

Please sign in to comment.