ENH: Since list file cache does not make much sense any more (because of proper list file parsing), and it actually adds unnecessary complications and make ctest scripting not work, take it out

This commit is contained in:
Andy Cedilnik 2006-02-07 08:49:42 -05:00
parent 515757007a
commit 4259971961
10 changed files with 13 additions and 138 deletions

View File

@ -48,10 +48,8 @@ int cmCTestBuildAndTestHandler::ProcessHandler()
m_Output = ""; m_Output = "";
std::string output; std::string output;
cmSystemTools::ResetErrorOccuredFlag(); cmSystemTools::ResetErrorOccuredFlag();
cmListFileCache::ClearCache();
int retv = this->RunCMakeAndTest(&m_Output); int retv = this->RunCMakeAndTest(&m_Output);
cmSystemTools::ResetErrorOccuredFlag(); cmSystemTools::ResetErrorOccuredFlag();
cmListFileCache::ClearCache();
return retv; return retv;
} }

View File

@ -212,7 +212,6 @@ CMakeSetupDialog::~CMakeSetupDialog()
{ {
delete m_CMakeInstance; delete m_CMakeInstance;
// clean up globals // clean up globals
cmListFileCache::GetInstance()->ClearCache();
cmDynamicLoader::FlushCache(); cmDynamicLoader::FlushCache();
} }

View File

@ -1656,13 +1656,6 @@ int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
cmCTestBuildAndTestHandler* handler = cmCTestBuildAndTestHandler* handler =
static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest")); static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest"));
int retv = handler->ProcessHandler(); int retv = handler->ProcessHandler();
/*
cmSystemTools::ResetErrorOccuredFlag();
cmListFileCache::ClearCache();
int retv = this->RunCMakeAndTest(output);
cmSystemTools::ResetErrorOccuredFlag();
cmListFileCache::ClearCache();
*/
*output = handler->GetOutput(); *output = handler->GetOutput();
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
cmDynamicLoader::FlushCache(); cmDynamicLoader::FlushCache();

View File

