mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Qt - better handling when a Qt install hasn't been added.
Used to NPE, now prints a message on the build console at build time. Change-Id: Ia38161dcc393506e44d4c4fa7e12a25f55e44bd0
This commit is contained in:
parent
095dd5160e
commit
e7ef5fb9ac
5 changed files with 40 additions and 14 deletions
|
@ -0,0 +1,15 @@
|
||||||
|
package org.eclipse.cdt.internal.qt.core;
|
||||||
|
|
||||||
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
|
public class Messages extends NLS {
|
||||||
|
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.qt.core.messages"; //$NON-NLS-1$
|
||||||
|
public static String QtBuilder_0;
|
||||||
|
static {
|
||||||
|
// initialize resource bundle
|
||||||
|
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Messages() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -107,10 +107,12 @@ public class QtBuildConfigurationFactory implements IAdapterFactory {
|
||||||
// return it if it exists already
|
// return it if it exists already
|
||||||
for (IBuildConfiguration config : project.getBuildConfigs()) {
|
for (IBuildConfiguration config : project.getBuildConfigs()) {
|
||||||
QtBuildConfiguration qtConfig = config.getAdapter(QtBuildConfiguration.class);
|
QtBuildConfiguration qtConfig = config.getAdapter(QtBuildConfiguration.class);
|
||||||
IQtInstall qtInstall = qtConfig.getQtInstall();
|
if (qtConfig != null) {
|
||||||
if (qtInstall != null && qtInstallManager.supports(qtInstall, target)
|
IQtInstall qtInstall = qtConfig.getQtInstall();
|
||||||
&& launchMode.equals(qtConfig.getLaunchMode())) {
|
if (qtInstall != null && qtInstallManager.supports(qtInstall, target)
|
||||||
return qtConfig;
|
&& launchMode.equals(qtConfig.getLaunchMode())) {
|
||||||
|
return qtConfig;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Map;
|
||||||
import org.eclipse.cdt.build.core.IConsoleService;
|
import org.eclipse.cdt.build.core.IConsoleService;
|
||||||
import org.eclipse.cdt.build.core.IToolChain;
|
import org.eclipse.cdt.build.core.IToolChain;
|
||||||
import org.eclipse.cdt.internal.qt.core.Activator;
|
import org.eclipse.cdt.internal.qt.core.Activator;
|
||||||
|
import org.eclipse.cdt.internal.qt.core.Messages;
|
||||||
import org.eclipse.cdt.qt.core.QtBuildConfiguration;
|
import org.eclipse.cdt.qt.core.QtBuildConfiguration;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -37,6 +38,11 @@ public class QtBuilder extends IncrementalProjectBuilder {
|
||||||
try {
|
try {
|
||||||
IConsoleService console = Activator.getService(IConsoleService.class);
|
IConsoleService console = Activator.getService(IConsoleService.class);
|
||||||
QtBuildConfiguration qtConfig = getBuildConfig().getAdapter(QtBuildConfiguration.class);
|
QtBuildConfiguration qtConfig = getBuildConfig().getAdapter(QtBuildConfiguration.class);
|
||||||
|
if (qtConfig == null) {
|
||||||
|
// Qt hasn't been configured yet print a message and bale
|
||||||
|
console.writeError(Messages.QtBuilder_0);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
IToolChain toolChain = qtConfig.getToolChain();
|
IToolChain toolChain = qtConfig.getToolChain();
|
||||||
|
|
||||||
Path buildDir = qtConfig.getBuildDirectory();
|
Path buildDir = qtConfig.getBuildDirectory();
|
||||||
|
@ -50,7 +56,7 @@ public class QtBuilder extends IncrementalProjectBuilder {
|
||||||
command.add(config);
|
command.add(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
IFile projectFile = qtConfig.getProject().getFile("main.pro");
|
IFile projectFile = qtConfig.getProject().getFile("main.pro"); //$NON-NLS-1$
|
||||||
command.add(projectFile.getLocation().toOSString());
|
command.add(projectFile.getLocation().toOSString());
|
||||||
|
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
|
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
|
||||||
|
@ -68,14 +74,14 @@ public class QtBuilder extends IncrementalProjectBuilder {
|
||||||
// run make
|
// run make
|
||||||
// TODO obviously hardcoding here
|
// TODO obviously hardcoding here
|
||||||
boolean isWin = Platform.getOS().equals(Platform.OS_WIN32);
|
boolean isWin = Platform.getOS().equals(Platform.OS_WIN32);
|
||||||
String make = isWin ? "C:/Qt/Tools/mingw492_32/bin/mingw32-make" : "make";
|
String make = isWin ? "C:/Qt/Tools/mingw492_32/bin/mingw32-make" : "make"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
ProcessBuilder procBuilder = new ProcessBuilder(make).directory(buildDir.toFile());
|
ProcessBuilder procBuilder = new ProcessBuilder(make).directory(buildDir.toFile());
|
||||||
if (isWin) {
|
if (isWin) {
|
||||||
// Need to put the toolchain into env
|
// Need to put the toolchain into env
|
||||||
Map<String, String> env = procBuilder.environment();
|
Map<String, String> env = procBuilder.environment();
|
||||||
String path = env.get("PATH");
|
String path = env.get("PATH"); //$NON-NLS-1$
|
||||||
path = "C:/Qt/Tools/mingw492_32/bin;" + path;
|
path = "C:/Qt/Tools/mingw492_32/bin;" + path; //$NON-NLS-1$
|
||||||
env.put("PATH", path);
|
env.put("PATH", path); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
toolChain.setEnvironment(procBuilder.environment());
|
toolChain.setEnvironment(procBuilder.environment());
|
||||||
Process process = procBuilder.start();
|
Process process = procBuilder.start();
|
||||||
|
@ -85,7 +91,7 @@ public class QtBuilder extends IncrementalProjectBuilder {
|
||||||
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
|
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
|
||||||
return new IProject[] { project };
|
return new IProject[] { project };
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, Activator.ID, "Building " + project.getName(), e));
|
throw new CoreException(new Status(IStatus.ERROR, Activator.ID, "Building " + project.getName(), e)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
QtBuilder_0=Error: Qt has not been configured.\nPlease add a Qt install in the Qt preferences page.\n
|
|
@ -24,10 +24,12 @@ public abstract class QtLaunchConfigurationDelegate extends LaunchConfigurationT
|
||||||
QtBuildConfiguration qtBuildConfig = getQtBuildConfiguration(configuration, mode, target, monitor);
|
QtBuildConfiguration qtBuildConfig = getQtBuildConfiguration(configuration, mode, target, monitor);
|
||||||
|
|
||||||
// Set it as active
|
// Set it as active
|
||||||
IProject project = qtBuildConfig.getProject();
|
if (qtBuildConfig != null) {
|
||||||
IProjectDescription desc = project.getDescription();
|
IProject project = qtBuildConfig.getProject();
|
||||||
desc.setActiveBuildConfig(qtBuildConfig.getBuildConfiguration().getName());
|
IProjectDescription desc = project.getDescription();
|
||||||
project.setDescription(desc, monitor);
|
desc.setActiveBuildConfig(qtBuildConfig.getBuildConfiguration().getName());
|
||||||
|
project.setDescription(desc, monitor);
|
||||||
|
}
|
||||||
|
|
||||||
// And build
|
// And build
|
||||||
return superBuildForLaunch(configuration, mode, monitor);
|
return superBuildForLaunch(configuration, mode, monitor);
|
||||||
|
|
Loading…
Add table
Reference in a new issue