mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-27 19:05:38 +02:00
Fix and Testcase for 197311, Full Indexer with dependent project corrupts index.
This commit is contained in:
parent
79b3fc77bb
commit
208e4f68ef
4 changed files with 101 additions and 20 deletions
|
@ -750,7 +750,6 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
// StructA_T gvar2;
|
// StructA_T gvar2;
|
||||||
public void testFileInMultipleFragments_bug192352() throws Exception {
|
public void testFileInMultipleFragments_bug192352() throws Exception {
|
||||||
StringBuffer[] contents= getContentsForTest(3);
|
StringBuffer[] contents= getContentsForTest(3);
|
||||||
|
|
||||||
|
|
||||||
ICProject p2 = CProjectHelper.createCCProject("__bugsTest_2_", "bin", IPDOMManager.ID_FAST_INDEXER);
|
ICProject p2 = CProjectHelper.createCCProject("__bugsTest_2_", "bin", IPDOMManager.ID_FAST_INDEXER);
|
||||||
try {
|
try {
|
||||||
|
@ -833,4 +832,65 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
index.releaseReadLock();
|
index.releaseReadLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int globalVar;
|
||||||
|
|
||||||
|
// #include "../__bugsTest__/common.h"
|
||||||
|
// void func() {
|
||||||
|
// globalVar++;
|
||||||
|
// }
|
||||||
|
public void testDependentProjectsWithFullIndexer_Bug197311() throws Exception {
|
||||||
|
StringBuffer[] contents= getContentsForTest(2);
|
||||||
|
final IIndexManager indexManager = CCorePlugin.getIndexManager();
|
||||||
|
indexManager.setIndexerId(fCProject, IPDOMManager.ID_FULL_INDEXER);
|
||||||
|
ICProject p2 = CProjectHelper.createCCProject("bug197311", "bin", IPDOMManager.ID_FULL_INDEXER);
|
||||||
|
IProject[] refs = new IProject[] {fCProject.getProject()};
|
||||||
|
IProjectDescription pd = p2.getProject().getDescription();
|
||||||
|
pd.setReferencedProjects(refs);
|
||||||
|
p2.getProject().setDescription(pd, new NullProgressMonitor());
|
||||||
|
try {
|
||||||
|
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0].toString());
|
||||||
|
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString());
|
||||||
|
IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[1].toString());
|
||||||
|
waitForIndexer();
|
||||||
|
|
||||||
|
IIndex index= indexManager.getIndex(p2, IIndexManager.ADD_DEPENDENCIES);
|
||||||
|
index.acquireReadLock();
|
||||||
|
try {
|
||||||
|
IIndexBinding[] bindings= index.findBindings("globalVar".toCharArray(), IndexFilter.ALL, NPM);
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
IIndexBinding binding= bindings[0];
|
||||||
|
IIndexName[] names= index.findReferences(binding);
|
||||||
|
assertEquals(2, names.length);
|
||||||
|
names= index.findDeclarations(binding);
|
||||||
|
assertEquals(1, names.length);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
indexManager.reindex(p2);
|
||||||
|
waitForIndexer();
|
||||||
|
|
||||||
|
index= indexManager.getIndex(p2, IIndexManager.ADD_DEPENDENCIES);
|
||||||
|
index.acquireReadLock();
|
||||||
|
try {
|
||||||
|
IIndexBinding[] bindings= index.findBindings("globalVar".toCharArray(), IndexFilter.ALL, NPM);
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
IIndexBinding binding= bindings[0];
|
||||||
|
IIndexName[] names= index.findReferences(binding);
|
||||||
|
assertEquals(2, names.length);
|
||||||
|
names= index.findDeclarations(binding);
|
||||||
|
assertEquals(1, names.length);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
CProjectHelper.delete(p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,19 @@ public interface IWritableIndex extends IIndex {
|
||||||
public IIndexFragmentFile fTargetFile;
|
public IIndexFragmentFile fTargetFile;
|
||||||
public boolean fIsContext= false;
|
public boolean fIsContext= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given file can be written to in this index.
|
||||||
|
*/
|
||||||
|
boolean isWritableFile(IIndexFragmentFile file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the given file in the index.
|
||||||
|
* @param file a file to clear.
|
||||||
|
* @param a collection that receives IndexFileLocation objects for files that
|
||||||
|
* had the cleared file as a context. May be <code>null</code>.
|
||||||
|
*/
|
||||||
|
void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a file object for the given location or returns an existing one.
|
* Creates a file object for the given location or returns an existing one.
|
||||||
|
@ -52,14 +65,6 @@ public interface IWritableIndex extends IIndex {
|
||||||
*/
|
*/
|
||||||
void clear() throws CoreException;
|
void clear() throws CoreException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the given file in the index.
|
|
||||||
* @param file a file to clear.
|
|
||||||
* @param a collection that receives IndexFileLocation objects for files that
|
|
||||||
* had the cleared file as a context. May be <code>null</code>.
|
|
||||||
*/
|
|
||||||
void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acquires a write lock, while giving up a certain amount of read locks.
|
* Acquires a write lock, while giving up a certain amount of read locks.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -61,15 +61,18 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
|
||||||
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
|
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
|
||||||
|
|
||||||
IIndexFragment indexFragment = file.getIndexFragment();
|
IIndexFragment indexFragment = file.getIndexFragment();
|
||||||
assert isWritableFragment(indexFragment);
|
if (!isWritableFragment(indexFragment)) {
|
||||||
|
assert false : "Attempt to update file of read-only fragment"; //$NON-NLS-1$
|
||||||
for (int i = 0; i < includes.length; i++) {
|
}
|
||||||
IncludeInformation ii= includes[i];
|
else {
|
||||||
if (ii.fLocation != null) {
|
for (int i = 0; i < includes.length; i++) {
|
||||||
ii.fTargetFile= addFile(ii.fLocation);
|
IncludeInformation ii= includes[i];
|
||||||
}
|
if (ii.fLocation != null) {
|
||||||
|
ii.fTargetFile= addFile(ii.fLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
((IWritableIndexFragment) indexFragment).addFileContent(file, includes, macros, names);
|
||||||
}
|
}
|
||||||
((IWritableIndexFragment) indexFragment).addFileContent(file, includes, macros, names);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() throws CoreException {
|
public void clear() throws CoreException {
|
||||||
|
@ -79,11 +82,18 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWritableFile(IIndexFragmentFile file) {
|
||||||
|
return isWritableFragment(file.getIndexFragment());
|
||||||
|
}
|
||||||
|
|
||||||
public void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException {
|
public void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException {
|
||||||
IIndexFragment indexFragment = file.getIndexFragment();
|
IIndexFragment indexFragment = file.getIndexFragment();
|
||||||
assert isWritableFragment(indexFragment);
|
if (!isWritableFragment(indexFragment)) {
|
||||||
|
assert false : "Attempt to clear file of read-only fragment"; //$NON-NLS-1$
|
||||||
((IWritableIndexFragment) indexFragment).clearFile(file, clearedContexts);
|
}
|
||||||
|
else {
|
||||||
|
((IWritableIndexFragment) indexFragment).clearFile(file, clearedContexts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask;
|
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask;
|
||||||
|
@ -173,6 +174,11 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
||||||
Object required= filePathsToParse.get(location);
|
Object required= filePathsToParse.get(location);
|
||||||
if (required == null) {
|
if (required == null) {
|
||||||
required= MISSING;
|
required= MISSING;
|
||||||
|
// bug 197311, don't attempt to update files in fragments of other projects.
|
||||||
|
IIndexFragmentFile file= (IIndexFragmentFile) fIndex.getFile(location);
|
||||||
|
if (file != null && !fIndex.isWritableFile(file)) {
|
||||||
|
required= SKIP;
|
||||||
|
}
|
||||||
filePathsToParse.put(location, required);
|
filePathsToParse.put(location, required);
|
||||||
}
|
}
|
||||||
else if (confighash != 0 && required == REQUIRED_IF_CONFIG_CHANGED) {
|
else if (confighash != 0 && required == REQUIRED_IF_CONFIG_CHANGED) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue