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 efd76606b2
commit e0149be3a3
4 changed files with 76 additions and 22 deletions

View file

@ -17,6 +17,7 @@ import java.util.List;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.eclipse.cdt.core.AbstractExecutableExtensionBase; 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.CIncludePathEntry;
import org.eclipse.cdt.core.settings.model.CMacroEntry; import org.eclipse.cdt.core.settings.model.CMacroEntry;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@ -649,6 +650,38 @@ public class LanguageSettingsManagerTests extends BaseTestCase {
assertEquals(3, includes.size()); 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. * Test ability to serialize providers for a configuration.
*/ */

View file

@ -13,10 +13,13 @@
package org.eclipse.cdt.core.model; package org.eclipse.cdt.core.model;
import java.net.URI; import java.net.URI;
import java.util.List;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature; 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.resources.IPathEntryStore;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
@ -26,6 +29,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.WriteAccessException; import org.eclipse.cdt.core.settings.model.WriteAccessException;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
import org.eclipse.cdt.internal.core.model.APathEntry; import org.eclipse.cdt.internal.core.model.APathEntry;
import org.eclipse.cdt.internal.core.model.BatchOperation; import org.eclipse.cdt.internal.core.model.BatchOperation;
import org.eclipse.cdt.internal.core.model.CModel; import org.eclipse.cdt.internal.core.model.CModel;
@ -1253,27 +1257,41 @@ public class CoreModel {
if(!mngr.isNewStyleCfg(indexCfg)){ if(!mngr.isNewStyleCfg(indexCfg)){
return oldIsScannerInformationEmpty(resource); 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;
entries = lSetting.getSettingEntries(ICSettingEntry.MACRO); if (indexCfg instanceof ILanguageSettingsProvidersKeeper) {
if(entries.length != 0) List<String> languageIds = LanguageSettingsManager.getLanguages(resource, indexCfg);
return false; for (String langId : languageIds) {
List<ICLanguageSettingEntry> entries = LanguageSettingsProvidersSerializer.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.INCLUDE_FILE); } else {
if(entries.length != 0) ICLanguageSetting lSetting = indexCfg.getLanguageSettingForFile(resource.getProjectRelativePath(), false);
return 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.MACRO_FILE); entries = lSetting.getSettingEntries(ICSettingEntry.MACRO);
if(entries.length != 0) if(entries.length != 0)
return false; 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

@ -369,12 +369,15 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin
boolean isPreferenceConfiguration(); boolean isPreferenceConfiguration();
/** /**
* Convenience method to return a language setting for the file * @deprecated Deprecated as of CDT 8.1. This method returns settings supplied by MBS only.
* with the specified project-relative path * For most cases, more generic Language Settings Providers mechanism should be used instead.
*
* Convenience method to return a language setting for the file with the specified project-relative path.
* *
* @param path - file project relative path * @param path - file project relative path
* @return ICLanguageSetting or null if not found * @return ICLanguageSetting or null if not found
*/ */
@Deprecated
ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus); ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus);
/** /**

View file

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