Skip to content

Commit

Permalink
Flip --incompatible_linkopts_in_user_link_flags
Browse files Browse the repository at this point in the history
Closes #6826.

This is a roll-forward of 4866f33 after Bazel with the flag was cut.

RELNOTES: Incompatible flag `--incompatible_linkopts_in_user_link_flags` has been flipped (#6826)
PiperOrigin-RevId: 233584729
  • Loading branch information
hlopko authored and Copybara-Service committed Feb 12, 2019
1 parent 68ea97d commit d62d294
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@
public class BazelRulesModule extends BlazeModule {
/** This is where deprecated options go to die. */
public static class GraveyardOptions extends OptionsBase {
@Option(
name = "incompatible_linkopts_in_user_link_flags",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES, OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
OptionMetadataTag.DEPRECATED,
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help = "Deprecated no-op.")
public boolean enableLinkoptsInUserLinkFlags;

@Option(
name = "incompatible_disable_runtimes_filegroups",
defaultValue = "false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,6 @@ public static String getLegacyCrosstoolFieldErrorMessage(String field) {
+ "migration instructions).";
}

public boolean enableLinkoptsInUserLinkFlags() {
return cppOptions.enableLinkoptsInUserLinkFlags;
}

public boolean disableEmittingStaticLibgcc() {
return cppOptions.disableEmittingStaticLibgcc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,16 +882,6 @@ public CppLinkAction build() throws InterruptedException {

CcToolchainVariables variables;
try {
ImmutableList<String> userLinkFlags;
if (cppConfiguration.enableLinkoptsInUserLinkFlags()) {
userLinkFlags =
ImmutableList.<String>builder()
.addAll(linkopts)
.addAll(cppConfiguration.getLinkopts())
.build();
} else {
userLinkFlags = ImmutableList.copyOf(linkopts);
}
variables =
LinkBuildVariables.setupVariables(
getLinkType().linkerOrArchiver().equals(LinkerOrArchiver.LINKER),
Expand All @@ -906,7 +896,10 @@ public CppLinkAction build() throws InterruptedException {
featureConfiguration,
useTestOnlyFlags,
isLtoIndexing,
userLinkFlags,
ImmutableList.<String>builder()
.addAll(linkopts)
.addAll(cppConfiguration.getLinkopts())
.build(),
toolchain.getInterfaceSoBuilder().getExecPathString(),
interfaceOutput != null ? interfaceOutput.getExecPathString() : null,
ltoOutputRootPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,21 +727,6 @@ public Label getFdoPrefetchHintsLabel() {
+ "(see https://github.com/bazelbuild/bazel/issues/7008 for migration instructions).")
public boolean disableExpandIfAllAvailableInFlagSet;

@Option(
name = "incompatible_linkopts_in_user_link_flags",
oldName = "experimental_linkopts_in_user_link_flags",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES, OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help =
"If true, flags coming from --linkopt Bazel option will appear in user_link_flags "
+ "crosstool variable, not in legacy_link_flags.")
public boolean enableLinkoptsInUserLinkFlags;

@Option(
name = "incompatible_dont_emit_static_libgcc",
oldName = "experimental_dont_emit_static_libgcc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,6 @@ private static ImmutableList<String> getToolchainFlags(
result.addAll(ccToolchainProvider.getTestOnlyLinkOptions());
}

if (!cppConfiguration.enableLinkoptsInUserLinkFlags()) {
result.addAll(cppConfiguration.getLinkopts());
}

// -pie is not compatible with shared and should be
// removed when the latter is part of the link command. Should we need to further
// distinguish between shared libraries and executables, we could add additional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,33 +460,9 @@ private Action getPredecessorByInputName(Action action, String str) {
return null;
}

@Test
public void testUserLinkFlags() throws Exception {
useConfiguration("--linkopt=-bar", "--noexperimental_linkopts_in_user_link_flags");

scratch.file("x/BUILD", "cc_binary(name = 'foo', srcs = ['a.cc'], linkopts = ['-foo'])");
scratch.file("x/a.cc");

ConfiguredTarget testTarget = getConfiguredTarget("//x:foo");
CcToolchainVariables testVariables =
getLinkBuildVariables(testTarget, LinkTargetType.EXECUTABLE);

ImmutableList<String> userLinkFlags =
CcToolchainVariables.toStringList(
testVariables, LinkBuildVariables.USER_LINK_FLAGS.getVariableName());
assertThat(userLinkFlags).contains("-foo");
assertThat(userLinkFlags).doesNotContain("-bar");

ImmutableList<String> legacyLinkFlags =
CcToolchainVariables.toStringList(
testVariables, LinkBuildVariables.LEGACY_LINK_FLAGS.getVariableName());
assertThat(legacyLinkFlags).doesNotContain("-foo");
assertThat(legacyLinkFlags).contains("-bar");
}

@Test
public void testUserLinkFlagsWithLinkoptOption() throws Exception {
useConfiguration("--linkopt=-bar", "--experimental_linkopts_in_user_link_flags");
useConfiguration("--linkopt=-bar");

scratch.file("x/BUILD", "cc_binary(name = 'foo', srcs = ['a.cc'], linkopts = ['-foo'])");
scratch.file("x/a.cc");
Expand Down

0 comments on commit d62d294

Please sign in to comment.