diff options
Diffstat (limited to 'Source/cmLoadCacheCommand.cxx')
-rw-r--r-- | Source/cmLoadCacheCommand.cxx | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/Source/cmLoadCacheCommand.cxx b/Source/cmLoadCacheCommand.cxx index 3fd7343..cca1633 100644 --- a/Source/cmLoadCacheCommand.cxx +++ b/Source/cmLoadCacheCommand.cxx @@ -3,24 +3,30 @@ #include "cmLoadCacheCommand.h" #include "cmsys/FStream.hxx" +#include <set> +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmake.h" -class cmExecutionStatus; +static bool ReadWithPrefix(std::vector<std::string> const& args, + cmExecutionStatus& status); -// cmLoadCacheCommand -bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +static void CheckLine(cmMakefile& mf, std::string const& prefix, + std::set<std::string> const& variablesToRead, + const char* line); + +bool cmLoadCacheCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with wrong number of arguments."); + status.SetError("called with wrong number of arguments."); } if (args.size() >= 2 && args[1] == "READ_WITH_PREFIX") { - return this->ReadWithPrefix(args); + return ReadWithPrefix(args, status); } // Cache entries to be excluded from the import list. @@ -59,24 +65,26 @@ bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& args, } } + cmMakefile& mf = status.GetMakefile(); + // Loop over each build directory listed in the arguments. Each // directory has a cache file. for (std::string const& arg : args) { if ((arg == "EXCLUDE") || (arg == "INCLUDE_INTERNALS")) { break; } - this->Makefile->GetCMakeInstance()->LoadCache(arg, false, excludes, - includes); + mf.GetCMakeInstance()->LoadCache(arg, false, excludes, includes); } return true; } -bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args) +static bool ReadWithPrefix(std::vector<std::string> const& args, + cmExecutionStatus& status) { // Make sure we have a prefix. if (args.size() < 3) { - this->SetError("READ_WITH_PREFIX form must specify a prefix."); + status.SetError("READ_WITH_PREFIX form must specify a prefix."); return false; } @@ -84,17 +92,19 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args) std::string cacheFile = args[0] + "/CMakeCache.txt"; if (!cmSystemTools::FileExists(cacheFile)) { std::string e = "Cannot load cache file from " + cacheFile; - this->SetError(e); + status.SetError(e); return false; } // Prepare the table of variables to read. - this->Prefix = args[2]; - this->VariablesToRead.insert(args.begin() + 3, args.end()); + std::string const prefix = args[2]; + std::set<std::string> const variablesToRead(args.begin() + 3, args.end()); // Read the cache file. cmsys::ifstream fin(cacheFile.c_str()); + cmMakefile& mf = status.GetMakefile(); + // This is a big hack read loop to overcome a buggy ifstream // implementation on HP-UX. This should work on all platforms even // for small buffer sizes. @@ -123,7 +133,7 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args) } if (i != end) { // Completed a line. - this->CheckLine(line.c_str()); + CheckLine(mf, prefix, variablesToRead, line.c_str()); line.clear(); // Skip the newline character. @@ -134,13 +144,15 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args) } if (!line.empty()) { // Partial last line. - this->CheckLine(line.c_str()); + CheckLine(mf, prefix, variablesToRead, line.c_str()); } return true; } -void cmLoadCacheCommand::CheckLine(const char* line) +static void CheckLine(cmMakefile& mf, std::string const& prefix, + std::set<std::string> const& variablesToRead, + const char* line) { // Check one line of the cache file. std::string var; @@ -148,14 +160,14 @@ void cmLoadCacheCommand::CheckLine(const char* line) cmStateEnums::CacheEntryType type = cmStateEnums::UNINITIALIZED; if (cmake::ParseCacheEntry(line, var, value, type)) { // Found a real entry. See if this one was requested. - if (this->VariablesToRead.find(var) != this->VariablesToRead.end()) { + if (variablesToRead.find(var) != variablesToRead.end()) { // This was requested. Set this variable locally with the given // prefix. - var = this->Prefix + var; + var = prefix + var; if (!value.empty()) { - this->Makefile->AddDefinition(var, value); + mf.AddDefinition(var, value); } else { - this->Makefile->RemoveDefinition(var); + mf.RemoveDefinition(var); } } } |