@ -25,65 +25,7 @@ bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
cmListFileFunction& function, cmListFileFunction& function,
const char* filename); const char* filename);
cmListFileCache* cmListFileCache::Instance = 0; bool cmListFile::ParseFile(const char* path, bool requireProjectCommand)
cmListFileCache* cmListFileCache::GetInstance()
{
if(!cmListFileCache::Instance)
{
cmListFileCache::Instance = new cmListFileCache;
}
return cmListFileCache::Instance;
}
void cmListFileCache::ClearCache()
{
delete cmListFileCache::Instance;
cmListFileCache::Instance = 0;
}
cmListFile* cmListFileCache::GetFileCache(const char* path,
bool requireProjectCommand)
{
ListFileMap::iterator sl = m_ListFileCache.find(path);
if (sl == m_ListFileCache.end())
{
// if not already in the map, then parse and store the
// file
if(!this->CacheFile(path, requireProjectCommand))
{
return 0;
}
sl = m_ListFileCache.find(path);
if (sl == m_ListFileCache.end())
{
cmSystemTools::Error("Fatal error, in cmListFileCache CacheFile failed",
path);
return 0;
}
}
cmListFile& ret = sl->second;
if(cmSystemTools::ModifiedTime(path) > ret.m_ModifiedTime )
{
if(!this->CacheFile(path, requireProjectCommand))
{
return 0;
}
else
{
sl = m_ListFileCache.find(path);
return &sl->second;
}
}
return &ret;
}
bool cmListFileCache::CacheFile(const char* path, bool requireProjectCommand)
{ {
if(!cmSystemTools::FileExists(path)) if(!cmSystemTools::FileExists(path))
{ {
@ -110,8 +52,7 @@ bool cmListFileCache::CacheFile(const char* path, bool requireProjectCommand)
// Use a simple recursive-descent parser to process the token // Use a simple recursive-descent parser to process the token
// stream. // stream.
cmListFile inFile; this->m_ModifiedTime = cmSystemTools::ModifiedTime(filename);
inFile.m_ModifiedTime = cmSystemTools::ModifiedTime(filename);
bool parseError = false; bool parseError = false;
bool haveNewline = true; bool haveNewline = true;
cmListFileLexer_Token* token; cmListFileLexer_Token* token;
@ -132,7 +73,7 @@ bool cmListFileCache::CacheFile(const char* path, bool requireProjectCommand)
inFunction.m_Line = token->line; inFunction.m_Line = token->line;
if(cmListFileCacheParseFunction(lexer, inFunction, filename)) if(cmListFileCacheParseFunction(lexer, inFunction, filename))
{ {
inFile.m_Functions.push_back(inFunction); this->m_Functions.push_back(inFunction);
} }
else else
{ {
@ -166,7 +107,7 @@ bool cmListFileCache::CacheFile(const char* path, bool requireProjectCommand)
} }
if (parseError) if (parseError)
{ {
inFile.m_ModifiedTime = 0; this->m_ModifiedTime = 0;
} }
cmListFileLexer_Delete(lexer); cmListFileLexer_Delete(lexer);
@ -176,8 +117,8 @@ bool cmListFileCache::CacheFile(const char* path, bool requireProjectCommand)
bool hasProject = false; bool hasProject = false;
// search for a project command // search for a project command
for(std::vector<cmListFileFunction>::iterator i for(std::vector<cmListFileFunction>::iterator i
= inFile.m_Functions.begin(); = this->m_Functions.begin();
i != inFile.m_Functions.end(); ++i) i != this->m_Functions.end(); ++i)
{ {
if(cmSystemTools::LowerCase(i->m_Name) == "project") if(cmSystemTools::LowerCase(i->m_Name) == "project")
{ {
@ -192,23 +133,12 @@ bool cmListFileCache::CacheFile(const char* path, bool requireProjectCommand)
project.m_Name = "PROJECT"; project.m_Name = "PROJECT";
cmListFileArgument prj("Project", false, filename, 0); cmListFileArgument prj("Project", false, filename, 0);
project.m_Arguments.push_back(prj); project.m_Arguments.push_back(prj);
inFile.m_Functions.insert(inFile.m_Functions.begin(),project); this->m_Functions.insert(this->m_Functions.begin(),project);
} }
} }
m_ListFileCache[filename] = inFile;
return true; return true;
} }
void cmListFileCache::FlushCache(const char* path)
{
ListFileMap::iterator it = m_ListFileCache.find(path);
if ( it != m_ListFileCache.end() )
{
m_ListFileCache.erase(it);
return;
}
}
bool cmListFileCacheParseFunction(cmListFileLexer* lexer, bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
cmListFileFunction& function, cmListFileFunction& function,
const char* filename) const char* filename)
@ -284,7 +214,7 @@ bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* cmListFileCache::GetUniqueStringPointer(const char* name) const char* cmListFile::GetUniqueStringPointer(const char* name)
{ {
UniqueStrings::iterator i = m_UniqueStrings.find(name); UniqueStrings::iterator i = m_UniqueStrings.find(name);
if(i == m_UniqueStrings.end()) if(i == m_UniqueStrings.end())
@ -296,12 +226,3 @@ const char* cmListFileCache::GetUniqueStringPointer(const char* name)
return i->second; return i->second;
} }
//----------------------------------------------------------------------------
cmListFileCache::~cmListFileCache()
{
for(UniqueStrings::iterator i = m_UniqueStrings.begin();
i != m_UniqueStrings.end(); ++i)
{
delete [] i->second;
}
}

View File

@ -62,42 +62,12 @@ struct cmListFile
:m_ModifiedTime(0) :m_ModifiedTime(0)
{ {
} }
bool ParseFile(const char* path, bool requireProjectCommand);
long int m_ModifiedTime; long int m_ModifiedTime;
std::vector<cmListFileFunction> m_Functions; std::vector<cmListFileFunction> m_Functions;
};
class cmListFileCache
{
public:
static cmListFileCache* GetInstance();
static void ClearCache();
/** Return the cached version of the given file.
* If the file is not already in the cache, a cache entry
* will be made. If there is an error loading the file,
* NULL is returned. If requireProjectCommand is true,
* then a PROJECT(Project) command will be added to the file
* if it does not have a PROJECT command in it.
*/
cmListFile* GetFileCache(const char* path, bool requireProjectCommand);
//! Flush cache file out of cache.
void FlushCache(const char* path);
~cmListFileCache();
private:
// Cache the file
bool CacheFile(const char* path, bool requireProjectCommand);
// private data
typedef std::map<cmStdString, cmListFile> ListFileMap;
ListFileMap m_ListFileCache; // file name to ListFile map
typedef std::map<cmStdString, char*> UniqueStrings; typedef std::map<cmStdString, char*> UniqueStrings;
UniqueStrings m_UniqueStrings; UniqueStrings m_UniqueStrings;
const char* GetUniqueStringPointer(const char* name); const char* GetUniqueStringPointer(const char* name);
static cmListFileCache* Instance; // singelton pointer
}; };
#endif #endif

