From 7911ac8a2b008bc670d8b2e2b3971b1b1a88a9a8 Mon Sep 17 00:00:00 2001 From: Erwin Waterlander Date: Mon, 5 Dec 2022 13:07:48 +0000 Subject: [PATCH] Bug 552070 - Build not configured correctly error while building a project https://bugs.eclipse.org/bugs/show_bug.cgi?id=552070 After closing and opening a Core Build project (Make, CMake, Autotools, and Meson), the project could not be built for Debug anymore. Error: "Build not configured correctly". Restoration of the debug build configurations failed, because the settings had been removed during closure of the project. CBuildConfiguration(IBuildConfiguration config, String name) failed with a CoreException. The CBuildConfigurationManager silently catched the exception and put the IBuildConfiguration for debug in the noConfigs list. --- .../cdt/core/build/CBuildConfiguration.java | 14 ++++++++++++++ .../core/build/CBuildConfigurationManager.java | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java index bef93ded743..9f38926a0ee 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java @@ -59,6 +59,7 @@ import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.internal.core.BuildRunnerHelper; import org.eclipse.cdt.internal.core.ConsoleOutputSniffer; +import org.eclipse.cdt.internal.core.build.CBuildConfigurationManager; import org.eclipse.cdt.internal.core.build.Messages; import org.eclipse.cdt.internal.core.model.BinaryRunner; import org.eclipse.cdt.internal.core.model.CModelManager; @@ -95,6 +96,19 @@ * Root class for CDT build configurations. Provides access to the build * settings for subclasses. * + * Each Eclipse project has one or more build configurations ({@link IBuildConfiguration}). + * A CDT Core Build project pairs each build configuration with a Core Build configuration + * ({@link ICBuildConfiguration}). A Core Build configuration has variable config pointing to + * the IBuildConfiguration. The link from IBuildConfiguration to ICBuildConfiguration + * goes via getAdapter(ICBuildConfiguration.class) which gets the ICBuildConfiguration + * from Map configs in the {@link CBuildConfigurationManager}. + * + * In a new project the initial Core Build configurations creation is triggered by the + * {@link CoreBuildLaunchBarTracker}. The initial configuration for Debug will only be + * created if the user selects the Debug launch mode. Restoration of Core Build configurations, + * after an Eclipse restart or close and open of the project, uses the settings which are + * persistently stored in the backing store. @see org.osgi.service.prefs.Preferences + * * @since 6.0 */ public abstract class CBuildConfiguration extends PlatformObject implements ICBuildConfiguration, ICBuildConfiguration2, diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java index ee279adc33f..b5a1f26e01b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java @@ -367,7 +367,12 @@ public void resourceChanged(IResourceChangeEvent event) { Preferences projectNode = parentNode.node(project.getName()); if (projectNode != null) { try { - projectNode.removeNode(); + if (event.getType() == IResourceChangeEvent.PRE_DELETE) { + // We need to keep the settings when the project is closed. They are used by + // CBuildConfiguration.CBuildConfiguration(IBuildConfiguration config, String name) + // to restore Debug core build configurations when the project is reopened. + projectNode.removeNode(); + } parentNode.flush(); } catch (BackingStoreException e) { CCorePlugin.log(e);