diff --git a/base/src/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java b/base/src/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java index 28db0e578d9..c7f82a445db 100644 --- a/base/src/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java +++ b/base/src/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 The Bazel Authors. All rights reserved. + * Copyright 2025 The Bazel Authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import com.intellij.openapi.util.io.FileUtil; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Objects; @@ -93,6 +94,12 @@ public File decode(ArtifactLocation artifactLocation) { private @Nullable File tryToResolveExternalArtifactToMainWorkspace(ArtifactLocation artifactLocation) { if (artifactLocation.isExternal()) { try { + Path estimatedLocation = blazeInfo.getExecutionRoot().toPath().resolve(artifactLocation.getExecutionRootRelativePath()); + if (!Files.exists(estimatedLocation)) { + LOG.info("Cannot resolve " + estimatedLocation + " because it does not exist"); + return null; + } + File realFile = blazeInfo.getExecutionRoot().toPath() .resolve(artifactLocation.getExecutionRootRelativePath()).toRealPath().toFile(); if (pathResolver.getWorkspacePath(realFile) != null) { diff --git a/base/src/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolver.java b/base/src/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolver.java index 12fc7f38e3a..0b00c6f29e4 100644 --- a/base/src/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolver.java +++ b/base/src/com/google/idea/blaze/base/sync/workspace/ExecutionRootPathResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 The Bazel Authors. All rights reserved. + * Copyright 2025 The Bazel Authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,8 @@ import com.intellij.openapi.project.Project; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import javax.annotation.Nullable; import org.jetbrains.annotations.NotNull; @@ -158,14 +160,19 @@ public ImmutableList resolveToIncludeDirectories(ExecutionRootPath path) { public ImmutableList resolveToExternalWorkspaceWithSymbolicLinkResolution( ExecutionRootPath path) { File fileInExecutionRoot = path.getFileRootedAt(outputBase); - - try { - File realPath = fileInExecutionRoot.toPath().toRealPath().toFile(); - if (workspacePathResolver.getWorkspacePath(realPath) != null) { - return ImmutableList.of(realPath); + Path pathInExecutionRoot = fileInExecutionRoot.toPath(); + if (!Files.exists(pathInExecutionRoot)) { + LOG.info("Cannot resolve " + pathInExecutionRoot + " because it does not exist"); + } + else { + try { + File realPath = pathInExecutionRoot.toRealPath().toFile(); + if (workspacePathResolver.getWorkspacePath(realPath) != null) { + return ImmutableList.of(realPath); + } + } catch (IOException ioException) { + LOG.warn("Failed to resolve real path for " + fileInExecutionRoot, ioException); } - } catch (IOException ioException) { - LOG.warn("Failed to resolve real path for " + fileInExecutionRoot, ioException); } return ImmutableList.of(fileInExecutionRoot);