Skip to content

Commit

Permalink
Introduce --incompatible_disable_nocopts flag
Browse files Browse the repository at this point in the history
This flag prohibits the use of 'nocopts' attribute in cc_* rules.

Issue bazelbuild#8706

RELNOTES: --incompatible_disable_nocopts flag has been added. See bazelbuild#8706 for details.
PiperOrigin-RevId: 254781400
  • Loading branch information
scentini authored and siberex committed Jul 4, 2019
1 parent 97025be commit 520d765
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,14 @@ private static Pattern getNoCoptsPattern(RuleContext ruleContext) {
if (Strings.isNullOrEmpty(nocoptsValue)) {
return null;
}

if (ruleContext.getConfiguration().getFragment(CppConfiguration.class).disableNoCopts()) {
ruleContext.attributeError(
NO_COPTS_ATTRIBUTE,
"This attribute was removed. See https://github.com/bazelbuild/bazel/issues/8706 for"
+ " details.");
}

String nocoptsAttr = ruleContext.getExpander().expand(NO_COPTS_ATTRIBUTE, nocoptsValue);
try {
return Pattern.compile(nocoptsAttr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,8 @@ public boolean useStandaloneLtoIndexingCommandLines() {
public boolean useSpecificToolFiles() {
return cppOptions.useSpecificToolFiles;
}

public boolean disableNoCopts() {
return cppOptions.disableNoCopts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,20 @@ public Label getFdoPrefetchHintsLabel() {
+ "See https://github.com/bazelbuild/bazel/issues/8546.")
public boolean disableStaticCcToolchains;

@Option(
name = "incompatible_disable_nocopts",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES,
},
help =
"When enabled, it removes nocopts attribute from C++ rules. See"
+ " https://github.com/bazelbuild/bazel/issues/8706 for details.")
public boolean disableNoCopts;

@Override
public FragmentOptions getHost() {
CppOptions host = (CppOptions) getDefault();
Expand Down Expand Up @@ -959,6 +973,7 @@ public FragmentOptions getHost() {
host.useStandaloneLtoIndexingCommandLines = useStandaloneLtoIndexingCommandLines;
host.useSpecificToolFiles = useSpecificToolFiles;
host.disableStaticCcToolchains = disableStaticCcToolchains;
host.disableNoCopts = disableNoCopts;

// Save host options for further use.
host.hostCoptList = hostCoptList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1060,4 +1060,15 @@ public void testCompilationParameterFile() throws Exception {
private String removeOutDirectory(String s) {
return s.replace("blaze-out", "").replace("bazel-out", "");
}

@Test
public void testNoCoptsDisabled() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'], nocopts = 'abc')");
useConfiguration("--incompatible_disable_nocopts");
getConfiguredTarget("//x:foo");
assertContainsEvent(
"This attribute was removed. See https://github.com/bazelbuild/bazel/issues/8706 for"
+ " details.");
}
}

0 comments on commit 520d765

Please sign in to comment.