Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2017-11-20 15:09:26 -0500
committerDoug Schaefer2017-11-20 15:55:39 -0500
commita90655bc049f296b3e661e6aabd4ffe6bc6dd98d (patch)
tree348033258cf4f2dc690404a8ccc1d715163392bd
parentdc4be72b1ae13020fcbd8dbb46f8c6f9b9eb973b (diff)
downloadorg.eclipse.cdt-a90655bc049f296b3e661e6aabd4ffe6bc6dd98d.tar.gz
org.eclipse.cdt-a90655bc049f296b3e661e6aabd4ffe6bc6dd98d.tar.xz
org.eclipse.cdt-a90655bc049f296b3e661e6aabd4ffe6bc6dd98d.zip
Set CC and CXX variables to toolchain compileCommands in std build.
Also set BUILD_MODE to the launch mode so the makefile can do different things based on the mode. Change template to add -g option for debug. Also fix a deadlock I detected due to side affect build folder creation. Change-Id: Ic7b13ba3238e6ef201cccb1b2bfc8dcc6956ea3a
-rw-r--r--build/org.eclipse.cdt.make.core/templates/simple/Makefile6
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java45
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/StandardBuildConfiguration.java38
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java2
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties2
5 files changed, 75 insertions, 18 deletions
diff --git a/build/org.eclipse.cdt.make.core/templates/simple/Makefile b/build/org.eclipse.cdt.make.core/templates/simple/Makefile
index 404907713d..8214dabe9d 100644
--- a/build/org.eclipse.cdt.make.core/templates/simple/Makefile
+++ b/build/org.eclipse.cdt.make.core/templates/simple/Makefile
@@ -2,13 +2,17 @@ PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
OBJS = ${projectName}.o
+ifeq ($(BUILD_MODE),debug)
+ CFLAGS += -g
+endif
+
all: ${projectName}
${projectName}: $(OBJS)
$(CXX) -o $@ $^
%.o: $(PROJECT_ROOT)%.cpp
- $(CXX) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
+ $(CXX) -c $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
%.o: $(PROJECT_ROOT)%.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
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 8bd5cc76e6..425c791895 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
@@ -68,12 +68,11 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.osgi.util.NLS;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
@@ -127,9 +126,9 @@ public abstract class CBuildConfiguration extends PlatformObject
null));
}
}
- toolChain = tc;
+ this.toolChain = tc;
- launchMode = settings.get(LAUNCH_MODE, "run"); //$NON-NLS-1$
+ this.launchMode = settings.get(LAUNCH_MODE, "run"); //$NON-NLS-1$
}
protected CBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
@@ -204,18 +203,28 @@ public abstract class CBuildConfiguration extends PlatformObject
}
public IContainer getBuildContainer() throws CoreException {
- // TODO should really be passing a monitor in here or create this in
- // a better spot. should also throw the core exception
// TODO make the name of this folder a project property
- IProgressMonitor monitor = new NullProgressMonitor();
IProject project = getProject();
IFolder buildRootFolder = project.getFolder("build"); //$NON-NLS-1$
- if (!buildRootFolder.exists()) {
- buildRootFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
- }
IFolder buildFolder = buildRootFolder.getFolder(name);
- if (!buildFolder.exists()) {
- buildFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
+
+ if (!buildRootFolder.exists() || !buildFolder.exists()) {
+ new Job(Messages.CBuildConfiguration_CreateJob) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ if (!buildRootFolder.exists()) {
+ buildRootFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
+ }
+ if (!buildFolder.exists()) {
+ buildFolder.create(IResource.FORCE | IResource.DERIVED, true, monitor);
+ }
+ return Status.OK_STATUS;
+ } catch (CoreException e) {
+ return e.getStatus();
+ }
+ }
+ }.schedule();
}
return buildFolder;
@@ -308,7 +317,14 @@ public abstract class CBuildConfiguration extends PlatformObject
@Override
public IEnvironmentVariable getVariable(String name) {
- // By default, none
+ IEnvironmentVariable[] vars = getVariables();
+ if (vars != null) {
+ for (IEnvironmentVariable var : vars) {
+ if (var.getName().equals(name)) {
+ return var;
+ }
+ }
+ }
return null;
}
@@ -377,8 +393,7 @@ public abstract class CBuildConfiguration extends PlatformObject
URI uri = URIUtil.toURI(externalLocation);
if (uri.getScheme() != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, externalLocation);
- String locationText = NLS.bind(
- CCorePlugin.getResourceString("ACBuilder.ProblemsView.Location"), //$NON-NLS-1$
+ String locationText = String.format(Messages.CBuildConfiguration_Location,
problemMarkerInfo.lineNumber, externalLocation);
marker.setAttribute(IMarker.LOCATION, locationText);
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/StandardBuildConfiguration.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/StandardBuildConfiguration.java
index 3919f34371..a012f8c780 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/StandardBuildConfiguration.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/StandardBuildConfiguration.java
@@ -19,6 +19,10 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ConsoleOutputStream;
import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.IConsoleParser;
+import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
+import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
+import org.eclipse.cdt.core.envvar.EnvironmentVariable;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.core.build.Messages;
@@ -59,15 +63,18 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
private String[] buildCommand;
private String[] cleanCommand;
private IContainer buildContainer;
+ private IEnvironmentVariable[] envVars;
public StandardBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
super(config, name);
applyProperties();
+ setupEnvVars();
}
public StandardBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
- String launchMode) {
- super(config, name, toolChain);
+ String launchMode) throws CoreException {
+ super(config, name, toolChain, launchMode);
+ setupEnvVars();
}
private void applyProperties() {
@@ -92,6 +99,33 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
}
}
+ private void setupEnvVars() throws CoreException {
+ IToolChain toolchain = getToolChain();
+ List<IEnvironmentVariable> vars = new ArrayList<>();
+
+ String[] cc = toolchain.getCompileCommands(GCCLanguage.getDefault());
+ if (cc != null && cc.length > 0) {
+ vars.add(new EnvironmentVariable("CC", cc[0])); //$NON-NLS-1$
+ }
+
+ String[] cxx = toolchain.getCompileCommands(GPPLanguage.getDefault());
+ if (cxx != null && cxx.length > 0) {
+ vars.add(new EnvironmentVariable("CXX", cxx[0])); //$NON-NLS-1$
+ }
+
+ String mode = getLaunchMode();
+ if (mode != null && !mode.isEmpty()) {
+ vars.add(new EnvironmentVariable("BUILD_MODE", mode)); //$NON-NLS-1$
+ }
+
+ envVars = vars.toArray(new IEnvironmentVariable[0]);
+ }
+
+ @Override
+ public IEnvironmentVariable[] getVariables() {
+ return envVars;
+ }
+
public void setBuildContainer(IContainer buildContainer) {
this.buildContainer = buildContainer;
setProperty(BUILD_CONTAINER, buildContainer.getFullPath().toString());
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java
index d6481fe739..0e517dcdf8 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java
@@ -11,7 +11,9 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.build.Messages"; //$NON-NLS-1$
+ public static String CBuildConfiguration_CreateJob;
public static String CBuildConfiguration_ToolchainMissing;
+ public static String CBuildConfiguration_Location;
public static String CBuilder_ExceptionWhileBuilding;
public static String CBuilder_ExceptionWhileBuilding2;
public static String CBuilder_NotConfiguredCorrectly;
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties
index 0483412de3..84de49bcac 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties
@@ -11,4 +11,6 @@ CBuilder_NotConfiguredCorrectly=Build not configured correctly\n
CBuilder_NotConfiguredCorrectly2=Build not configured correctly\n
StandardBuildConfiguration_0=Building in: %s\n
StandardBuildConfiguration_1=Build complete: %s\n
+CBuildConfiguration_CreateJob=Create Build Folder
+CBuildConfiguration_Location=line %d, external location: %s
CBuildConfiguration_ToolchainMissing=Toolchain is missing for build configuration

Back to the top