1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Support project scanner info in new build system for new class wiz.

The New Class Wizard asks scanner info for include paths for a project.
Need to decide whether that's a good thing or not but for now, add
support in the Qt config and GCC toolchain for it.

Change-Id: I5f037deb13db41fc0a083ea9fdc30ac1f61557e6
This commit is contained in:
Doug Schaefer 2016-02-08 14:09:56 -05:00 committed by Gerrit Code Review @ Eclipse.org
parent 345877d034
commit 44599764f0
2 changed files with 29 additions and 16 deletions

View file

@ -10,7 +10,6 @@ package org.eclipse.cdt.build.gcc.core;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@ -32,6 +31,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
@ -151,23 +151,26 @@ public class GCCToolChain implements IToolChain {
if (files.length > 0) {
// replace it with a temp file
Path parentPath = filePath.getParent();
int n = 0;
while (true) {
// TODO need to know the language
tmpFile = parentPath.resolve(".sc" + n + ".cpp"); //$NON-NLS-1$ //$NON-NLS-2$
commandLine.set(i, tmpFile.toString());
try {
Files.createFile(tmpFile);
break;
} catch (FileAlreadyExistsException e) {
// try again
++n;
}
String extension = files[0].getFileExtension();
if (extension == null) {
// Not sure if this is a reasonable choice when there's
// no extension
extension = ".cpp"; //$NON-NLS-1$
} else {
extension = '.' + extension;
}
break;
tmpFile = Files.createTempFile(parentPath, ".sc", extension); //$NON-NLS-1$
commandLine.set(i, tmpFile.toString());
}
}
}
if (tmpFile == null) {
// Have to assume there wasn't a source file. Add one in the
// resource's container
IPath parentPath = resource instanceof IFile ? resource.getParent().getLocation() : resource.getLocation();
tmpFile = Files.createTempFile(parentPath.toFile().toPath(), ".sc", ".cpp"); //$NON-NLS-1$ //$NON-NLS-2$
commandLine.add(tmpFile.toString());
}
Files.createDirectories(buildDirectory);

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.internal.qt.core.Activator;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
@ -208,7 +209,16 @@ public class QtBuildConfiguration extends CBuildConfiguration {
args.addAll(Arrays.asList(getProperty("QMAKE_CXXFLAGS").split(" "))); //$NON-NLS-1$ //$NON-NLS-2$
args.add("-o"); //$NON-NLS-1$
args.add("-"); //$NON-NLS-1$
args.add(resource.getLocation().toString());
String srcFile;
if (resource instanceof IFile) {
srcFile = resource.getLocation().toOSString();
// Only add file if it's an IFile
args.add(srcFile);
} else {
// Doesn't matter, the toolchain will create a tmp file for this
srcFile = "scannerInfo.cpp"; //$NON-NLS-1$
}
String[] includePaths = getProperty("INCLUDEPATH").split(" "); //$NON-NLS-1$ //$NON-NLS-2$
for (int i = 0; i < includePaths.length; ++i) {
@ -219,7 +229,7 @@ public class QtBuildConfiguration extends CBuildConfiguration {
}
ILanguage language = LanguageManager.getInstance()
.getLanguage(CCorePlugin.getContentType(getProject(), resource.getName()), getProject()); // $NON-NLS-1$
.getLanguage(CCorePlugin.getContentType(getProject(), srcFile), getProject()); // $NON-NLS-1$
Path dir = Paths.get(getProject().getLocationURI());
IExtendedScannerInfo extendedInfo = getToolChain().getScannerInfo(command, args,
Arrays.asList(includePaths), resource, dir);