30
30
import com .google .common .util .concurrent .ListeningScheduledExecutorService ;
31
31
import com .google .common .util .concurrent .MoreExecutors ;
32
32
import com .google .common .util .concurrent .ThreadFactoryBuilder ;
33
+ import com .google .devtools .build .lib .actions .ActionAnalysisMetadata ;
33
34
import com .google .devtools .build .lib .actions .ActionExecutionMetadata ;
34
35
import com .google .devtools .build .lib .actions .ActionGraph ;
35
36
import com .google .devtools .build .lib .actions .ActionInput ;
111
112
import java .util .concurrent .LinkedBlockingQueue ;
112
113
import java .util .concurrent .ThreadFactory ;
113
114
import java .util .concurrent .ThreadPoolExecutor ;
115
+ import javax .annotation .Nullable ;
114
116
115
117
/** RemoteModule provides distributed cache and remote execution for Bazel. */
116
118
public final class RemoteModule extends BlazeModule {
@@ -126,7 +128,7 @@ public final class RemoteModule extends BlazeModule {
126
128
127
129
private RemoteActionContextProvider actionContextProvider ;
128
130
private RemoteActionInputFetcher actionInputFetcher ;
129
- private RemoteOutputsMode remoteOutputsMode ;
131
+ private RemoteOptions remoteOptions ;
130
132
private RemoteOutputService remoteOutputService ;
131
133
132
134
private ChannelFactory channelFactory =
@@ -244,15 +246,15 @@ private void initHttpAndDiskCache(
244
246
public void beforeCommand (CommandEnvironment env ) throws AbruptExitException {
245
247
Preconditions .checkState (actionContextProvider == null , "actionContextProvider must be null" );
246
248
Preconditions .checkState (actionInputFetcher == null , "actionInputFetcher must be null" );
247
- Preconditions .checkState (remoteOutputsMode == null , "remoteOutputsMode must be null" );
249
+ Preconditions .checkState (remoteOptions == null , "remoteOptions must be null" );
248
250
249
251
RemoteOptions remoteOptions = env .getOptions ().getOptions (RemoteOptions .class );
250
252
if (remoteOptions == null ) {
251
253
// Quit if no supported command is being used. See getCommandOptions for details.
252
254
return ;
253
255
}
254
256
255
- remoteOutputsMode = remoteOptions . remoteOutputsMode ;
257
+ this . remoteOptions = remoteOptions ;
256
258
257
259
AuthAndTLSOptions authAndTlsOptions = env .getOptions ().getOptions (AuthAndTLSOptions .class );
258
260
DigestHashFunction hashFn = env .getRuntime ().getFileSystem ().getDigestFunction ();
@@ -705,8 +707,8 @@ public void afterAnalysis(
705
707
AnalysisResult analysisResult ) {
706
708
// The actionContextProvider may be null if remote execution is disabled or if there was an
707
709
// error during initialization.
708
- if (remoteOutputsMode != null
709
- && remoteOutputsMode .downloadToplevelOutputsOnly ()
710
+ if (remoteOptions != null
711
+ && remoteOptions . remoteOutputsMode .downloadToplevelOutputsOnly ()
710
712
&& actionContextProvider != null ) {
711
713
boolean isTestCommand = env .getCommandName ().equals ("test" );
712
714
TopLevelArtifactContext artifactContext = request .getTopLevelArtifactContext ();
@@ -726,6 +728,41 @@ public void afterAnalysis(
726
728
}
727
729
actionContextProvider .setFilesToDownload (ImmutableSet .copyOf (filesToDownload ));
728
730
}
731
+
732
+ if (remoteOptions != null && remoteOptions .incompatibleRemoteBuildEventUploadRespectNoCache ) {
733
+ parseNoCacheOutputs (analysisResult );
734
+ }
735
+ }
736
+
737
+ private void parseNoCacheOutputs (AnalysisResult analysisResult ) {
738
+ if (actionContextProvider == null || actionContextProvider .getRemoteCache () == null ) {
739
+ return ;
740
+ }
741
+
742
+ ByteStreamBuildEventArtifactUploader uploader = buildEventArtifactUploaderFactoryDelegate .get ();
743
+ if (uploader == null ) {
744
+ return ;
745
+ }
746
+
747
+ for (ConfiguredTarget configuredTarget : analysisResult .getTargetsToBuild ()) {
748
+ if (configuredTarget instanceof RuleConfiguredTarget ) {
749
+ RuleConfiguredTarget ruleConfiguredTarget = (RuleConfiguredTarget ) configuredTarget ;
750
+ for (ActionAnalysisMetadata action : ruleConfiguredTarget .getActions ()) {
751
+ boolean uploadLocalResults =
752
+ RemoteExecutionService .shouldUploadLocalResults (
753
+ remoteOptions , action .getExecutionInfo ());
754
+ if (!uploadLocalResults ) {
755
+ for (Artifact output : action .getOutputs ()) {
756
+ if (output .isTreeArtifact ()) {
757
+ uploader .omitTree (output .getPath ());
758
+ } else {
759
+ uploader .omitFile (output .getPath ());
760
+ }
761
+ }
762
+ }
763
+ }
764
+ }
765
+ }
729
766
}
730
767
731
768
// This is a short-term fix for top-level outputs that are symlinks. Unfortunately, we cannot
@@ -829,7 +866,7 @@ public void afterCommand() throws AbruptExitException {
829
866
remoteDownloaderSupplier .set (null );
830
867
actionContextProvider = null ;
831
868
actionInputFetcher = null ;
832
- remoteOutputsMode = null ;
869
+ remoteOptions = null ;
833
870
remoteOutputService = null ;
834
871
835
872
if (failure != null ) {
@@ -873,7 +910,7 @@ public void registerActionContexts(
873
910
@ Override
874
911
public void executorInit (CommandEnvironment env , BuildRequest request , ExecutorBuilder builder ) {
875
912
Preconditions .checkState (actionInputFetcher == null , "actionInputFetcher must be null" );
876
- Preconditions .checkNotNull (remoteOutputsMode , "remoteOutputsMode must not be null" );
913
+ Preconditions .checkNotNull (remoteOptions , "remoteOptions must not be null" );
877
914
878
915
if (actionContextProvider == null ) {
879
916
return ;
@@ -897,7 +934,7 @@ public void executorInit(CommandEnvironment env, BuildRequest request, ExecutorB
897
934
@ Override
898
935
public OutputService getOutputService () {
899
936
Preconditions .checkState (remoteOutputService == null , "remoteOutputService must be null" );
900
- if (remoteOutputsMode != null && !remoteOutputsMode .downloadAllOutputs ()) {
937
+ if (remoteOptions != null && !remoteOptions . remoteOutputsMode .downloadAllOutputs ()) {
901
938
remoteOutputService = new RemoteOutputService ();
902
939
}
903
940
return remoteOutputService ;
@@ -913,13 +950,21 @@ public Iterable<Class<? extends OptionsBase>> getCommandOptions(Command command)
913
950
private static class BuildEventArtifactUploaderFactoryDelegate
914
951
implements BuildEventArtifactUploaderFactory {
915
952
916
- private volatile BuildEventArtifactUploaderFactory uploaderFactory ;
953
+ @ Nullable private ByteStreamBuildEventArtifactUploaderFactory uploaderFactory ;
917
954
918
- public void init (BuildEventArtifactUploaderFactory uploaderFactory ) {
955
+ public void init (ByteStreamBuildEventArtifactUploaderFactory uploaderFactory ) {
919
956
Preconditions .checkState (this .uploaderFactory == null );
920
957
this .uploaderFactory = uploaderFactory ;
921
958
}
922
959
960
+ @ Nullable
961
+ public ByteStreamBuildEventArtifactUploader get () {
962
+ if (uploaderFactory == null ) {
963
+ return null ;
964
+ }
965
+ return uploaderFactory .get ();
966
+ }
967
+
923
968
public void reset () {
924
969
this .uploaderFactory = null ;
925
970
}
0 commit comments