aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/rules/cpp
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2018-07-19 11:34:51 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-19 11:36:29 -0700
commitcfa35f3750d1ae37935bdf402a0cee306672795b (patch)
tree06037f6f8eef8edeeb6d63841dfa70415b8e23d1 /src/test/java/com/google/devtools/build/lib/rules/cpp
parent866fda697b21a6aa129cd7513ec7638bc2ddd43d (diff)
Move --linkopt flags into user_link_flags
Previous behavior was to put flags coming from Bazel option --linkopt into legacy_link_flags. They should be in user_link_flags instead (together with flags coming from linkopts rule attribute). This cl introduces --experimental_linkopts_in_user_link_flags option that flips the behavior. There is another incompatible change. Previously cc_common.create_link_variables() included flags from --linkopt, with the flag flipped it doesn't anymore. I believe --linkopt flags shouldn't be there by default because: * We don't tie the API with the specifics of C++ rules/options, enabling theoretical use with other languages (objc) * Users are free to use ctx.fragments.cpp to access C++ options and add them explicitly (https://github.com/bazelbuild/bazel/issues/5602) * New behavior maintains the symmetry with --copt and user_compile_flags RELNOTES: None. PiperOrigin-RevId: 205274272
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/cpp')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java
index cabbb2da82..cffef0494c 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.rules.cpp;
import static com.google.common.truth.Truth.assertThat;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.Artifact;
@@ -367,4 +368,51 @@ public class LinkBuildVariablesTest extends LinkBuildVariablesTestCase {
}
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");
+
+ 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).containsAllOf("-foo", "-bar").inOrder();
+
+ ImmutableList<String> legacyLinkFlags =
+ CcToolchainVariables.toStringList(
+ testVariables, LinkBuildVariables.LEGACY_LINK_FLAGS.getVariableName());
+ assertThat(legacyLinkFlags).doesNotContain("-foo");
+ assertThat(legacyLinkFlags).doesNotContain("-bar");
+ }
}