Skip to content

Commit

Permalink
Resolve canonical repos from external folder (bzlmod)
Browse files Browse the repository at this point in the history
  • Loading branch information
guw committed Feb 22, 2024
1 parent 82f5782 commit 888bcd3
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package com.salesforce.bazel.eclipse.core.model.discovery;

import static java.lang.String.format;
import static java.nio.file.Files.exists;
import static java.util.stream.Collectors.toList;
import static org.eclipse.core.runtime.IPath.forPosix;
import static org.eclipse.core.runtime.IPath.fromPath;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -379,7 +381,33 @@ public Collection<ClasspathEntry> compute() throws CoreException {
}

private BazelWorkspace findExternalWorkspace(Label label) throws CoreException {
var externalRepository = bazelWorkspace.getExternalRepository(label.externalWorkspaceName());
var externalWorkspaceName = label.externalWorkspaceName();
if (externalWorkspaceName.startsWith("@")) {
// we have a canonical repository name; try to see if it links to workspace in the IDE
// IJ does similar thing: https://github.com/bazelbuild/intellij/blob/8b64eb559811a803e07bc07c278168f3607c0f50/base/src/com/google/idea/blaze/base/sync/workspace/WorkspaceHelper.java#L169-L184
try {
var externalWorkspacePath =
getBlazeInfo().getOutputBase().resolve("external").resolve(externalWorkspaceName.substring(1));
if (exists(externalWorkspacePath)) {
var path = fromPath(externalWorkspacePath.toRealPath());
var externalWorkspace = bazelWorkspace.getParent().getBazelWorkspace(path);
if (externalWorkspace.exists()) {
return externalWorkspace;
}
}
} catch (IOException e) {
throw new CoreException(
Status.error(
format(
"Error while resolving canonical repository name '%s': %s",
externalWorkspaceName.substring(1),
e.getMessage()),
e));
}
}

// lookup and see if it maps to 'local_repository'
var externalRepository = bazelWorkspace.getExternalRepository(externalWorkspaceName);
if (externalRepository != null) {
switch (externalRepository.getRuleClass()) {
case "local_repository": {
Expand All @@ -398,6 +426,8 @@ private BazelWorkspace findExternalWorkspace(Label label) throws CoreException {
}
}
}

LOG.debug("External workspace '{}' not found in current IDE workspace.", externalWorkspaceName);
return null;
}

Expand Down

0 comments on commit 888bcd3

Please sign in to comment.