2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-01-19 01:09:05 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2005-01-19 01:09:05 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2005-01-19 01:09:05 +03:00
|
|
|
#include "cmDependsC.h"
|
|
|
|
|
2005-12-09 21:58:55 +03:00
|
|
|
#include "cmFileTimeComparison.h"
|
2006-05-25 17:47:30 +04:00
|
|
|
#include "cmLocalGenerator.h"
|
2008-05-08 18:09:14 +04:00
|
|
|
#include "cmMakefile.h"
|
2006-05-25 17:47:30 +04:00
|
|
|
#include "cmSystemTools.h"
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2005-01-19 01:09:05 +03:00
|
|
|
|
2005-05-10 19:00:15 +04:00
|
|
|
#include <ctype.h> // isspace
|
|
|
|
|
2007-02-05 17:48:38 +03:00
|
|
|
|
2007-02-07 17:23:41 +03:00
|
|
|
#define INCLUDE_REGEX_LINE \
|
|
|
|
"^[ \t]*#[ \t]*(include|import)[ \t]*[<\"]([^\">]+)([\">])"
|
2007-02-05 17:48:38 +03:00
|
|
|
|
|
|
|
#define INCLUDE_REGEX_LINE_MARKER "#IncludeRegexLine: "
|
|
|
|
#define INCLUDE_REGEX_SCAN_MARKER "#IncludeRegexScan: "
|
|
|
|
#define INCLUDE_REGEX_COMPLAIN_MARKER "#IncludeRegexComplain: "
|
2008-05-14 19:54:32 +04:00
|
|
|
#define INCLUDE_REGEX_TRANSFORM_MARKER "#IncludeRegexTransform: "
|
2007-02-05 17:48:38 +03:00
|
|
|
|
2005-01-19 01:09:05 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2008-05-08 18:09:14 +04:00
|
|
|
cmDependsC::cmDependsC()
|
2009-09-23 22:02:05 +04:00
|
|
|
: ValidDeps(0)
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
|
|
|
}
|
2008-05-08 18:09:14 +04:00
|
|
|
|
2005-01-19 01:09:05 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2009-09-23 22:02:05 +04:00
|
|
|
cmDependsC::cmDependsC(cmLocalGenerator* lg,
|
|
|
|
const char* targetDir,
|
2014-02-04 06:20:56 +04:00
|
|
|
const std::string& lang,
|
2009-09-23 22:02:05 +04:00
|
|
|
const std::map<std::string, DependencyVector>* validDeps)
|
|
|
|
: cmDepends(lg, targetDir)
|
|
|
|
, ValidDeps(validDeps)
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
2008-05-08 18:09:14 +04:00
|
|
|
cmMakefile* mf = lg->GetMakefile();
|
|
|
|
|
|
|
|
// Configure the include file search path.
|
|
|
|
this->SetIncludePathFromLanguage(lang);
|
|
|
|
|
|
|
|
// Configure regular expressions.
|
|
|
|
std::string scanRegex = "^.*$";
|
|
|
|
std::string complainRegex = "^$";
|
|
|
|
{
|
|
|
|
std::string scanRegexVar = "CMAKE_";
|
|
|
|
scanRegexVar += lang;
|
|
|
|
scanRegexVar += "_INCLUDE_REGEX_SCAN";
|
2014-03-11 03:04:11 +04:00
|
|
|
if(const char* sr = mf->GetDefinition(scanRegexVar))
|
2008-05-08 18:09:14 +04:00
|
|
|
{
|
|
|
|
scanRegex = sr;
|
|
|
|
}
|
|
|
|
std::string complainRegexVar = "CMAKE_";
|
|
|
|
complainRegexVar += lang;
|
|
|
|
complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
|
2014-03-11 03:04:11 +04:00
|
|
|
if(const char* cr = mf->GetDefinition(complainRegexVar))
|
2008-05-08 18:09:14 +04:00
|
|
|
{
|
|
|
|
complainRegex = cr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->IncludeRegexLine.compile(INCLUDE_REGEX_LINE);
|
|
|
|
this->IncludeRegexScan.compile(scanRegex.c_str());
|
|
|
|
this->IncludeRegexComplain.compile(complainRegex.c_str());
|
|
|
|
this->IncludeRegexLineString = INCLUDE_REGEX_LINE_MARKER INCLUDE_REGEX_LINE;
|
|
|
|
this->IncludeRegexScanString = INCLUDE_REGEX_SCAN_MARKER;
|
|
|
|
this->IncludeRegexScanString += scanRegex;
|
|
|
|
this->IncludeRegexComplainString = INCLUDE_REGEX_COMPLAIN_MARKER;
|
|
|
|
this->IncludeRegexComplainString += complainRegex;
|
|
|
|
|
2008-05-14 19:54:32 +04:00
|
|
|
this->SetupTransforms();
|
|
|
|
|
2008-05-08 18:09:14 +04:00
|
|
|
this->CacheFileName = this->TargetDirectory;
|
|
|
|
this->CacheFileName += "/";
|
|
|
|
this->CacheFileName += lang;
|
|
|
|
this->CacheFileName += ".includecache";
|
|
|
|
|
2005-12-09 21:58:55 +03:00
|
|
|
this->ReadCacheFile();
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmDependsC::~cmDependsC()
|
|
|
|
{
|
2005-12-09 21:58:55 +03:00
|
|
|
this->WriteCacheFile();
|
2015-01-04 15:33:16 +03:00
|
|
|
cmDeleteAll(this->FileCache);
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-09-30 19:53:01 +04:00
|
|
|
bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
|
|
|
|
const std::string& obj,
|
|
|
|
std::ostream& makeDepends,
|
|
|
|
std::ostream& internalDepends)
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
|
|
|
// Make sure this is a scanning instance.
|
2012-09-30 19:53:01 +04:00
|
|
|
if(sources.empty() || sources.begin()->empty())
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
2005-07-27 17:49:37 +04:00
|
|
|
cmSystemTools::Error("Cannot scan dependencies without a source file.");
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-30 19:53:01 +04:00
|
|
|
if(obj.empty())
|
2005-07-27 17:49:37 +04:00
|
|
|
{
|
|
|
|
cmSystemTools::Error("Cannot scan dependencies without an object file.");
|
2005-01-19 01:09:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> dependencies;
|
2012-09-30 12:57:59 +04:00
|
|
|
bool haveDeps = false;
|
|
|
|
|
2009-09-23 22:02:05 +04:00
|
|
|
if (this->ValidDeps != 0)
|
|
|
|
{
|
|
|
|
std::map<std::string, DependencyVector>::const_iterator tmpIt =
|
|
|
|
this->ValidDeps->find(obj);
|
|
|
|
if (tmpIt!= this->ValidDeps->end())
|
|
|
|
{
|
2014-11-25 18:33:00 +03:00
|
|
|
dependencies.insert(tmpIt->second.begin(), tmpIt->second.end());
|
2012-09-30 12:57:59 +04:00
|
|
|
haveDeps = true;
|
2009-09-23 22:02:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-30 12:57:59 +04:00
|
|
|
if (!haveDeps)
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
// Walk the dependency graph starting with the source file.
|
2012-09-30 19:53:01 +04:00
|
|
|
int srcFiles = (int)sources.size();
|
2012-09-30 13:05:45 +04:00
|
|
|
this->Encountered.clear();
|
2012-09-30 19:53:01 +04:00
|
|
|
|
|
|
|
for(std::set<std::string>::const_iterator srcIt = sources.begin();
|
|
|
|
srcIt != sources.end(); ++srcIt)
|
|
|
|
{
|
|
|
|
UnscannedEntry root;
|
|
|
|
root.FileName = *srcIt;
|
|
|
|
this->Unscanned.push(root);
|
|
|
|
this->Encountered.insert(*srcIt);
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> scanned;
|
2012-09-30 13:05:45 +04:00
|
|
|
|
|
|
|
// Use reserve to allocate enough memory for tempPathStr
|
|
|
|
// so that during the loops no memory is allocated or freed
|
|
|
|
std::string tempPathStr;
|
|
|
|
tempPathStr.reserve(4*1024);
|
|
|
|
|
|
|
|
while(!this->Unscanned.empty())
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
// Get the next file to scan.
|
|
|
|
UnscannedEntry current = this->Unscanned.front();
|
|
|
|
this->Unscanned.pop();
|
|
|
|
|
|
|
|
// If not a full path, find the file in the include path.
|
|
|
|
std::string fullName;
|
2012-09-30 19:53:01 +04:00
|
|
|
if((srcFiles>0)
|
|
|
|
|| cmSystemTools::FileIsFullPath(current.FileName.c_str()))
|
2005-02-08 00:11:01 +03:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
if(cmSystemTools::FileExists(current.FileName.c_str(), true))
|
|
|
|
{
|
|
|
|
fullName = current.FileName;
|
|
|
|
}
|
2005-02-08 00:11:01 +03:00
|
|
|
}
|
2012-09-30 13:05:45 +04:00
|
|
|
else if(!current.QuotedLocation.empty() &&
|
|
|
|
cmSystemTools::FileExists(current.QuotedLocation.c_str(), true))
|
2006-09-13 20:43:32 +04:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
// The include statement producing this entry was a double-quote
|
|
|
|
// include and the included file is present in the directory of
|
|
|
|
// the source containing the include statement.
|
|
|
|
fullName = current.QuotedLocation;
|
2006-09-13 20:43:32 +04:00
|
|
|
}
|
2012-09-30 13:05:45 +04:00
|
|
|
else
|
2006-09-13 20:43:32 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::iterator
|
2012-09-30 13:05:45 +04:00
|
|
|
headerLocationIt=this->HeaderLocationCache.find(current.FileName);
|
|
|
|
if (headerLocationIt!=this->HeaderLocationCache.end())
|
2005-02-24 20:44:56 +03:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
fullName=headerLocationIt->second;
|
2005-02-24 20:44:56 +03:00
|
|
|
}
|
2012-09-30 13:05:45 +04:00
|
|
|
else for(std::vector<std::string>::const_iterator i =
|
|
|
|
this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
|
2005-02-24 20:44:56 +03:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
// Construct the name of the file as if it were in the current
|
|
|
|
// include directory. Avoid using a leading "./".
|
2005-02-24 20:44:56 +03:00
|
|
|
|
2013-06-19 16:35:23 +04:00
|
|
|
tempPathStr =
|
|
|
|
cmSystemTools::CollapseCombinedPath(*i, current.FileName);
|
2012-09-30 13:05:45 +04:00
|
|
|
|
|
|
|
// Look for the file in this location.
|
|
|
|
if(cmSystemTools::FileExists(tempPathStr.c_str(), true))
|
|
|
|
{
|
|
|
|
fullName = tempPathStr;
|
|
|
|
HeaderLocationCache[current.FileName]=fullName;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
|
|
|
}
|
2005-02-08 00:11:01 +03:00
|
|
|
|
2012-09-30 13:05:45 +04:00
|
|
|
// Complain if the file cannot be found and matches the complain
|
|
|
|
// regex.
|
|
|
|
if(fullName.empty() &&
|
|
|
|
this->IncludeRegexComplain.find(current.FileName.c_str()))
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Cannot find file \"",
|
|
|
|
current.FileName.c_str(), "\".");
|
|
|
|
return false;
|
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
|
2012-09-30 13:05:45 +04:00
|
|
|
// Scan the file if it was found and has not been scanned already.
|
|
|
|
if(!fullName.empty() && (scanned.find(fullName) == scanned.end()))
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
// Record scanned files.
|
|
|
|
scanned.insert(fullName);
|
|
|
|
|
|
|
|
// Check whether this file is already in the cache
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, cmIncludeLines*>::iterator fileIt=
|
2012-09-30 13:05:45 +04:00
|
|
|
this->FileCache.find(fullName);
|
|
|
|
if (fileIt!=this->FileCache.end())
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
fileIt->second->Used=true;
|
|
|
|
dependencies.insert(fullName);
|
|
|
|
for (std::vector<UnscannedEntry>::const_iterator incIt=
|
|
|
|
fileIt->second->UnscannedEntries.begin();
|
|
|
|
incIt!=fileIt->second->UnscannedEntries.end(); ++incIt)
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
2012-09-30 13:05:45 +04:00
|
|
|
if (this->Encountered.find(incIt->FileName) ==
|
|
|
|
this->Encountered.end())
|
|
|
|
{
|
|
|
|
this->Encountered.insert(incIt->FileName);
|
|
|
|
this->Unscanned.push(*incIt);
|
|
|
|
}
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
|
|
|
}
|
2012-09-30 13:05:45 +04:00
|
|
|
else
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2012-09-30 13:05:45 +04:00
|
|
|
// Try to scan the file. Just leave it out if we cannot find
|
|
|
|
// it.
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(fullName.c_str());
|
2012-09-30 13:05:45 +04:00
|
|
|
if(fin)
|
|
|
|
{
|
|
|
|
// Add this file as a dependency.
|
|
|
|
dependencies.insert(fullName);
|
|
|
|
|
|
|
|
// Scan this file for new dependencies. Pass the directory
|
|
|
|
// containing the file to handle double-quote includes.
|
|
|
|
std::string dir = cmSystemTools::GetFilenamePath(fullName);
|
|
|
|
this->Scan(fin, dir.c_str(), fullName);
|
|
|
|
}
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2012-09-30 19:53:01 +04:00
|
|
|
srcFiles--;
|
2012-09-30 13:05:45 +04:00
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2006-05-25 17:47:30 +04:00
|
|
|
// Write the dependencies to the output stream. Makefile rules
|
|
|
|
// written by the original local generator for this directory
|
|
|
|
// convert the dependencies to paths relative to the home output
|
|
|
|
// directory. We must do the same here.
|
2014-07-22 20:50:37 +04:00
|
|
|
std::string obj_i =
|
|
|
|
this->LocalGenerator->Convert(obj, cmLocalGenerator::HOME_OUTPUT);
|
|
|
|
std::string obj_m =
|
|
|
|
this->LocalGenerator->ConvertToOutputFormat(obj_i,
|
|
|
|
cmLocalGenerator::MAKERULE);
|
|
|
|
internalDepends << obj_i << std::endl;
|
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
for(std::set<std::string>::const_iterator i=dependencies.begin();
|
2005-01-19 01:09:05 +03:00
|
|
|
i != dependencies.end(); ++i)
|
|
|
|
{
|
2014-07-22 20:50:37 +04:00
|
|
|
makeDepends << obj_m << ": " <<
|
2014-03-11 03:04:11 +04:00
|
|
|
this->LocalGenerator->Convert(*i,
|
2006-06-05 22:32:12 +04:00
|
|
|
cmLocalGenerator::HOME_OUTPUT,
|
2014-07-22 20:27:57 +04:00
|
|
|
cmLocalGenerator::MAKERULE)
|
2005-12-09 21:58:55 +03:00
|
|
|
<< std::endl;
|
2014-03-11 16:35:32 +04:00
|
|
|
internalDepends << " " << *i << std::endl;
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
2005-10-12 21:52:29 +04:00
|
|
|
makeDepends << std::endl;
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2005-01-19 01:09:05 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2005-12-09 21:58:55 +03:00
|
|
|
void cmDependsC::ReadCacheFile()
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
2006-03-16 17:33:23 +03:00
|
|
|
if(this->CacheFileName.size() == 0)
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(this->CacheFileName.c_str());
|
2005-12-09 21:58:55 +03:00
|
|
|
if(!fin)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2005-12-09 21:58:55 +03:00
|
|
|
std::string line;
|
|
|
|
cmIncludeLines* cacheEntry=0;
|
|
|
|
bool haveFileName=false;
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2005-12-09 21:58:55 +03:00
|
|
|
while(cmSystemTools::GetLineFromStream(fin, line))
|
|
|
|
{
|
|
|
|
if (line.empty())
|
|
|
|
{
|
|
|
|
cacheEntry=0;
|
|
|
|
haveFileName=false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//the first line after an empty line is the name of the parsed file
|
|
|
|
if (haveFileName==false)
|
|
|
|
{
|
|
|
|
haveFileName=true;
|
|
|
|
int newer=0;
|
|
|
|
cmFileTimeComparison comp;
|
2011-12-18 18:42:48 +04:00
|
|
|
bool res=comp.FileTimeCompare(this->CacheFileName.c_str(),
|
2006-03-15 19:02:08 +03:00
|
|
|
line.c_str(), &newer);
|
2011-12-18 18:42:48 +04:00
|
|
|
|
2005-12-09 21:58:55 +03:00
|
|
|
if ((res==true) && (newer==1)) //cache is newer than the parsed file
|
|
|
|
{
|
|
|
|
cacheEntry=new cmIncludeLines;
|
2006-09-13 20:43:32 +04:00
|
|
|
this->FileCache[line]=cacheEntry;
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
2007-02-07 17:23:41 +03:00
|
|
|
// file doesn't exist, check that the regular expressions
|
|
|
|
// haven't changed
|
2007-02-05 17:48:38 +03:00
|
|
|
else if (res==false)
|
|
|
|
{
|
|
|
|
if (line.find(INCLUDE_REGEX_LINE_MARKER) == 0)
|
|
|
|
{
|
|
|
|
if (line != this->IncludeRegexLineString)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line.find(INCLUDE_REGEX_SCAN_MARKER) == 0)
|
|
|
|
{
|
|
|
|
if (line != this->IncludeRegexScanString)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line.find(INCLUDE_REGEX_COMPLAIN_MARKER) == 0)
|
|
|
|
{
|
|
|
|
if (line != this->IncludeRegexComplainString)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
else if (line.find(INCLUDE_REGEX_TRANSFORM_MARKER) == 0)
|
|
|
|
{
|
|
|
|
if (line != this->IncludeRegexTransformString)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-02-05 17:48:38 +03:00
|
|
|
}
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
|
|
|
else if (cacheEntry!=0)
|
|
|
|
{
|
|
|
|
UnscannedEntry entry;
|
|
|
|
entry.FileName = line;
|
|
|
|
if (cmSystemTools::GetLineFromStream(fin, line))
|
|
|
|
{
|
|
|
|
if (line!="-")
|
|
|
|
{
|
|
|
|
entry.QuotedLocation=line;
|
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
cacheEntry->UnscannedEntries.push_back(entry);
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmDependsC::WriteCacheFile() const
|
|
|
|
{
|
2006-03-16 17:33:23 +03:00
|
|
|
if(this->CacheFileName.size() == 0)
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream cacheOut(this->CacheFileName.c_str());
|
2005-12-09 21:58:55 +03:00
|
|
|
if(!cacheOut)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2011-12-18 18:42:48 +04:00
|
|
|
|
2007-02-05 17:48:38 +03:00
|
|
|
cacheOut << this->IncludeRegexLineString << "\n\n";
|
|
|
|
cacheOut << this->IncludeRegexScanString << "\n\n";
|
|
|
|
cacheOut << this->IncludeRegexComplainString << "\n\n";
|
2008-05-14 19:54:32 +04:00
|
|
|
cacheOut << this->IncludeRegexTransformString << "\n\n";
|
2007-02-05 17:48:38 +03:00
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
for (std::map<std::string, cmIncludeLines*>::const_iterator fileIt=
|
2006-09-13 20:43:32 +04:00
|
|
|
this->FileCache.begin();
|
|
|
|
fileIt!=this->FileCache.end(); ++fileIt)
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
if (fileIt->second->Used)
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
|
|
|
cacheOut<<fileIt->first.c_str()<<std::endl;
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2005-12-10 07:04:33 +03:00
|
|
|
for (std::vector<UnscannedEntry>::const_iterator
|
2011-12-18 18:42:48 +04:00
|
|
|
incIt=fileIt->second->UnscannedEntries.begin();
|
2006-03-15 19:02:08 +03:00
|
|
|
incIt!=fileIt->second->UnscannedEntries.end(); ++incIt)
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
|
|
|
cacheOut<<incIt->FileName.c_str()<<std::endl;
|
|
|
|
if (incIt->QuotedLocation.empty())
|
|
|
|
{
|
|
|
|
cacheOut<<"-"<<std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cacheOut<<incIt->QuotedLocation.c_str()<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cacheOut<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2006-03-10 21:06:26 +03:00
|
|
|
void cmDependsC::Scan(std::istream& is, const char* directory,
|
2014-02-10 09:21:34 +04:00
|
|
|
const std::string& fullName)
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
|
|
|
cmIncludeLines* newCacheEntry=new cmIncludeLines;
|
2006-03-15 19:02:08 +03:00
|
|
|
newCacheEntry->Used=true;
|
2006-09-13 20:43:32 +04:00
|
|
|
this->FileCache[fullName]=newCacheEntry;
|
2011-12-18 18:42:48 +04:00
|
|
|
|
2005-01-19 01:09:05 +03:00
|
|
|
// Read one line at a time.
|
|
|
|
std::string line;
|
|
|
|
while(cmSystemTools::GetLineFromStream(is, line))
|
|
|
|
{
|
2008-05-14 19:54:32 +04:00
|
|
|
// Transform the line content first.
|
|
|
|
if(!this->TransformRules.empty())
|
|
|
|
{
|
|
|
|
this->TransformLine(line);
|
|
|
|
}
|
|
|
|
|
2005-02-08 00:11:01 +03:00
|
|
|
// Match include directives.
|
2006-03-15 19:02:08 +03:00
|
|
|
if(this->IncludeRegexLine.find(line.c_str()))
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
|
|
|
// Get the file being included.
|
2005-03-03 23:22:18 +03:00
|
|
|
UnscannedEntry entry;
|
2006-09-26 16:04:23 +04:00
|
|
|
entry.FileName = this->IncludeRegexLine.match(2);
|
2011-01-17 23:03:53 +03:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(entry.FileName);
|
2006-09-26 16:04:23 +04:00
|
|
|
if(this->IncludeRegexLine.match(3) == "\"" &&
|
2006-01-06 01:16:22 +03:00
|
|
|
!cmSystemTools::FileIsFullPath(entry.FileName.c_str()))
|
2005-03-03 23:22:18 +03:00
|
|
|
{
|
2006-01-06 01:16:22 +03:00
|
|
|
// This was a double-quoted include with a relative path. We
|
|
|
|
// must check for the file in the directory containing the
|
|
|
|
// file we are scanning.
|
2013-06-19 16:35:23 +04:00
|
|
|
entry.QuotedLocation =
|
|
|
|
cmSystemTools::CollapseCombinedPath(directory, entry.FileName);
|
2005-03-03 23:22:18 +03:00
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
|
2005-02-08 00:11:01 +03:00
|
|
|
// Queue the file if it has not yet been encountered and it
|
2005-03-03 23:22:18 +03:00
|
|
|
// matches the regular expression for recursive scanning. Note
|
|
|
|
// that this check does not account for the possibility of two
|
|
|
|
// headers with the same name in different directories when one
|
|
|
|
// is included by double-quotes and the other by angle brackets.
|
2011-12-18 18:44:33 +04:00
|
|
|
// It also does not work properly if two header files with the same
|
|
|
|
// name exist in different directories, and both are included from a
|
|
|
|
// file their own directory by simply using "filename.h" (#12619)
|
2005-03-03 23:22:18 +03:00
|
|
|
// This kind of problem will be fixed when a more
|
|
|
|
// preprocessor-like implementation of this scanner is created.
|
2006-03-15 19:02:08 +03:00
|
|
|
if (this->IncludeRegexScan.find(entry.FileName.c_str()))
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
newCacheEntry->UnscannedEntries.push_back(entry);
|
|
|
|
if(this->Encountered.find(entry.FileName) == this->Encountered.end())
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Encountered.insert(entry.FileName);
|
|
|
|
this->Unscanned.push(entry);
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmDependsC::SetupTransforms()
|
|
|
|
{
|
|
|
|
// Get the transformation rules.
|
|
|
|
std::vector<std::string> transformRules;
|
|
|
|
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
|
|
|
if(const char* xform =
|
|
|
|
mf->GetDefinition("CMAKE_INCLUDE_TRANSFORMS"))
|
|
|
|
{
|
|
|
|
cmSystemTools::ExpandListArgument(xform, transformRules, true);
|
|
|
|
}
|
|
|
|
for(std::vector<std::string>::const_iterator tri = transformRules.begin();
|
|
|
|
tri != transformRules.end(); ++tri)
|
|
|
|
{
|
|
|
|
this->ParseTransform(*tri);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->IncludeRegexTransformString = INCLUDE_REGEX_TRANSFORM_MARKER;
|
|
|
|
if(!this->TransformRules.empty())
|
|
|
|
{
|
|
|
|
// Construct the regular expression to match lines to be
|
|
|
|
// transformed.
|
|
|
|
std::string xform = "^([ \t]*#[ \t]*(include|import)[ \t]*)(";
|
|
|
|
const char* sep = "";
|
|
|
|
for(TransformRulesType::const_iterator tri = this->TransformRules.begin();
|
|
|
|
tri != this->TransformRules.end(); ++tri)
|
|
|
|
{
|
|
|
|
xform += sep;
|
|
|
|
xform += tri->first;
|
|
|
|
sep = "|";
|
|
|
|
}
|
|
|
|
xform += ")[ \t]*\\(([^),]*)\\)";
|
|
|
|
this->IncludeRegexTransform.compile(xform.c_str());
|
|
|
|
|
|
|
|
// Build a string that encodes all transformation rules and will
|
|
|
|
// change when rules are changed.
|
|
|
|
this->IncludeRegexTransformString += xform;
|
|
|
|
for(TransformRulesType::const_iterator tri = this->TransformRules.begin();
|
|
|
|
tri != this->TransformRules.end(); ++tri)
|
|
|
|
{
|
|
|
|
this->IncludeRegexTransformString += " ";
|
|
|
|
this->IncludeRegexTransformString += tri->first;
|
|
|
|
this->IncludeRegexTransformString += "(%)=";
|
|
|
|
this->IncludeRegexTransformString += tri->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmDependsC::ParseTransform(std::string const& xform)
|
|
|
|
{
|
|
|
|
// A transform rule is of the form SOME_MACRO(%)=value-with-%
|
|
|
|
// We can simply separate with "(%)=".
|
|
|
|
std::string::size_type pos = xform.find("(%)=");
|
|
|
|
if(pos == xform.npos || pos == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::string name = xform.substr(0, pos);
|
|
|
|
std::string value = xform.substr(pos+4, xform.npos);
|
|
|
|
this->TransformRules[name] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmDependsC::TransformLine(std::string& line)
|
|
|
|
{
|
|
|
|
// Check for a transform rule match. Return if none.
|
|
|
|
if(!this->IncludeRegexTransform.find(line.c_str()))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TransformRulesType::const_iterator tri =
|
|
|
|
this->TransformRules.find(this->IncludeRegexTransform.match(3));
|
|
|
|
if(tri == this->TransformRules.end())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the transformed line.
|
|
|
|
std::string newline = this->IncludeRegexTransform.match(1);
|
|
|
|
std::string arg = this->IncludeRegexTransform.match(4);
|
|
|
|
for(const char* c = tri->second.c_str(); *c; ++c)
|
|
|
|
{
|
|
|
|
if(*c == '%')
|
|
|
|
{
|
|
|
|
newline += arg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newline += *c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the transformed line.
|
|
|
|
line = newline;
|
|
|
|
}
|