Skip to content

Commit

Permalink
make import fail if Bazel build fails (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
plaird authored Oct 14, 2021
1 parent 8e442a5 commit 0ca13a5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ public void closeBazelWorkspace() {
// now forget about the workspace
bazelWorkspace = null;
bazelWorkspaceCommandRunner = null;
configurationManager.setBazelWorkspacePath(null);
}

// TEST ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,23 @@ public void run(ImportContext ctx, SubMonitor progressMonitor) {
try {
Map<BazelLabel, Set<AspectTargetInfo>> targetInfos =
bazelWorkspaceCmdRunner.getAspectTargetInfos(labels, "importWorkspace");

if (targetInfos.isEmpty()) {
BazelPluginActivator.getInstance().closeBazelWorkspace();
throw new IllegalStateException(
"Bazel could not provide any information about the selected project(s). "
+ "This usually means there is a Bazel build error in the underlying packages being imported.\n\n"
+ "Please run a command line build for these packages to verify they build correctly.");
}

List<AspectTargetInfo> allTargetInfos = new ArrayList<>();
for (Set<AspectTargetInfo> targetTargetInfos : targetInfos.values()) {
allTargetInfos.addAll(targetTargetInfos);
}
ctx.setAspectTargetInfos(new AspectTargetInfos(allTargetInfos));
} catch (RuntimeException e) {
// the error dialog looks better if we dont wrap the exception, so dont do it unless we have to
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.jface.preference.IPreferenceStore;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;

import com.salesforce.bazel.eclipse.BazelPluginActivator;
Expand Down Expand Up @@ -138,6 +139,12 @@ public Preferences getProjectBazelPreferences(IProject project) {
LOG.error("Could not find the Preferences node for the Bazel plugin for project [{}]", project.getName());
}

try {
eclipseProjectPrefs.sync();
} catch (BackingStoreException bse) {
LOG.error("Could not read Eclipse preferences for project [{}]", project.getName(), bse);
}

return eclipseProjectPrefs;
}

Expand Down Expand Up @@ -279,7 +286,7 @@ public void createFolderLink(IFolder thisFolder, IPath bazelWorkspaceLocation, i
IProgressMonitor monitor) {
try {
LOG.debug("createFolderLink: thisFolder=" + thisFolder.getLocation().toOSString()
+ " bazelWorkspaceLocation=" + bazelWorkspaceLocation.toOSString());
+ " bazelWorkspaceLocation=" + bazelWorkspaceLocation.toOSString());
thisFolder.createLink(bazelWorkspaceLocation, updateFlags, monitor);
} catch (Exception anyE) {
throw new IllegalArgumentException(anyE);
Expand Down

0 comments on commit 0ca13a5

Please sign in to comment.