Create the convenience symlinks only after the build, and only those that point to an existing directory.

This required fixing the worker strategy so that it reads params files not through said convenience symlinks, but from the execroot.

--
MOS_MIGRATED_REVID=112682485
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 60ca6a5..213a973 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
@@ -326,7 +326,7 @@
    * @param buildId UUID of the build id
    * @param analysisResult the analysis phase output
    * @param buildResult the mutable build result
-   * @param packageRoots package roots collected from loading phase and BuildConfigutaionCollection
+   * @param packageRoots package roots collected from loading phase and BuildConfigurationCollection
    * creation
    */
   void executeBuild(UUID buildId, AnalysisResult analysisResult,
@@ -342,21 +342,6 @@
     // Get top-level artifacts.
     ImmutableSet<Artifact> additionalArtifacts = analysisResult.getAdditionalArtifactsToBuild();
 
-    // Create symlinks only after we've verified that we're actually
-    // supposed to build something.
-    if (getWorkspace().getFileSystem().supportsSymbolicLinks()) {
-      List<BuildConfiguration> targetConfigurations = configurations.getTargetConfigurations();
-      // TODO(bazel-team): This is not optimal - we retain backwards compatibility in the case where
-      // there's only a single configuration, but we don't create any symlinks in the multi-config
-      // case. Can we do better? [multi-config]
-      if (targetConfigurations.size() == 1) {
-        OutputDirectoryLinksUtils.createOutputDirectoryLinks(
-            runtime.getWorkspaceName(), getWorkspace(), getExecRoot(),
-            runtime.getOutputPath(), getReporter(), targetConfigurations.get(0),
-            request.getBuildOptions().getSymlinkPrefix());
-      }
-    }
-
     OutputService outputService = env.getOutputService();
     ModifiedFileSet modifiedOutputFiles = ModifiedFileSet.EVERYTHING_MODIFIED;
     if (outputService != null) {
@@ -450,6 +435,21 @@
       }
       if (buildCompleted) {
         getReporter().handle(Event.progress("Building complete."));
+
+        // Create symlinks only after we've actually built something so that we don't create
+        // dangling symlinks.
+        if (getWorkspace().getFileSystem().supportsSymbolicLinks()) {
+          List<BuildConfiguration> targetConfigurations = configurations.getTargetConfigurations();
+          // TODO(bazel-team): This is not optimal - we retain backwards compatibility in the case
+          // where there's only a single configuration, but we don't create any symlinks in the
+          // multi-config case. Can we do better? [multi-config]
+          if (targetConfigurations.size() == 1) {
+            OutputDirectoryLinksUtils.createOutputDirectoryLinks(
+                runtime.getWorkspaceName(), getWorkspace(), getExecRoot(),
+                runtime.getOutputPath(), getReporter(), targetConfigurations.get(0),
+                request.getBuildOptions().getSymlinkPrefix());
+          }
+        }
       }
 
       env.getEventBus().post(new ExecutionFinishedEvent(ImmutableMap.<String, Long> of(), 0L,