1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixes for scanner info for Makefile projects.

Using ESP-IDF (the ESP32 FreeRTOS SDK) on MSYS2 as a test bed.
Making sure the indexer picks up as much as it can. Removed -j
since that messes up build output parsing. Add UI so you can put
it back if you want.

Change-Id: I767c739dce1412c75fb56d0bb1efceb913883a5f
This commit is contained in:
Doug Schaefer 2017-11-10 10:28:36 -05:00
parent 45019ea780
commit b7b1d41f08
7 changed files with 162 additions and 24 deletions

View file

@ -321,10 +321,13 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
if (tmpFile == null) {
// Have to assume there wasn't a source file. Add one in the
// resource's container
// TODO really?
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());
if (parentPath.toFile().exists()) {
tmpFile = Files.createTempFile(parentPath.toFile().toPath(), ".sc", ".cpp"); //$NON-NLS-1$ //$NON-NLS-2$
commandLine.add(tmpFile.toString());
}
}
return getScannerInfo(buildConfig, commandLine, buildDirectory, tmpFile);
@ -490,7 +493,8 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
if (cCommand.contains("gcc")) { //$NON-NLS-1$
cppCommand = cCommand.replace("gcc", "g++"); //$NON-NLS-1$ //$NON-NLS-2$
// Also recognize c++ as an alias for g++
commands = new String[] { cCommand, cppCommand, cCommand.replace("gcc", "c++"), "cc", "c++" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
commands = new String[] { cCommand, cppCommand, cCommand.replace("gcc", "cc"), //$NON-NLS-1$ //$NON-NLS-2$
cCommand.replace("gcc", "c++") }; //$NON-NLS-1$ //$NON-NLS-2$
} else if (cCommand.contains("clang")) { //$NON-NLS-1$
cppCommand = cCommand.replace("clang", "clang++"); //$NON-NLS-1$ //$NON-NLS-2$
commands = new String[] { cCommand, cppCommand };
@ -533,12 +537,23 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
// ran into an option, we're done.
break;
}
if (i > 1 && cmd.get(i - 1).equals("-o")) { //$NON-NLS-1$
// this is an output file
--i;
continue;
}
try {
Path srcPath = Paths.get(arg);
URI uri;
if (srcPath.isAbsolute()) {
uri = srcPath.toUri();
} else {
if (arg.startsWith("/") && Platform.getOS().equals(Platform.OS_WIN32)) { //$NON-NLS-1$
String drive = srcPath.getName(0).toString();
if (drive.length() == 1) {
srcPath = Paths.get(drive + ":\\").resolve(srcPath.subpath(1, srcPath.getNameCount())); //$NON-NLS-1$
}
}
uri = Paths.get(buildDirectoryURI).resolve(srcPath).toUri().normalize();
}

View file

@ -30,8 +30,8 @@ public class NewGCCToolChainWizard extends ToolChainWizard {
@Override
public boolean performFinish() {
Path path = settingsPage.getPath();
String os = settingsPage.getOS();
String arch = settingsPage.getArch();
String os = settingsPage.getOS().trim();
String arch = settingsPage.getArch().trim();
IEnvironmentVariable[] envvars = envPage.getEnvVars();
new Job(Messages.NewGCCToolChainWizard_Add) {
@ -47,7 +47,9 @@ public class NewGCCToolChainWizard extends ToolChainWizard {
}
GCCToolChain gcc = new GCCToolChain(provider, path, arch, envvars);
gcc.setProperty(IToolChain.ATTR_OS, os);
if (!os.isEmpty()) {
gcc.setProperty(IToolChain.ATTR_OS, os);
}
provider.addToolChain(gcc);
return Status.OK_STATUS;
} catch (CoreException e) {

View file

@ -25,11 +25,15 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class MakeBuildSettingsTab extends CommonBuildTab {
private Button projectButton;
private Button configButton;
private Text buildCmdText;
private Text cleanCmdText;
private boolean defaultProject;
@ -49,18 +53,35 @@ public class MakeBuildSettingsTab extends CommonBuildTab {
tcControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
// Build Output Group
Group group = new Group(comp, SWT.NONE);
group.setText("Build Output Location");
group.setLayout(new GridLayout());
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Group outputGroup = new Group(comp, SWT.NONE);
outputGroup.setText("Build Output Location");
outputGroup.setLayout(new GridLayout());
outputGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
projectButton = new Button(group, SWT.RADIO);
projectButton = new Button(outputGroup, SWT.RADIO);
projectButton.setText("Build in project directory");
projectButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
configButton = new Button(group, SWT.RADIO);
configButton = new Button(outputGroup, SWT.RADIO);
configButton.setText("Build in configuration specific folder");
configButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Group cmdGroup = new Group(comp, SWT.NONE);
cmdGroup.setText("Build Commands");
cmdGroup.setLayout(new GridLayout(2, false));
cmdGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label label = new Label(cmdGroup, SWT.NONE);
label.setText("Build:");
buildCmdText = new Text(cmdGroup, SWT.BORDER);
buildCmdText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
label = new Label(cmdGroup, SWT.NONE);
label.setText("Clean:");
cleanCmdText = new Text(cmdGroup, SWT.BORDER);
cleanCmdText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
}
@Override
@ -85,6 +106,16 @@ public class MakeBuildSettingsTab extends CommonBuildTab {
defaultProject = false;
}
}
String buildCommand = properties.get(StandardBuildConfiguration.BUILD_COMMAND);
if (buildCommand != null && !buildCommand.trim().isEmpty()) {
buildCmdText.setText(buildCommand);
}
String cleanCommand = properties.get(StandardBuildConfiguration.CLEAN_COMMAND);
if (cleanCommand != null && !cleanCommand.trim().isEmpty()) {
cleanCmdText.setText(cleanCommand);
}
}
@Override
@ -102,6 +133,16 @@ public class MakeBuildSettingsTab extends CommonBuildTab {
properties.put(StandardBuildConfiguration.BUILD_CONTAINER,
stdConfig.getProject().getFullPath().toString());
}
String buildCommand = buildCmdText.getText().trim();
if (!buildCommand.isEmpty()) {
properties.put(StandardBuildConfiguration.BUILD_COMMAND, buildCommand);
}
String cleanCommand = cleanCmdText.getText().trim();
if (!cleanCommand.isEmpty()) {
properties.put(StandardBuildConfiguration.CLEAN_COMMAND, cleanCommand);
}
}
} catch (CoreException e) {
MakeUIPlugin.log(e.getStatus());
@ -125,6 +166,16 @@ public class MakeBuildSettingsTab extends CommonBuildTab {
defaultProject = false;
}
}
String buildCommand = buildConfig.getProperty(StandardBuildConfiguration.BUILD_COMMAND);
if (buildCommand != null && !buildCommand.trim().isEmpty()) {
buildCmdText.setText(buildCommand);
}
String cleanCommand = buildConfig.getProperty(StandardBuildConfiguration.CLEAN_COMMAND);
if (cleanCommand != null && !cleanCommand.trim().isEmpty()) {
cleanCmdText.setText(cleanCommand);
}
}
@Override
@ -140,6 +191,16 @@ public class MakeBuildSettingsTab extends CommonBuildTab {
} else if (!defaultProject && projectButton.getSelection()) {
stdConfig.setBuildContainer(stdConfig.getProject());
}
String buildCommand = buildCmdText.getText().trim();
if (!buildCommand.isEmpty()) {
stdConfig.setBuildCommand(buildCommand.split(" ")); //$NON-NLS-1$
}
String cleanCommand = cleanCmdText.getText().trim();
if (!cleanCommand.isEmpty()) {
stdConfig.setCleanCommand(cleanCommand.split(" ")); //$NON-NLS-1$
}
}
} catch (CoreException e) {
MakeUIPlugin.log(e.getStatus());

View file

@ -75,11 +75,23 @@
</filter>
</resource>
<resource path="src/org/eclipse/cdt/core/build/StandardBuildConfiguration.java" type="org.eclipse.cdt.core.build.StandardBuildConfiguration">
<filter id="336658481">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.StandardBuildConfiguration"/>
<message_argument value="BUILD_COMMAND"/>
</message_arguments>
</filter>
<filter comment="No one extends this yet." id="336658481">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.StandardBuildConfiguration"/>
<message_argument value="BUILD_CONTAINER"/>
</message_arguments>
</filter>
<filter id="336658481">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.StandardBuildConfiguration"/>
<message_argument value="CLEAN_COMMAND"/>
</message_arguments>
</filter>
</resource>
</component>

View file

@ -674,6 +674,7 @@ public abstract class CBuildConfiguration extends PlatformObject
// Make sure it's a compile command
String[] compileCommands = toolChain.getCompileCommands();
boolean found = false;
loop:
for (String arg : command) {
// TODO we should really ask the toolchain, not all args start with '-'
@ -685,9 +686,26 @@ public abstract class CBuildConfiguration extends PlatformObject
for (String cc : compileCommands) {
if (arg.endsWith(cc)
&& (arg.equals(cc) || arg.endsWith("/" + cc) || arg.endsWith("\\" + cc))) { //$NON-NLS-1$ //$NON-NLS-2$
found = true;
break loop;
}
}
if (Platform.getOS().equals(Platform.OS_WIN32) && !arg.endsWith(".exe")) { //$NON-NLS-1$
// Try with exe
arg = arg + ".exe"; //$NON-NLS-1$
for (String cc : compileCommands) {
if (arg.endsWith(cc)
&& (arg.equals(cc) || arg.endsWith("/" + cc) || arg.endsWith("\\" + cc))) { //$NON-NLS-1$ //$NON-NLS-2$
found = true;
break loop;
}
}
}
}
if (!found) {
return false;
}
try {

View file

@ -47,6 +47,14 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
* @since 6.4
*/
public static final String BUILD_CONTAINER = "stdbuild.build.container"; //$NON-NLS-1$
/**
* @since 6.4
*/
public static final String BUILD_COMMAND = "stdbuild.build.command"; //$NON-NLS-1$
/**
* @since 6.4
*/
public static final String CLEAN_COMMAND = "stdbuild.clean.command"; //$NON-NLS-1$
private String[] buildCommand;
private String[] cleanCommand;
@ -54,6 +62,15 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
public StandardBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
super(config, name);
applyProperties();
}
public StandardBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
String launchMode) {
super(config, name, toolChain);
}
private void applyProperties() {
String container = getProperty(BUILD_CONTAINER);
if (container != null && !container.trim().isEmpty()) {
IPath containerLoc = new org.eclipse.core.runtime.Path(container);
@ -63,11 +80,16 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
buildContainer = ResourcesPlugin.getWorkspace().getRoot().getFolder(containerLoc);
}
}
}
public StandardBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
String launchMode) {
super(config, name, toolChain);
String buildCmd = getProperty(BUILD_COMMAND);
if (buildCmd != null && !buildCmd.trim().isEmpty()) {
buildCommand = buildCmd.split(" "); //$NON-NLS-1$
}
String cleanCmd = getProperty(CLEAN_COMMAND);
if (cleanCmd != null && !cleanCmd.trim().isEmpty()) {
cleanCommand = cleanCmd.split(" "); //$NON-NLS-1$
}
}
public void setBuildContainer(IContainer buildContainer) {
@ -77,6 +99,7 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
public void setBuildCommand(String[] buildCommand) {
this.buildCommand = buildCommand;
setProperty(BUILD_COMMAND, String.join(" ", buildCommand)); //$NON-NLS-1$
}
public void setCleanCommand(String[] cleanCommand) {
@ -132,6 +155,15 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
return null;
}
@Override
public boolean setProperties(Map<String, String> properties) {
if (!super.setProperties(properties)) {
return false;
}
applyProperties();
return true;
}
@Override
public IProject[] build(int kind, Map<String, String> args, IConsole console, IProgressMonitor monitor)
throws CoreException {
@ -153,7 +185,6 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
} else {
command = new ArrayList<>();
command.add(findCommand("make").toString()); //$NON-NLS-1$
command.add("-j"); //$NON-NLS-1$
if (!getBuildContainer().equals(getProject())) {
Path makefile = Paths.get(getProject().getFile("Makefile").getLocationURI()); //$NON-NLS-1$
Path relative = getBuildDirectory().relativize(makefile);

View file

@ -126,6 +126,12 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
availTable.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
toolChains = new ArrayList<IToolChain>();
try {
toolChains.addAll(manager.getAllToolChains());
} catch (CoreException e) {
CUIPlugin.log(e.getStatus());
}
return toolChains.toArray();
}
});
@ -282,13 +288,6 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
}
});
toolChains = new ArrayList<IToolChain>();
try {
toolChains.addAll(manager.getAllToolChains());
} catch (CoreException e) {
CUIPlugin.log(e.getStatus());
}
availTable.setInput(manager);
userTable.setInput(manager);
updateButtons();