Permit .afdo files to be passed in through the xbinary_fdo flag
This permits the xbinary_fdo flag to accept .xfdo and .afdo files. The BranchFdoMode is used to enable the appropriate feature. So, when BranchFdoMode == AUTO_FDO for .afdo files, it will enable the "autofdo" feature, and similarly for XFDO (as it does today).
PiperOrigin-RevId: 396838547
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java
index dbeac97..72067af 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java
@@ -169,11 +169,11 @@
branchFdoMode = BranchFdoMode.LLVM_CS_FDO;
}
}
- if (branchFdoMode != BranchFdoMode.XBINARY_FDO
+ if ((branchFdoMode != BranchFdoMode.XBINARY_FDO)
+ && (branchFdoMode != BranchFdoMode.AUTO_FDO)
&& cppConfiguration.getXFdoProfileLabelUnsafeSinceItCanReturnValueFromWrongConfiguration()
!= null) {
- ruleContext.throwWithRuleError(
- "--xbinary_fdo cannot accept profile input other than *.xfdo");
+ ruleContext.throwWithRuleError("--xbinary_fdo only accepts *.xfdo and *.afdo");
}
if (configuration.isCodeCoverageEnabled()) {
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java
index 475268e..5d30bc4 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java
@@ -477,15 +477,27 @@
}
@Test
- public void testXFdoOptimizeRejectAFdoInput() throws Exception {
+ public void testXFdoOptimizeAcceptAFdoInput() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file(
"a/BUILD",
"cc_toolchain_alias(name = 'b')",
"fdo_profile(name='out.afdo', profile='profile.afdo')");
useConfiguration("-c", "opt", "--xbinary_fdo=//a:out.afdo");
+ assertThat(getConfiguredTarget("//a:b")).isNotNull();
+ assertNoEvents();
+ }
+
+ @Test
+ public void testXFdoOptimizeRejectFdoInput() throws Exception {
+ reporter.removeHandler(failFastHandler);
+ scratch.file(
+ "a/BUILD",
+ "cc_toolchain_alias(name = 'b')",
+ "fdo_profile(name='out.fdo', profile='profile.profdata')");
+ useConfiguration("-c", "opt", "--xbinary_fdo=//a:out.fdo");
assertThat(getConfiguredTarget("//a:b")).isNull();
- assertContainsEvent("--xbinary_fdo cannot accept profile input other than *.xfdo");
+ assertContainsEvent("--xbinary_fdo only accepts");
}
@Test