Commit 2c50a725 authored by Vitaly Stakhovsky's avatar Vitaly Stakhovsky

cmDepends: all members accept std::string arguments

Most `const char*` arguments converted to `const std::string&`
in `cmDepends` and derived classes.
In addition performed minor code cleanup.
parent a61c061b
......@@ -13,7 +13,7 @@
#include <string.h>
#include <utility>
cmDepends::cmDepends(cmLocalGenerator* lg, const char* targetDir)
cmDepends::cmDepends(cmLocalGenerator* lg, const std::string& targetDir)
: LocalGenerator(lg)
, TargetDirectory(targetDir)
, Dependee(new char[MaxPath])
......@@ -65,12 +65,13 @@ bool cmDepends::Finalize(std::ostream& /*unused*/, std::ostream& /*unused*/)
return true;
}
bool cmDepends::Check(const char* makeFile, const char* internalFile,
bool cmDepends::Check(const std::string& makeFile,
const std::string& internalFile,
std::map<std::string, DependencyVector>& validDeps)
{
// Check whether dependencies must be regenerated.
bool okay = true;
cmsys::ifstream fin(internalFile);
cmsys::ifstream fin(internalFile.c_str());
if (!(fin && this->CheckDependencies(fin, internalFile, validDeps))) {
// Clear all dependencies so they will be regenerated.
this->Clear(makeFile);
......@@ -81,7 +82,7 @@ bool cmDepends::Check(const char* makeFile, const char* internalFile,
return okay;
}
void cmDepends::Clear(const char* file)
void cmDepends::Clear(const std::string& file)
{
// Print verbose output.
if (this->Verbose) {
......@@ -107,7 +108,7 @@ bool cmDepends::WriteDependencies(const std::set<std::string>& /*unused*/,
}
bool cmDepends::CheckDependencies(
std::istream& internalDepends, const char* internalDependsFileName,
std::istream& internalDepends, const std::string& internalDependsFileName,
std::map<std::string, DependencyVector>& validDeps)
{
// Parse dependencies from the stream. If any dependee is missing
......@@ -194,8 +195,8 @@ bool cmDepends::CheckDependencies(
// The dependee exists, but the depender doesn't. Regenerate if the
// internalDepends file is older than the dependee.
int result = 0;
if ((!this->FileComparison->FileTimeCompare(internalDependsFileName,
dependee, &result) ||
if ((!this->FileComparison->FileTimeCompare(
internalDependsFileName.c_str(), dependee, &result) ||
result < 0)) {
// The depends-file is older than the dependee.
regenerate = true;
......
......@@ -29,7 +29,7 @@ class cmDepends
public:
/** Instances need to know the build directory name and the relative
path from the build directory to the target file. */
cmDepends(cmLocalGenerator* lg = nullptr, const char* targetDir = "");
cmDepends(cmLocalGenerator* lg = nullptr, const std::string& targetDir = "");
/** Set the local generator for the directory in which we are
scanning dependencies. This is not a full local generator; it
......@@ -41,7 +41,10 @@ public:
void SetLanguage(const std::string& lang) { this->Language = lang; }
/** Set the target build directory. */
void SetTargetDirectory(const char* dir) { this->TargetDirectory = dir; }
void SetTargetDirectory(const std::string& dir)
{
this->TargetDirectory = dir;
}
/** should this be verbose in its output */
void SetVerbose(bool verb) { this->Verbose = verb; }
......@@ -61,11 +64,11 @@ public:
they must be generated Clear has already been called to wipe out
the old dependencies.
Dependencies which are still valid will be stored in validDeps. */
bool Check(const char* makeFile, const char* internalFile,
bool Check(const std::string& makeFile, const std::string& internalFile,
std::map<std::string, DependencyVector>& validDeps);
/** Clear dependencies for the target file so they will be regenerated. */
void Clear(const char* file);
void Clear(const std::string& file);
/** Set the file comparison object */
void SetFileComparison(cmFileTimeComparison* fc)
......@@ -85,7 +88,7 @@ protected:
// Return false if dependencies must be regenerated and true
// otherwise.
virtual bool CheckDependencies(
std::istream& internalDepends, const char* internalDependsFileName,
std::istream& internalDepends, const std::string& internalDependsFileName,
std::map<std::string, DependencyVector>& validDeps);
// Finalize the dependency information for the target.
......
......@@ -24,7 +24,7 @@ cmDependsC::cmDependsC()
}
cmDependsC::cmDependsC(
cmLocalGenerator* lg, const char* targetDir, const std::string& lang,
cmLocalGenerator* lg, const std::string& targetDir, const std::string& lang,
const std::map<std::string, DependencyVector>* validDeps)
: cmDepends(lg, targetDir)
, ValidDeps(validDeps)
......@@ -53,8 +53,8 @@ cmDependsC::cmDependsC(
}
this->IncludeRegexLine.compile(INCLUDE_REGEX_LINE);
this->IncludeRegexScan.compile(scanRegex.c_str());
this->IncludeRegexComplain.compile(complainRegex.c_str());
this->IncludeRegexScan.compile(scanRegex);
this->IncludeRegexComplain.compile(complainRegex);
this->IncludeRegexLineString = INCLUDE_REGEX_LINE_MARKER INCLUDE_REGEX_LINE;
this->IncludeRegexScanString = INCLUDE_REGEX_SCAN_MARKER;
this->IncludeRegexScanString += scanRegex;
......@@ -212,7 +212,7 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
// 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);
this->Scan(fin, dir, fullName);
} else {
// Skip file with encoding we do not implement.
}
......@@ -342,7 +342,7 @@ void cmDependsC::WriteCacheFile() const
}
}
void cmDependsC::Scan(std::istream& is, const char* directory,
void cmDependsC::Scan(std::istream& is, const std::string& directory,
const std::string& fullName)
{
cmIncludeLines* newCacheEntry = new cmIncludeLines;
......@@ -418,7 +418,7 @@ void cmDependsC::SetupTransforms()
sep = "|";
}
xform += ")[ \t]*\\(([^),]*)\\)";
this->IncludeRegexTransform.compile(xform.c_str());
this->IncludeRegexTransform.compile(xform);
// Build a string that encodes all transformation rules and will
// change when rules are changed.
......@@ -460,11 +460,11 @@ void cmDependsC::TransformLine(std::string& line)
// 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 == '%') {
for (char c : tri->second) {
if (c == '%') {
newline += arg;
} else {
newline += *c;
newline += c;
}
}
......
......@@ -28,7 +28,7 @@ public:
/** Checking instances need to know the build directory name and the
relative path from the build directory to the target file. */
cmDependsC();
cmDependsC(cmLocalGenerator* lg, const char* targetDir,
cmDependsC(cmLocalGenerator* lg, const std::string& targetDir,
const std::string& lang,
const std::map<std::string, DependencyVector>* validDeps);
......@@ -42,7 +42,7 @@ protected:
std::ostream& internalDepends) override;
// Method to scan a single file.
void Scan(std::istream& is, const char* directory,
void Scan(std::istream& is, const std::string& directory,
const std::string& fullName);
// Regular expression to identify C preprocessor include directives.
......
......@@ -7,7 +7,6 @@
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include "cmAlgorithms.h"
......@@ -54,7 +53,8 @@ public:
typedef std::map<std::string, cmFortranSourceInfo> ObjectInfoMap;
ObjectInfoMap ObjectInfo;
cmFortranSourceInfo& CreateObjectInfo(const char* obj, const char* src)
cmFortranSourceInfo& CreateObjectInfo(const std::string& obj,
const std::string& src)
{
std::map<std::string, cmFortranSourceInfo>::iterator i =
this->ObjectInfo.find(obj);
......@@ -121,8 +121,7 @@ bool cmDependsFortran::WriteDependencies(const std::set<std::string>& sources,
bool okay = true;
for (std::string const& src : sources) {
// Get the information object for this source.
cmFortranSourceInfo& info =
this->Internal->CreateObjectInfo(obj.c_str(), src.c_str());
cmFortranSourceInfo& info = this->Internal->CreateObjectInfo(obj, src);
// Create the parser object. The constructor takes info by reference,
// so we may look into the resulting objects later.
......@@ -153,7 +152,7 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
this->LocateModules();
// Get the directory in which stamp files will be stored.
const char* stamp_dir = this->TargetDirectory.c_str();
const std::string& stamp_dir = this->TargetDirectory;
// Get the directory in which module files will be created.
cmMakefile* mf = this->LocalGenerator->GetMakefile();
......@@ -167,9 +166,8 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
typedef cmDependsFortranInternals::ObjectInfoMap ObjectInfoMap;
ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
for (auto const& i : objInfo) {
if (!this->WriteDependenciesReal(i.first.c_str(), i.second, mod_dir,
stamp_dir, makeDepends,
internalDepends)) {
if (!this->WriteDependenciesReal(i.first, i.second, mod_dir, stamp_dir,
makeDepends, internalDepends)) {
return false;
}
}
......@@ -256,22 +254,22 @@ void cmDependsFortran::LocateModules()
std::string fname = targetDir + "/fortran.internal";
cmsys::ifstream fin(fname.c_str());
if (fin) {
this->MatchRemoteModules(fin, targetDir.c_str());
this->MatchRemoteModules(fin, targetDir);
}
}
}
void cmDependsFortran::MatchLocalModules()
{
const char* stampDir = this->TargetDirectory.c_str();
std::string const& stampDir = this->TargetDirectory;
std::set<std::string> const& provides = this->Internal->TargetProvides;
for (std::string const& i : provides) {
this->ConsiderModule(i.c_str(), stampDir);
this->ConsiderModule(i, stampDir);
}
}
void cmDependsFortran::MatchRemoteModules(std::istream& fin,
const char* stampDir)
const std::string& stampDir)
{
std::string line;
bool doing_provides = false;
......@@ -300,7 +298,8 @@ void cmDependsFortran::MatchRemoteModules(std::istream& fin,
}
}
void cmDependsFortran::ConsiderModule(const char* name, const char* stampDir)
void cmDependsFortran::ConsiderModule(const std::string& name,
const std::string& stampDir)
{
// Locate each required module.
typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
......@@ -317,17 +316,17 @@ void cmDependsFortran::ConsiderModule(const char* name, const char* stampDir)
}
}
bool cmDependsFortran::WriteDependenciesReal(const char* obj,
bool cmDependsFortran::WriteDependenciesReal(std::string const& obj,
cmFortranSourceInfo const& info,
std::string const& mod_dir,
const char* stamp_dir,
std::string const& stamp_dir,
std::ostream& makeDepends,
std::ostream& internalDepends)
{
typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
// Get the source file for this object.
const char* src = info.Source.c_str();
std::string const& src = info.Source;
// Write the include dependencies to the output stream.
std::string binDir = this->LocalGenerator->GetBinaryDirectory();
......@@ -502,8 +501,7 @@ bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
cmFortranModuleAppendUpperLower(cmSystemTools::GetFilenameName(mod),
mod_upper, mod_lower);
if (cmSystemTools::FileExists(mod_upper, true)) {
if (cmDependsFortran::ModulesDiffer(mod_upper.c_str(), stamp.c_str(),
compilerId.c_str())) {
if (cmDependsFortran::ModulesDiffer(mod_upper, stamp, compilerId)) {
if (!cmSystemTools::CopyFileAlways(mod_upper, stamp)) {
std::cerr << "Error copying Fortran module from \"" << mod_upper
<< "\" to \"" << stamp << "\".\n";
......@@ -513,8 +511,7 @@ bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
return true;
}
if (cmSystemTools::FileExists(mod_lower, true)) {
if (cmDependsFortran::ModulesDiffer(mod_lower.c_str(), stamp.c_str(),
compilerId.c_str())) {
if (cmDependsFortran::ModulesDiffer(mod_lower, stamp, compilerId)) {
if (!cmSystemTools::CopyFileAlways(mod_lower, stamp)) {
std::cerr << "Error copying Fortran module from \"" << mod_lower
<< "\" to \"" << stamp << "\".\n";
......@@ -581,9 +578,9 @@ static bool cmFortranStreamsDiffer(std::istream& ifs1, std::istream& ifs2)
return true;
}
bool cmDependsFortran::ModulesDiffer(const char* modFile,
const char* stampFile,
const char* compilerId)
bool cmDependsFortran::ModulesDiffer(const std::string& modFile,
const std::string& stampFile,
const std::string& compilerId)
{
/*
gnu >= 4.9:
......@@ -617,16 +614,17 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
* source is compiled twice
* -SunPro
*/
if (strcmp(compilerId, "SunPro") == 0) {
if (compilerId == "SunPro") {
return cmSystemTools::FilesDiffer(modFile, stampFile);
}
#if defined(_WIN32) || defined(__CYGWIN__)
cmsys::ifstream finModFile(modFile, std::ios::in | std::ios::binary);
cmsys::ifstream finStampFile(stampFile, std::ios::in | std::ios::binary);
cmsys::ifstream finModFile(modFile.c_str(), std::ios::in | std::ios::binary);
cmsys::ifstream finStampFile(stampFile.c_str(),
std::ios::in | std::ios::binary);
#else
cmsys::ifstream finModFile(modFile);
cmsys::ifstream finStampFile(stampFile);
cmsys::ifstream finModFile(modFile.c_str());
cmsys::ifstream finStampFile(stampFile.c_str());
#endif
if (!finModFile || !finStampFile) {
// At least one of the files does not exist. The modules differ.
......@@ -641,7 +639,7 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
* Eat the stream content until all recompile only related changes
* are left behind.
*/
if (strcmp(compilerId, "GNU") == 0) {
if (compilerId == "GNU") {
// GNU Fortran 4.9 and later compress .mod files with gzip
// but also do not include a date so we can fall through to
// compare them without skipping any prefix.
......@@ -664,7 +662,7 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
return true;
}
}
} else if (strcmp(compilerId, "Intel") == 0) {
} else if (compilerId == "Intel") {
const char seq[2] = { '\n', '\0' };
const int seqlen = 2;
......
......@@ -44,8 +44,9 @@ public:
/** Determine if a mod file and the corresponding mod.stamp file
are representing different module information. */
static bool ModulesDiffer(const char* modFile, const char* stampFile,
const char* compilerId);
static bool ModulesDiffer(const std::string& modFile,
const std::string& stampFile,
const std::string& compilerId);
protected:
// Finalize the dependency information for the target.
......@@ -55,8 +56,8 @@ protected:
// Find all the modules required by the target.
void LocateModules();
void MatchLocalModules();
void MatchRemoteModules(std::istream& fin, const char* stampDir);
void ConsiderModule(const char* name, const char* stampDir);
void MatchRemoteModules(std::istream& fin, const std::string& stampDir);
void ConsiderModule(const std::string& name, const std::string& stampDir);
bool FindModule(std::string const& name, std::string& module);
// Implement writing/checking methods required by superclass.
......@@ -65,8 +66,10 @@ protected:
std::ostream& internalDepends) override;
// Actually write the dependencies to the streams.
bool WriteDependenciesReal(const char* obj, cmFortranSourceInfo const& info,
std::string const& mod_dir, const char* stamp_dir,
bool WriteDependenciesReal(std::string const& obj,
cmFortranSourceInfo const& info,
std::string const& mod_dir,
std::string const& stamp_dir,
std::ostream& makeDepends,
std::ostream& internalDepends);
......
......@@ -27,7 +27,8 @@ bool cmDependsJava::WriteDependencies(const std::set<std::string>& sources,
}
bool cmDependsJava::CheckDependencies(
std::istream& /*internalDepends*/, const char* /*internalDependsFileName*/,
std::istream& /*internalDepends*/,
const std::string& /*internalDependsFileName*/,
std::map<std::string, DependencyVector>& /*validDeps*/)
{
return true;
......
......@@ -33,7 +33,7 @@ protected:
const std::string& file, std::ostream& makeDepends,
std::ostream& internalDepends) override;
bool CheckDependencies(
std::istream& internalDepends, const char* internalDependsFileName,
std::istream& internalDepends, const std::string& internalDependsFileName,
std::map<std::string, DependencyVector>& validDeps) override;
};
......
......@@ -1333,8 +1333,8 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
// dependency vector. This means that in the normal case, when only
// few or one file have been edited, then also only this one file is
// actually scanned again, instead of all files for this target.
needRescanDependencies = !checker.Check(
dependFile.c_str(), internalDependFile.c_str(), validDependencies);
needRescanDependencies =
!checker.Check(dependFile, internalDependFile, validDependencies);
}
if (needRescanDependInfo || needRescanDirInfo || needRescanDependencies) {
......@@ -1347,7 +1347,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
cmsysTerminal_Color_ForegroundBold,
message.c_str(), true, color);
return this->ScanDependencies(dir.c_str(), validDependencies);
return this->ScanDependencies(dir, validDependencies);
}
// The dependencies are already up-to-date.
......@@ -1355,7 +1355,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
}
bool cmLocalUnixMakefileGenerator3::ScanDependencies(
const char* targetDir,
const std::string& targetDir,
std::map<std::string, cmDepends::DependencyVector>& validDeps)
{
// Read the directory information file.
......@@ -1393,12 +1393,9 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
cmSystemTools::Error("Directory Information file not found");
}
// create the file stream for the depends file
std::string dir = targetDir;
// Open the make depends file. This should be copy-if-different
// because the make tool may try to reload it needlessly otherwise.
std::string ruleFileNameFull = dir;
std::string ruleFileNameFull = targetDir;
ruleFileNameFull += "/depend.make";
cmGeneratedFileStream ruleFileStream(
ruleFileNameFull, false, this->GlobalGenerator->GetMakefileEncoding());
......@@ -1410,7 +1407,7 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
// Open the cmake dependency tracking file. This should not be
// copy-if-different because dependencies are re-scanned when it is
// older than the DependInfo.cmake.
std::string internalRuleFileNameFull = dir;
std::string internalRuleFileNameFull = targetDir;
internalRuleFileNameFull += "/depend.internal";
cmGeneratedFileStream internalRuleFileStream(
internalRuleFileNameFull, false,
......@@ -1451,7 +1448,7 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
scanner->SetFileComparison(
this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
scanner->SetLanguage(lang);
scanner->SetTargetDirectory(dir.c_str());
scanner->SetTargetDirectory(targetDir);
scanner->Write(ruleFileStream, internalRuleFileStream);
// free the scanner for this language
......@@ -1720,7 +1717,7 @@ void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf,
// Clear the implicit dependency makefile.
std::string dependFile = dir + "/depend.make";
clearer.Clear(dependFile.c_str());
clearer.Clear(dependFile);
// Remove the internal dependency check file to force
// regeneration.
......
......@@ -245,7 +245,7 @@ protected:
// Helper methods for dependency updates.
bool ScanDependencies(
const char* targetDir,
const std::string& targetDir,
std::map<std::string, cmDepends::DependencyVector>& validDeps);
void CheckMultipleOutputs(bool verbose);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment