Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.net.URI;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -36,11 +37,12 @@
*
*/
public class ToolchainSettings implements IToolchainSettings {
private static final String EXTENSION_CPP = "cpp";
private final List<ICLanguageSetting> languageSettings;
private final ICConfigurationDescription activeConfiguration;
private final IProject project;
private final IWorkspaceRoot root;
private static final String GCC_LANGUAGE_ID = "org.eclipse.cdt.core.gcc";
private static final String GPP_LANGUAGE_ID = "org.eclipse.cdt.core.g++";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this does not feel rock solid to me. eclipse can use different compilers, not just gcc/g++. is it specified somewhere that getLanguageId only returns these strings for C/C++ code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw the old code to compare the extension is not rock solid neither.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!


public ToolchainSettings(IProject project) throws IllegalStateException {
languageSettings = new LinkedList<ICLanguageSetting>();
Expand All @@ -67,13 +69,10 @@ public ToolchainSettings(IProject project) throws IllegalStateException {
ICLanguageSetting[] allLanguageSettings = folderDescription
.getLanguageSettings();

// fetch the include settings from the first tool which supports c
for (ICLanguageSetting languageSetting : allLanguageSettings) {
String extensions[] = languageSetting.getSourceExtensions();
for (String extension : extensions) {
if (EXTENSION_CPP.equalsIgnoreCase(extension)) { //$NON-NLS-1$
languageSettings.add(languageSetting);
}
for (ICLanguageSetting ls : allLanguageSettings) {
String id = ls.getLanguageId();
if (GCC_LANGUAGE_ID.equals(id) || GPP_LANGUAGE_ID.equals(id)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the file to analyze is a C file then it would be preferable to not use GPP settings. how doable would that be?

If neither GCC_LANGUAGE_ID nor GPP_LANGUAGE_ID is found but another compiler is used.. an idea could be to load all the include paths from all language settings?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a good idea, I'll see what I can do

languageSettings.add(ls);
}
}

Expand Down Expand Up @@ -161,7 +160,7 @@ protected Collection<File> resolveIncludePath(File includePath)
* @return all include folders in a list
*/
protected Collection<File> getIncludes(boolean onlyUserDefined) {
Collection<File> paths = new LinkedList<File>();
Collection<File> paths = new LinkedHashSet<File>();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid duplicates if same includes are added in both c and c++ language settings

IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
URI workspaceUri = workspaceRoot.getLocationURI();

Expand Down
Loading