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"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.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"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmOutputConverter.h"
|
2006-05-25 17:47:30 +04:00
|
|
|
#include "cmSystemTools.h"
|
2005-01-19 01:09:05 +03:00
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <cmsys/FStream.hxx>
|
|
|
|
#include <utility>
|
2005-05-10 19:00:15 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define INCLUDE_REGEX_LINE \
|
2007-02-07 17:23:41 +03:00
|
|
|
"^[ \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
|
|
|
|
2008-05-08 18:09:14 +04:00
|
|
|
cmDependsC::cmDependsC()
|
2016-06-27 23:44:16 +03:00
|
|
|
: ValidDeps(CM_NULLPTR)
|
2005-01-19 01:09:05 +03:00
|
|
|
{
|
|
|
|
}
|
2008-05-08 18:09:14 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmDependsC::cmDependsC(
|
|
|
|
cmLocalGenerator* lg, const char* targetDir, const std::string& lang,
|
|
|
|
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 = "^$";
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string scanRegexVar = "CMAKE_";
|
|
|
|
scanRegexVar += lang;
|
|
|
|
scanRegexVar += "_INCLUDE_REGEX_SCAN";
|
|
|
|
if (const char* sr = mf->GetDefinition(scanRegexVar)) {
|
|
|
|
scanRegex = sr;
|
2008-05-08 18:09:14 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string complainRegexVar = "CMAKE_";
|
|
|
|
complainRegexVar += lang;
|
|
|
|
complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
|
|
|
|
if (const char* cr = mf->GetDefinition(complainRegexVar)) {
|
|
|
|
complainRegex = cr;
|
2008-05-08 18:09:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (sources.empty() || sources.begin()->empty()) {
|
2005-07-27 17:49:37 +04:00
|
|
|
cmSystemTools::Error("Cannot scan dependencies without a source file.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03: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;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> dependencies;
|
2012-09-30 12:57:59 +04:00
|
|
|
bool haveDeps = false;
|
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
if (this->ValidDeps != CM_NULLPTR) {
|
2009-09-23 22:02:05 +04:00
|
|
|
std::map<std::string, DependencyVector>::const_iterator tmpIt =
|
2016-05-16 17:34:04 +03:00
|
|
|
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
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-23 22:02:05 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!haveDeps) {
|
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
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator srcIt = sources.begin();
|
|
|
|
srcIt != sources.end(); ++srcIt) {
|
2012-09-30 19:53:01 +04:00
|
|
|
UnscannedEntry root;
|
|
|
|
root.FileName = *srcIt;
|
|
|
|
this->Unscanned.push(root);
|
|
|
|
this->Encountered.insert(*srcIt);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-30 19:53:01 +04:00
|
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
tempPathStr.reserve(4 * 1024);
|
2012-09-30 13:05:45 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
while (!this->Unscanned.empty()) {
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((srcFiles > 0) ||
|
|
|
|
cmSystemTools::FileIsFullPath(current.FileName.c_str())) {
|
|
|
|
if (cmSystemTools::FileExists(current.FileName.c_str(), true)) {
|
2012-09-30 13:05:45 +04:00
|
|
|
fullName = current.FileName;
|
2005-02-08 00:11:01 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!current.QuotedLocation.empty() &&
|
|
|
|
cmSystemTools::FileExists(current.QuotedLocation.c_str(),
|
|
|
|
true)) {
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
std::map<std::string, std::string>::iterator headerLocationIt =
|
|
|
|
this->HeaderLocationCache.find(current.FileName);
|
|
|
|
if (headerLocationIt != this->HeaderLocationCache.end()) {
|
|
|
|
fullName = headerLocationIt->second;
|
2016-06-10 19:36:24 +03:00
|
|
|
} else {
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator i =
|
|
|
|
this->IncludePath.begin();
|
|
|
|
i != this->IncludePath.end(); ++i) {
|
|
|
|
// Construct the name of the file as if it were in the current
|
|
|
|
// include directory. Avoid using a leading "./".
|
|
|
|
|
|
|
|
tempPathStr =
|
|
|
|
cmSystemTools::CollapseCombinedPath(*i, current.FileName);
|
|
|
|
|
|
|
|
// Look for the file in this location.
|
|
|
|
if (cmSystemTools::FileExists(tempPathStr.c_str(), true)) {
|
|
|
|
fullName = tempPathStr;
|
|
|
|
HeaderLocationCache[current.FileName] = fullName;
|
|
|
|
break;
|
2012-09-30 13:05:45 +04:00
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fullName.empty() &&
|
|
|
|
this->IncludeRegexComplain.find(current.FileName.c_str())) {
|
|
|
|
cmSystemTools::Error("Cannot find file \"", current.FileName.c_str(),
|
|
|
|
"\".");
|
2012-09-30 13:05:45 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fullName.empty() && (scanned.find(fullName) == scanned.end())) {
|
2012-09-30 13:05:45 +04:00
|
|
|
// Record scanned files.
|
|
|
|
scanned.insert(fullName);
|
|
|
|
|
|
|
|
// Check whether this file is already in the cache
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<std::string, cmIncludeLines*>::iterator fileIt =
|
2012-09-30 13:05:45 +04:00
|
|
|
this->FileCache.find(fullName);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fileIt != this->FileCache.end()) {
|
|
|
|
fileIt->second->Used = true;
|
2012-09-30 13:05:45 +04:00
|
|
|
dependencies.insert(fullName);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<UnscannedEntry>::const_iterator incIt =
|
|
|
|
fileIt->second->UnscannedEntries.begin();
|
|
|
|
incIt != fileIt->second->UnscannedEntries.end(); ++incIt) {
|
2012-09-30 13:05:45 +04:00
|
|
|
if (this->Encountered.find(incIt->FileName) ==
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Encountered.end()) {
|
2012-09-30 13:05:45 +04:00
|
|
|
this->Encountered.insert(incIt->FileName);
|
|
|
|
this->Unscanned.push(*incIt);
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
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());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fin) {
|
2015-04-03 18:15:12 +03:00
|
|
|
cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (bom == cmsys::FStream::BOM_None ||
|
|
|
|
bom == cmsys::FStream::BOM_UTF8) {
|
2015-04-03 18:15:12 +03:00
|
|
|
// Add this file as a dependency.
|
|
|
|
dependencies.insert(fullName);
|
2012-09-30 13:05:45 +04:00
|
|
|
|
2015-04-03 18:15:12 +03:00
|
|
|
// 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);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-04-03 18:15:12 +03:00
|
|
|
// Skip file with encoding we do not implement.
|
2012-09-30 13:05:45 +04:00
|
|
|
}
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2012-09-30 19:53:01 +04:00
|
|
|
srcFiles--;
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +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.
|
2016-08-27 14:44:56 +03:00
|
|
|
std::string obj_i = this->LocalGenerator->ConvertToRelativePath(
|
2016-09-07 00:02:23 +03:00
|
|
|
this->LocalGenerator->GetBinaryDirectory(), obj);
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string obj_m = this->LocalGenerator->ConvertToOutputFormat(
|
2016-05-20 00:11:40 +03:00
|
|
|
obj_i, cmOutputConverter::MAKERULE);
|
2014-07-22 20:50:37 +04:00
|
|
|
internalDepends << obj_i << std::endl;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = dependencies.begin();
|
|
|
|
i != dependencies.end(); ++i) {
|
|
|
|
makeDepends << obj_m << ": "
|
2016-05-20 00:11:40 +03:00
|
|
|
<< this->LocalGenerator->Convert(
|
|
|
|
*i, cmOutputConverter::HOME_OUTPUT,
|
|
|
|
cmOutputConverter::MAKERULE)
|
2005-12-09 21:58:55 +03:00
|
|
|
<< std::endl;
|
2014-03-11 16:35:32 +04:00
|
|
|
internalDepends << " " << *i << std::endl;
|
2016-05-16 17:34:04 +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
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CacheFileName.empty()) {
|
2005-12-09 21:58:55 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(this->CacheFileName.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fin) {
|
2005-12-09 21:58:55 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2005-12-09 21:58:55 +03:00
|
|
|
std::string line;
|
2016-06-27 23:44:16 +03:00
|
|
|
cmIncludeLines* cacheEntry = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
bool haveFileName = false;
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
|
|
|
if (line.empty()) {
|
2016-06-27 23:44:16 +03:00
|
|
|
cacheEntry = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
haveFileName = false;
|
2005-12-09 21:58:55 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
// the first line after an empty line is the name of the parsed file
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!haveFileName) {
|
2016-05-16 17:34:04 +03:00
|
|
|
haveFileName = true;
|
|
|
|
int newer = 0;
|
2005-12-09 21:58:55 +03:00
|
|
|
cmFileTimeComparison comp;
|
2016-05-16 17:34:04 +03:00
|
|
|
bool res = comp.FileTimeCompare(this->CacheFileName.c_str(),
|
|
|
|
line.c_str(), &newer);
|
2011-12-18 18:42:48 +04:00
|
|
|
|
2016-06-02 00:29:53 +03:00
|
|
|
if (res && newer == 1) // cache is newer than the parsed file
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
cacheEntry = new cmIncludeLines;
|
|
|
|
this->FileCache[line] = cacheEntry;
|
|
|
|
}
|
2007-02-07 17:23:41 +03:00
|
|
|
// file doesn't exist, check that the regular expressions
|
|
|
|
// haven't changed
|
2016-06-02 00:29:53 +03:00
|
|
|
else if (!res) {
|
2016-05-16 17:34:04 +03:00
|
|
|
if (line.find(INCLUDE_REGEX_LINE_MARKER) == 0) {
|
|
|
|
if (line != this->IncludeRegexLineString) {
|
2007-02-05 17:48:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (line.find(INCLUDE_REGEX_SCAN_MARKER) == 0) {
|
|
|
|
if (line != this->IncludeRegexScanString) {
|
2007-02-05 17:48:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (line.find(INCLUDE_REGEX_COMPLAIN_MARKER) == 0) {
|
|
|
|
if (line != this->IncludeRegexComplainString) {
|
2007-02-05 17:48:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (line.find(INCLUDE_REGEX_TRANSFORM_MARKER) == 0) {
|
|
|
|
if (line != this->IncludeRegexTransformString) {
|
2008-05-14 19:54:32 +04:00
|
|
|
return;
|
|
|
|
}
|
2007-02-05 17:48:38 +03:00
|
|
|
}
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
2016-06-27 23:44:16 +03:00
|
|
|
} else if (cacheEntry != CM_NULLPTR) {
|
2005-12-09 21:58:55 +03:00
|
|
|
UnscannedEntry entry;
|
|
|
|
entry.FileName = line;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::GetLineFromStream(fin, line)) {
|
|
|
|
if (line != "-") {
|
|
|
|
entry.QuotedLocation = line;
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cacheEntry->UnscannedEntries.push_back(entry);
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmDependsC::WriteCacheFile() const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CacheFileName.empty()) {
|
2005-12-09 21:58:55 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream cacheOut(this->CacheFileName.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cacheOut) {
|
2005-12-09 21:58:55 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, cmIncludeLines*>::const_iterator fileIt =
|
2006-09-13 20:43:32 +04:00
|
|
|
this->FileCache.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
fileIt != this->FileCache.end(); ++fileIt) {
|
|
|
|
if (fileIt->second->Used) {
|
2016-06-07 00:53:32 +03:00
|
|
|
cacheOut << fileIt->first << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
|
|
|
|
for (std::vector<UnscannedEntry>::const_iterator incIt =
|
|
|
|
fileIt->second->UnscannedEntries.begin();
|
|
|
|
incIt != fileIt->second->UnscannedEntries.end(); ++incIt) {
|
2016-06-07 00:53:32 +03:00
|
|
|
cacheOut << incIt->FileName << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (incIt->QuotedLocation.empty()) {
|
|
|
|
cacheOut << "-" << std::endl;
|
|
|
|
} else {
|
2016-06-07 00:53:32 +03:00
|
|
|
cacheOut << incIt->QuotedLocation << std::endl;
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cacheOut << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2005-12-09 21:58:55 +03:00
|
|
|
}
|
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
void cmDependsC::Scan(std::istream& is, const char* directory,
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& fullName)
|
2005-12-09 21:58:55 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmIncludeLines* newCacheEntry = new cmIncludeLines;
|
|
|
|
newCacheEntry->Used = true;
|
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(is, line)) {
|
2008-05-14 19:54:32 +04:00
|
|
|
// Transform the line content first.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->TransformRules.empty()) {
|
2008-05-14 19:54:32 +04:00
|
|
|
this->TransformLine(line);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
|
2005-02-08 00:11:01 +03:00
|
|
|
// Match include directives.
|
2016-05-16 17:34:04 +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);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IncludeRegexLine.match(3) == "\"" &&
|
|
|
|
!cmSystemTools::FileIsFullPath(entry.FileName.c_str())) {
|
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);
|
2016-05-16 17:34:04 +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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IncludeRegexScan.find(entry.FileName.c_str())) {
|
2006-03-15 19:02:08 +03:00
|
|
|
newCacheEntry->UnscannedEntries.push_back(entry);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Encountered.find(entry.FileName) ==
|
|
|
|
this->Encountered.end()) {
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Encountered.insert(entry.FileName);
|
|
|
|
this->Unscanned.push(entry);
|
2005-01-19 01:09:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +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();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* xform = mf->GetDefinition("CMAKE_INCLUDE_TRANSFORMS")) {
|
2008-05-14 19:54:32 +04:00
|
|
|
cmSystemTools::ExpandListArgument(xform, transformRules, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator tri = transformRules.begin();
|
|
|
|
tri != transformRules.end(); ++tri) {
|
2008-05-14 19:54:32 +04:00
|
|
|
this->ParseTransform(*tri);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
|
|
|
|
this->IncludeRegexTransformString = INCLUDE_REGEX_TRANSFORM_MARKER;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->TransformRules.empty()) {
|
2008-05-14 19:54:32 +04:00
|
|
|
// Construct the regular expression to match lines to be
|
|
|
|
// transformed.
|
|
|
|
std::string xform = "^([ \t]*#[ \t]*(include|import)[ \t]*)(";
|
|
|
|
const char* sep = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (TransformRulesType::const_iterator tri = this->TransformRules.begin();
|
|
|
|
tri != this->TransformRules.end(); ++tri) {
|
2008-05-14 19:54:32 +04:00
|
|
|
xform += sep;
|
|
|
|
xform += tri->first;
|
|
|
|
sep = "|";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (TransformRulesType::const_iterator tri = this->TransformRules.begin();
|
|
|
|
tri != this->TransformRules.end(); ++tri) {
|
2008-05-14 19:54:32 +04:00
|
|
|
this->IncludeRegexTransformString += " ";
|
|
|
|
this->IncludeRegexTransformString += tri->first;
|
|
|
|
this->IncludeRegexTransformString += "(%)=";
|
|
|
|
this->IncludeRegexTransformString += tri->second;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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("(%)=");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pos == xform.npos || pos == 0) {
|
2008-05-14 19:54:32 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
std::string name = xform.substr(0, pos);
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string value = xform.substr(pos + 4, xform.npos);
|
2008-05-14 19:54:32 +04:00
|
|
|
this->TransformRules[name] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmDependsC::TransformLine(std::string& line)
|
|
|
|
{
|
|
|
|
// Check for a transform rule match. Return if none.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->IncludeRegexTransform.find(line.c_str())) {
|
2008-05-14 19:54:32 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
TransformRulesType::const_iterator tri =
|
|
|
|
this->TransformRules.find(this->IncludeRegexTransform.match(3));
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tri == this->TransformRules.end()) {
|
2008-05-14 19:54:32 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
|
|
|
|
// Construct the transformed line.
|
|
|
|
std::string newline = this->IncludeRegexTransform.match(1);
|
|
|
|
std::string arg = this->IncludeRegexTransform.match(4);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (const char* c = tri->second.c_str(); *c; ++c) {
|
|
|
|
if (*c == '%') {
|
2008-05-14 19:54:32 +04:00
|
|
|
newline += arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-05-14 19:54:32 +04:00
|
|
|
newline += *c;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-14 19:54:32 +04:00
|
|
|
|
|
|
|
// Return the transformed line.
|
|
|
|
line = newline;
|
|
|
|
}
|