View File

@ -378,20 +378,18 @@ bool cmMakefile::ReadListFile(const char* filename_in, const char *external_in)
} }
} }
cmListFile* lf = cmListFile cacheFile;
cmListFileCache::GetInstance()->GetFileCache(filenametoread, if( !cacheFile.ParseFile(filenametoread, requireProjectCommand) )
requireProjectCommand);
if(!lf)
{ {
this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentFile.c_str()); this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentFile.c_str());
return false; return false;
} }
// add this list file to the list of dependencies // add this list file to the list of dependencies
m_ListFiles.push_back( filenametoread); m_ListFiles.push_back( filenametoread);
const size_t numberFunctions = lf->m_Functions.size(); const size_t numberFunctions = cacheFile.m_Functions.size();
for(size_t i =0; i < numberFunctions; ++i) for(size_t i =0; i < numberFunctions; ++i)
{ {
this->ExecuteCommand(lf->m_Functions[i]); this->ExecuteCommand(cacheFile.m_Functions[i]);
if ( cmSystemTools::GetFatalErrorOccured() ) if ( cmSystemTools::GetFatalErrorOccured() )
{ {
this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentFile.c_str()); this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentFile.c_str());

View File

@ -243,7 +243,6 @@ int cmTryCompileCommand::CoreTryCompileCode(
// if They specified clean then we clean up what we can // if They specified clean then we clean up what we can
if (srcFileSignature && clean) if (srcFileSignature && clean)
{ {
cmListFileCache::GetInstance()->FlushCache(outFileName.c_str());
if(!mf->GetCMakeInstance()->GetDebugTryCompile()) if(!mf->GetCMakeInstance()->GetDebugTryCompile())
{ {
cmTryCompileCommand::CleanupFiles(binaryDirectory); cmTryCompileCommand::CleanupFiles(binaryDirectory);

View File

@ -152,7 +152,6 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv)
// if we created a directory etc, then cleanup after ourselves // if we created a directory etc, then cleanup after ourselves
std::string cacheFile = binaryDirectory; std::string cacheFile = binaryDirectory;
cacheFile += "/CMakeLists.txt"; cacheFile += "/CMakeLists.txt";
cmListFileCache::GetInstance()->FlushCache(cacheFile.c_str());
if(!m_Makefile->GetCMakeInstance()->GetDebugTryCompile()) if(!m_Makefile->GetCMakeInstance()->GetDebugTryCompile())
{ {
cmTryCompileCommand::CleanupFiles(binaryDirectory.c_str()); cmTryCompileCommand::CleanupFiles(binaryDirectory.c_str());

View File

@ -121,7 +121,6 @@ int main(int ac, char** av)
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
cmDynamicLoader::FlushCache(); cmDynamicLoader::FlushCache();
#endif #endif
cmListFileCache::ClearCache();
return ret; return ret;
} }

View File

@ -237,7 +237,6 @@ int main (int argc, char *argv[])
std::string output; std::string output;
int res = inst.Run(args,&output); int res = inst.Run(args,&output);
cmCTestLog(&inst, OUTPUT, output); cmCTestLog(&inst, OUTPUT, output);
cmListFileCache::ClearCache();
return res; return res;
} }