aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2017-09-05 18:12:26 +0200
committerGravatar Yun Peng <pcloudy@google.com>2017-09-06 10:10:06 +0200
commit268c0bcbf79f9f3f72d95fa51af0f1b18c5ce29e (patch)
tree45bf496a5de6652214a7a06001390ab87bd1f6ee /src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java
parent87f40973c52e3323abe8a2e850296026671cb6ad (diff)
Introduce unfiltered_compile_flags build variable, rename copts variable to user_compile_flags
Also add magic to a feature named 'unfiltered_compile_flags' so the flags expanded from it are not subject to nocopt filtering. RELNOTES: None. PiperOrigin-RevId: 167587189
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java
index 97abeeb722..f481f0aa3b 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java
@@ -16,7 +16,6 @@ package com.google.devtools.build.lib.rules.cpp;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Root;
@@ -26,6 +25,7 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfig
import com.google.devtools.build.lib.rules.cpp.CompileCommandLine.Builder;
import com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile;
import java.io.IOException;
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -97,6 +97,47 @@ public class CompileCommandLineTest extends BuildViewTestCase {
.contains("-some_foo_flag");
}
+ @Test
+ public void testUnfilteredFlagsAreNotFiltered() throws Exception {
+ List<String> actualCommandLine =
+ getCompileCommandLineWithCoptsFilter(CppRuleClasses.UNFILTERED_COMPILE_FLAGS_FEATURE_NAME);
+ assertThat(actualCommandLine).contains("-i_am_a_flag");
+ }
+
+ @Test
+ public void testNonUnfilteredFlagsAreFiltered() throws Exception {
+ List<String> actualCommandLine = getCompileCommandLineWithCoptsFilter("filtered_flags");
+ assertThat(actualCommandLine).doesNotContain("-i_am_a_flag");
+ }
+
+ private List<String> getCompileCommandLineWithCoptsFilter(String featureName) throws Exception {
+ CompileCommandLine compileCommandLine =
+ makeCompileCommandLineBuilder()
+ .setFeatureConfiguration(
+ getMockFeatureConfiguration(
+ "",
+ "action_config {",
+ " config_name: 'c++-compile'",
+ " action_name: 'c++-compile'",
+ " implies: '" + featureName + "'",
+ " tool {",
+ " tool_path: 'foo/bar/DUMMY_COMPILER'",
+ " }",
+ "}",
+ "feature {",
+ " name: '" + featureName + "'",
+ " flag_set {",
+ " action: 'c++-compile'",
+ " flag_group {",
+ " flag: '-i_am_a_flag'",
+ " }",
+ " }",
+ "}"))
+ .setCoptsFilter(flag -> !flag.contains("i_am_a_flag"))
+ .build();
+ return compileCommandLine.getArgv(scratchArtifact("a/FakeOutput").getExecPath(), null);
+ }
+
private Builder makeCompileCommandLineBuilder() throws Exception {
ConfiguredTarget dummyTarget =
scratchConfiguredTarget("a", "a", "cc_binary(name='a', srcs=['a.cc'])");
@@ -110,7 +151,6 @@ public class CompileCommandLineTest extends BuildViewTestCase {
return true;
}
},
- ImmutableList.<String>of(),
"c++-compile",
getTargetConfiguration().getFragment(CppConfiguration.class),
new DotdFile(scratchArtifact("a/dotD")),