Post a new build event ConvenienceSymlinksIdentifiedEvent.
The event is posted whenever symlinks are created or deleted. However, if user passes in --experimental_convenience_symlink=ignore, then symlinks will not be created or deleted and the BuildEvent will not be posted.
The new flag --experimental_convenience_symlinks_bep_event will determine whether or not the new build event ConvenienceSymlinksIdentified will be posted. By default the value is false, which will be the same functionality as prior to the adding of the new event. If the value is set to true, the build event ConvenienceSymlinksIdentified will be posted with the managed symlinks.
RELNOTES: Post new ConvenienceSymlinksIdentifiedEvent to the BuildEventProtocol when --experimental_convenience_symlinks_bep_event is enabled.
PiperOrigin-RevId: 287584669
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
index 3c0a311..9119264 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
@@ -47,6 +47,9 @@
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
+import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.ConvenienceSymlink;
+import com.google.devtools.build.lib.buildtool.BuildRequestOptions.ConvenienceSymlinksMode;
+import com.google.devtools.build.lib.buildtool.buildevent.ConvenienceSymlinksIdentifiedEvent;
import com.google.devtools.build.lib.buildtool.buildevent.ExecRootPreparedEvent;
import com.google.devtools.build.lib.buildtool.buildevent.ExecutionPhaseCompleteEvent;
import com.google.devtools.build.lib.buildtool.buildevent.ExecutionStartingEvent;
@@ -251,7 +254,7 @@
createActionLogDirectory();
}
- createConvenienceSymlinks(request.getBuildOptions(), analysisResult);
+ handleConvenienceSymlinks(analysisResult);
ActionCache actionCache = getActionCache();
actionCache.resetStatistics();
@@ -464,6 +467,23 @@
}
/**
+ * Handles what action to perform on the convenience symlinks. If the the mode is {@link
+ * ConvenienceSymlinksMode.IGNORE}, then skip any creating or cleaning of convenience symlinks.
+ * Otherwise, manage the convenience symlinks and then post a {@link
+ * ConvenienceSymlinksIdentifiedEvent} build event.
+ */
+ private void handleConvenienceSymlinks(AnalysisResult analysisResult) {
+ ImmutableList<ConvenienceSymlink> convenienceSymlinks = ImmutableList.of();
+ if (request.getBuildOptions().experimentalConvenienceSymlinks
+ != ConvenienceSymlinksMode.IGNORE) {
+ convenienceSymlinks = createConvenienceSymlinks(request.getBuildOptions(), analysisResult);
+ }
+ if (request.getBuildOptions().experimentalConvenienceSymlinksBepEvent) {
+ env.getEventBus().post(new ConvenienceSymlinksIdentifiedEvent(convenienceSymlinks));
+ }
+ }
+
+ /**
* Creates convenience symlinks based on the target configurations.
*
* <p>Exactly what target configurations we consider depends on the value of {@code
@@ -476,7 +496,7 @@
* path the symlink should point to, it gets created; otherwise, the symlink is not created, and
* in fact gets removed if it was already present from a previous invocation.
*/
- private void createConvenienceSymlinks(
+ private ImmutableList<ConvenienceSymlink> createConvenienceSymlinks(
BuildRequestOptions buildRequestOptions, AnalysisResult analysisResult) {
SkyframeExecutor executor = env.getSkyframeExecutor();
Reporter reporter = env.getReporter();
@@ -494,16 +514,14 @@
analysisResult.getConfigurationCollection().getTargetConfigurations());
String productName = runtime.getProductName();
- String workspaceName = env.getWorkspaceName();
try (SilentCloseable c =
Profiler.instance().profile("OutputDirectoryLinksUtils.createOutputDirectoryLinks")) {
- OutputDirectoryLinksUtils.createOutputDirectoryLinks(
+ return OutputDirectoryLinksUtils.createOutputDirectoryLinks(
runtime.getRuleClassProvider().getSymlinkDefinitions(),
buildRequestOptions,
- workspaceName,
+ env.getWorkspaceName(),
env.getWorkspace(),
- env.getDirectories().getExecRoot(workspaceName),
- env.getDirectories().getOutputPath(workspaceName),
+ env.getDirectories(),
getReporter(),
targetConfigurations,
options -> getConfiguration(executor, reporter, options),