diff --git a/src/com/facebook/buck/distributed/AbstractDistBuildClientStats.java b/src/com/facebook/buck/distributed/AbstractDistBuildClientStats.java index 99bfbae1d5a..8fa4d62ac29 100644 --- a/src/com/facebook/buck/distributed/AbstractDistBuildClientStats.java +++ b/src/com/facebook/buck/distributed/AbstractDistBuildClientStats.java @@ -27,7 +27,7 @@ abstract class AbstractDistBuildClientStats { abstract boolean buckClientError(); - abstract String buildLabel(); + abstract String userOrInferredBuildLabel(); abstract String minionType(); diff --git a/src/com/facebook/buck/distributed/ClientStatsTracker.java b/src/com/facebook/buck/distributed/ClientStatsTracker.java index 56e67220f3b..fe6a956b912 100644 --- a/src/com/facebook/buck/distributed/ClientStatsTracker.java +++ b/src/com/facebook/buck/distributed/ClientStatsTracker.java @@ -93,14 +93,19 @@ public enum DistBuildClientStat { private volatile Optional buckClientErrorMessage = Optional.empty(); - private final String buildLabel; + private volatile String userOrInferredBuildLabel; + private final String minionType; - public ClientStatsTracker(String buildLabel, String minionType) { - this.buildLabel = buildLabel; + public ClientStatsTracker(String userOrInferredBuildLabel, String minionType) { + this.userOrInferredBuildLabel = userOrInferredBuildLabel; this.minionType = minionType; } + public void setUserOrInferredBuildLabel(String userOrInferredBuildLabel) { + this.userOrInferredBuildLabel = userOrInferredBuildLabel; + } + @GuardedBy("this") private void generateStatsPreconditionChecksNoException() { // Unless there was an exception, we expect all the following fields to be present. @@ -139,7 +144,7 @@ public synchronized DistBuildClientStats generateStats() { .setStampedeId(stampedeId) .setPerformedLocalBuild(performedLocalBuild) .setBuckClientError(buckClientError) - .setBuildLabel(buildLabel) + .setUserOrInferredBuildLabel(userOrInferredBuildLabel) .setMinionType(minionType); builder.setDistributedBuildExitCode(distributedBuildExitCode); diff --git a/src/com/facebook/buck/distributed/build_client/PreBuildPhase.java b/src/com/facebook/buck/distributed/build_client/PreBuildPhase.java index 86e811f0ca7..8886d268b23 100644 --- a/src/com/facebook/buck/distributed/build_client/PreBuildPhase.java +++ b/src/com/facebook/buck/distributed/build_client/PreBuildPhase.java @@ -69,7 +69,7 @@ public class PreBuildPhase { private final BuildExecutorArgs buildExecutorArgs; private final ImmutableSet topLevelTargets; private final ActionAndTargetGraphs actionAndTargetGraphs; - private final String buildLabel; + private volatile String buildLabel; public PreBuildPhase( DistBuildService distBuildService, @@ -119,6 +119,12 @@ public Pair> runPreDistBuildLocalStepsAsync( buildId, buildMode, minionRequirements, repository, tenantId, buildTargets, buildLabel); distBuildClientStats.stopTimer(CREATE_DISTRIBUTED_BUILD); + if (job.getBuildLabel() != null) { + // Override the build label with the server-side inferred label. + this.buildLabel = job.getBuildLabel(); + distBuildClientStats.setUserOrInferredBuildLabel(buildLabel); + } + StampedeId stampedeId = job.getStampedeId(); eventBus.post(new DistBuildCreatedEvent(stampedeId)); diff --git a/test/com/facebook/buck/distributed/ClientStatsTrackerTest.java b/test/com/facebook/buck/distributed/ClientStatsTrackerTest.java index c1ab76dd248..3be6165888d 100644 --- a/test/com/facebook/buck/distributed/ClientStatsTrackerTest.java +++ b/test/com/facebook/buck/distributed/ClientStatsTrackerTest.java @@ -84,6 +84,16 @@ public void testGenerateSucceedsWhenAllStandardStatsSet() { assertCommonStats(stats); } + @Test + public void testBuildLabelOverrideWorks() { + ClientStatsTracker tracker = new ClientStatsTracker(BUILD_LABEL, MINION_TYPE); + String newLabel = "this-label-is-better"; + tracker.setUserOrInferredBuildLabel(newLabel); + initializeCommonStats(tracker); + DistBuildClientStats stats = tracker.generateStats(); + Assert.assertEquals(newLabel, stats.userOrInferredBuildLabel()); + } + @Test(expected = java.lang.IllegalArgumentException.class) public void testGenerateFailsWhenLocalBuildButMissingLocalBuildFields() { ClientStatsTracker tracker = new ClientStatsTracker(BUILD_LABEL, MINION_TYPE); @@ -123,7 +133,7 @@ public void testGeneratesPartialResultWhenErrorButRequiredFields() { DISTRIBUTED_BUILD_EXIT_CODE, (long) stats.distributedBuildExitCode().getAsInt()); Assert.assertEquals(IS_LOCAL_FALLBACK_BUILD_ENABLED, stats.isLocalFallbackBuildEnabled().get()); Assert.assertEquals(BUCK_CLIENT_ERROR_MESSAGE, stats.buckClientErrorMessage().get()); - Assert.assertEquals(BUILD_LABEL, stats.buildLabel()); + Assert.assertEquals(BUILD_LABEL, stats.userOrInferredBuildLabel()); Assert.assertEquals(MINION_TYPE, stats.minionType()); Assert.assertTrue(stats.buckClientError());