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

Bug 392966: Indexing only source files in the build doesn't work properly with new scanner discovery

This commit is contained in:
Andrew Gvozdev 2012-10-27 08:46:06 -04:00
parent cfdd0d2581
commit 8194410514
5 changed files with 101 additions and 22 deletions

View file

@ -17,6 +17,7 @@ import java.util.List;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
import org.eclipse.cdt.core.settings.model.CMacroEntry;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@ -649,6 +650,38 @@ public class LanguageSettingsManagerTests extends BaseTestCase {
assertEquals(3, includes.size());
}
/**
* Test ability to get entries by kind.
*/
public void testEntriesByKind_CompositeKind() throws Exception {
MockConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
// contribute the entries
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
entries.add(new CIncludePathEntry("path0", 0));
entries.add(new CMacroEntry("MACRO0", "value0",0));
entries.add(new CIncludePathEntry("path1", 0));
entries.add(new CMacroEntry("MACRO1", "value1",0));
entries.add(new CIncludePathEntry("path2", 0));
entries.add(new CIncludeFileEntry("include-path-file", 0));
ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries);
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
providers.add(provider0);
cfgDescription.setLanguageSettingProviders(providers);
// retrieve entries by kind
List<ICLanguageSettingEntry> result = LanguageSettingsProvidersSerializer
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH | ICSettingEntry.MACRO);
assertEquals(new CIncludePathEntry("path0", 0), result.get(0));
assertEquals(new CMacroEntry("MACRO0", "value0",0), result.get(1));
assertEquals(new CIncludePathEntry("path1", 0), result.get(2));
assertEquals(new CMacroEntry("MACRO1", "value1",0), result.get(3));
assertEquals(new CIncludePathEntry("path2", 0), result.get(4));
assertEquals(5, result.size());
}
/**
* Test ability to serialize providers for a configuration.
*/

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
import org.eclipse.core.resources.IFile;
@ -39,6 +40,29 @@ import org.eclipse.core.runtime.IPath;
* @since 5.4
*/
public class LanguageSettingsManager {
/**
* Returns the list of setting entries of a certain kind (such as include paths)
* for the given configuration description, resource and language. This is a
* combined list for all providers taking into account settings of parent folder
* if settings for the given resource are not defined. For include paths both
* local (#include "...") and system (#include <...>) entries are returned.
*
* @param cfgDescription - configuration description.
* @param rc - resource such as file or folder.
* @param languageId - language id.
* @param kind - kind of language settings entries, such as
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
* and it is possible to specify composite kind.
* Use {@link ICSettingEntry#ALL} to get all kinds.
*
* @return the list of setting entries.
*
* @since 5.5
*/
public static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
return LanguageSettingsProvidersSerializer.getSettingEntriesByKind(cfgDescription, rc, languageId, kind);
}
/**
* Returns the list of setting entries of the given provider
* for the given configuration description, resource and language.

View file

@ -13,10 +13,13 @@
package org.eclipse.cdt.core.model;
import java.net.URI;
import java.util.List;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper;
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
@ -1253,27 +1256,41 @@ public class CoreModel {
if(!mngr.isNewStyleCfg(indexCfg)){
return oldIsScannerInformationEmpty(resource);
}
ICLanguageSetting lSetting = indexCfg.getLanguageSettingForFile(resource.getProjectRelativePath(), false);
if(lSetting != null && lSetting instanceof CLanguageSettingCache){
if(!((CLanguageSettingCache)lSetting).containsDiscoveredScannerInfo())
lSetting = null;
}
if(lSetting != null){
ICLanguageSettingEntry[] entries = lSetting.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
if(entries.length != 0)
return false;
if (indexCfg instanceof ILanguageSettingsProvidersKeeper) {
List<String> languageIds = LanguageSettingsManager.getLanguages(resource, indexCfg);
for (String langId : languageIds) {
List<ICLanguageSettingEntry> entries = LanguageSettingsManager.getSettingEntriesByKind(indexCfg, resource, langId,
ICSettingEntry.INCLUDE_PATH | ICSettingEntry.MACRO | ICSettingEntry.INCLUDE_FILE | ICSettingEntry.MACRO_FILE);
if (!(entries == null || entries.isEmpty())) {
return false;
}
}
return true;
entries = lSetting.getSettingEntries(ICSettingEntry.MACRO);
if(entries.length != 0)
return false;
} else {
ICLanguageSetting lSetting = indexCfg.getLanguageSettingForFile(resource.getProjectRelativePath(), false);
if(lSetting != null && lSetting instanceof CLanguageSettingCache){
if(!((CLanguageSettingCache)lSetting).containsDiscoveredScannerInfo())
lSetting = null;
}
if(lSetting != null){
ICLanguageSettingEntry[] entries = lSetting.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
if(entries.length != 0)
return false;
entries = lSetting.getSettingEntries(ICSettingEntry.INCLUDE_FILE);
if(entries.length != 0)
return false;
entries = lSetting.getSettingEntries(ICSettingEntry.MACRO_FILE);
if(entries.length != 0)
return false;
entries = lSetting.getSettingEntries(ICSettingEntry.MACRO);
if(entries.length != 0)
return false;
entries = lSetting.getSettingEntries(ICSettingEntry.INCLUDE_FILE);
if(entries.length != 0)
return false;
entries = lSetting.getSettingEntries(ICSettingEntry.MACRO_FILE);
if(entries.length != 0)
return false;
}
}
}
}

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.core.settings.model;
import java.util.Map;
import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor;
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider;
@ -369,12 +370,16 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin
boolean isPreferenceConfiguration();
/**
* Convenience method to return a language setting for the file
* with the specified project-relative path
* @deprecated Deprecated as of CDT 8.1. This method returns settings supplied by MBS only.
* For most cases, more generic Language Settings Providers mechanism should be used instead, see
* {@link LanguageSettingsManager#getSettingEntriesByKind(ICConfigurationDescription, org.eclipse.core.resources.IResource, String, int)}.
*
* Convenience method to return a language setting for the file with the specified project-relative path.
*
* @param path - file project relative path
* @return ICLanguageSetting or null if not found
*/
@Deprecated
ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus);
/**

View file

@ -1513,7 +1513,7 @@ public class LanguageSettingsProvidersSerializer {
for (ICLanguageSettingEntry entry : providerEntries) {
if (entry != null) {
String entryName = entry.getName();
boolean isRightKind = checkBit(entry.getKind(), kind);
boolean isRightKind = checkBit(kind, entry.getKind());
// Only first entry is considered
// Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line
if (isRightKind && !alreadyAdded.contains(entryName)) {