aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-02-06 13:57:20 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-06 13:59:03 -0800
commit53465cef1169d4e895bcc5e8bd50e77d75dc70b4 (patch)
tree9247822faecc52f5e1c62c7bf6f0a15986502258 /src
parente85e280645f579ffd5511a41553e95713c80177d (diff)
RELNOTES: Fix FDO_STAMP_MACRO to only be set when fdoBuildStamp is not null.
PiperOrigin-RevId: 184734801
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java1
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelperTest.java31
2 files changed, 31 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java
index 9b7ee60c60..dad73d3227 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java
@@ -87,7 +87,6 @@ public class CppLinkstampCompileHelper {
ImmutableList.<String>builder()
.add("GPLATFORM=\"" + cppConfiguration + "\"")
.add("BUILD_COVERAGE_ENABLED=" + (codeCoverageEnabled ? "1" : "0"))
- .add(CppConfiguration.FDO_STAMP_MACRO + "=\"" + fdoBuildStamp + "\"")
// G3_VERSION_INFO and G3_TARGET_NAME are C string literals that normally
// contain the label of the target being linked. However, they are set
// differently when using shared native deps. In that case, a single .so file
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelperTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelperTest.java
index 8082a7f85d..04014e80da 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelperTest.java
@@ -79,6 +79,10 @@ public class CppLinkstampCompileHelperTest extends BuildViewTestCase {
assertThat(Iterables.tryFind(arguments, (arg) -> arg.matches(correctG3BuildTargetPattern)))
.named("in " + arguments + " flag matching " + correctG3BuildTargetPattern)
.isPresent();
+ String fdoStampPattern = "-D" + CppConfiguration.FDO_STAMP_MACRO + "=\".*\"";
+ assertThat(Iterables.tryFind(arguments, (arg) -> arg.matches(fdoStampPattern)))
+ .named("in " + arguments + " flag matching " + fdoStampPattern)
+ .isAbsent();
}
/** Tests that linkstamp compilation applies expected command line options. */
@@ -144,4 +148,31 @@ public class CppLinkstampCompileHelperTest extends BuildViewTestCase {
(CppCompileAction) getGeneratingAction(compiledLinkstamp);
assertThat(linkstampCompileAction.getArguments()).contains("-fPIC");
}
+
+ @Test
+ public void testLinkstampRespectsFdoFromConfiguration() throws Exception {
+ useConfiguration("--fdo_instrument=foo");
+ scratch.file(
+ "x/BUILD",
+ "cc_binary(",
+ " name = 'foo',",
+ " deps = ['a'],",
+ ")",
+ "cc_library(",
+ " name = 'a',",
+ " srcs = [ 'a.cc' ],",
+ " linkstamp = 'ls.cc',",
+ ")");
+ ConfiguredTarget target = getConfiguredTarget("//x:foo");
+ Artifact executable = getExecutable(target);
+ CppLinkAction generatingAction = (CppLinkAction) getGeneratingAction(executable);
+ Artifact compiledLinkstamp =
+ ActionsTestUtil.getFirstArtifactEndingWith(generatingAction.getInputs(), "ls.o");
+ assertThat(generatingAction.getInputs()).contains(compiledLinkstamp);
+
+ CppCompileAction linkstampCompileAction =
+ (CppCompileAction) getGeneratingAction(compiledLinkstamp);
+ assertThat(linkstampCompileAction.getArguments())
+ .contains("-D" + CppConfiguration.FDO_STAMP_MACRO + "=\"FDO\"");
+ }
}