2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2001-05-09 12:51:54 +00:00
|
|
|
#include "cmLoadCacheCommand.h"
|
|
|
|
|
2014-01-04 05:47:13 +00:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-10-19 06:54:18 +00:00
|
|
|
|
|
|
|
#include "cmMakefile.h"
|
2016-10-25 18:35:04 +00:00
|
|
|
#include "cmStateTypes.h"
|
2016-10-19 06:54:18 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmake.h"
|
|
|
|
|
|
|
|
class cmExecutionStatus;
|
2001-05-09 12:51:54 +00:00
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
// cmLoadCacheCommand
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-05-09 12:51:54 +00:00
|
|
|
{
|
2016-09-15 21:59:29 +00:00
|
|
|
if (args.empty()) {
|
2001-08-15 17:40:56 +00:00
|
|
|
this->SetError("called with wrong number of arguments.");
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-03-29 19:20:32 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() >= 2 && args[1] == "READ_WITH_PREFIX") {
|
2002-11-20 23:00:02 +00:00
|
|
|
return this->ReadWithPrefix(args);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-08-16 15:41:44 +00:00
|
|
|
// Cache entries to be excluded from the import list.
|
|
|
|
// If this set is empty, all cache entries are brought in
|
|
|
|
// and they can not be overridden.
|
2016-05-16 14:34:04 +00:00
|
|
|
bool excludeFiles = false;
|
2001-08-15 17:40:56 +00:00
|
|
|
unsigned int i;
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> excludes;
|
2001-08-15 17:40:56 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < args.size(); i++) {
|
|
|
|
if (excludeFiles) {
|
2001-08-15 17:40:56 +00:00
|
|
|
excludes.insert(args[i]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (args[i] == "EXCLUDE") {
|
|
|
|
excludeFiles = true;
|
|
|
|
}
|
|
|
|
if (excludeFiles && (args[i] == "INCLUDE_INTERNALS")) {
|
2001-08-16 15:41:44 +00:00
|
|
|
break;
|
2001-05-09 12:51:54 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2001-05-09 12:51:54 +00:00
|
|
|
|
2001-08-16 15:41:44 +00:00
|
|
|
// Internal cache entries to be imported.
|
|
|
|
// If this set is empty, no internal cache entries are
|
|
|
|
// brought in.
|
2016-05-16 14:34:04 +00:00
|
|
|
bool includeFiles = false;
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> includes;
|
2001-08-16 15:41:44 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < args.size(); i++) {
|
|
|
|
if (includeFiles) {
|
2001-08-16 15:41:44 +00:00
|
|
|
includes.insert(args[i]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (args[i] == "INCLUDE_INTERNALS") {
|
|
|
|
includeFiles = true;
|
|
|
|
}
|
|
|
|
if (includeFiles && (args[i] == "EXCLUDE")) {
|
2001-08-16 15:41:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2001-08-16 15:41:44 +00:00
|
|
|
|
2002-01-22 15:17:37 +00:00
|
|
|
// Loop over each build directory listed in the arguments. Each
|
|
|
|
// directory has a cache file.
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < args.size(); i++) {
|
|
|
|
if ((args[i] == "EXCLUDE") || (args[i] == "INCLUDE_INTERNALS")) {
|
2001-08-15 17:40:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Makefile->GetCMakeInstance()->LoadCache(args[i], false, excludes,
|
|
|
|
includes);
|
|
|
|
}
|
2001-08-15 17:40:56 +00:00
|
|
|
|
2001-05-09 12:51:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
// Make sure we have a prefix.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() < 3) {
|
2002-11-20 23:00:02 +00:00
|
|
|
this->SetError("READ_WITH_PREFIX form must specify a prefix.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
// Make sure the cache file exists.
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string cacheFile = args[0] + "/CMakeCache.txt";
|
|
|
|
if (!cmSystemTools::FileExists(cacheFile.c_str())) {
|
2002-11-20 23:00:02 +00:00
|
|
|
std::string e = "Cannot load cache file from " + cacheFile;
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(e);
|
2002-11-20 23:00:02 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
// Prepare the table of variables to read.
|
|
|
|
this->Prefix = args[2];
|
2015-01-15 02:09:43 +00:00
|
|
|
this->VariablesToRead.insert(args.begin() + 3, args.end());
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
// Read the cache file.
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream fin(cacheFile.c_str());
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
// 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.
|
|
|
|
const int bufferSize = 4096;
|
2012-08-13 17:42:58 +00:00
|
|
|
char buffer[bufferSize];
|
2002-11-20 23:00:02 +00:00
|
|
|
std::string line;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (fin) {
|
2002-11-20 23:00:02 +00:00
|
|
|
// Read a block of the file.
|
|
|
|
fin.read(buffer, bufferSize);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (fin.gcount()) {
|
2002-11-20 23:00:02 +00:00
|
|
|
// Parse for newlines directly.
|
|
|
|
const char* i = buffer;
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* end = buffer + fin.gcount();
|
|
|
|
while (i != end) {
|
2002-11-20 23:00:02 +00:00
|
|
|
const char* begin = i;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (i != end && *i != '\n') {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i == begin || *(i - 1) != '\r') {
|
2002-11-20 23:00:02 +00:00
|
|
|
// Include this portion of the line.
|
2016-05-16 14:34:04 +00:00
|
|
|
line += std::string(begin, i - begin);
|
|
|
|
} else {
|
2002-11-20 23:00:02 +00:00
|
|
|
// Include this portion of the line.
|
|
|
|
// Don't include the \r in a \r\n pair.
|
2016-05-16 14:34:04 +00:00
|
|
|
line += std::string(begin, i - 1 - begin);
|
|
|
|
}
|
|
|
|
if (i != end) {
|
2002-11-20 23:00:02 +00:00
|
|
|
// Completed a line.
|
|
|
|
this->CheckLine(line.c_str());
|
|
|
|
line = "";
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
// Skip the newline character.
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!line.empty()) {
|
2002-11-20 23:00:02 +00:00
|
|
|
// Partial last line.
|
|
|
|
this->CheckLine(line.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-05-09 12:51:54 +00:00
|
|
|
|
2002-11-20 23:00:02 +00:00
|
|
|
void cmLoadCacheCommand::CheckLine(const char* line)
|
|
|
|
{
|
|
|
|
// Check one line of the cache file.
|
|
|
|
std::string var;
|
|
|
|
std::string value;
|
2016-10-18 19:28:47 +00:00
|
|
|
cmStateEnums::CacheEntryType type = cmStateEnums::UNINITIALIZED;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmake::ParseCacheEntry(line, var, value, type)) {
|
2002-11-20 23:00:02 +00:00
|
|
|
// Found a real entry. See if this one was requested.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->VariablesToRead.find(var) != this->VariablesToRead.end()) {
|
2002-11-20 23:00:02 +00:00
|
|
|
// This was requested. Set this variable locally with the given
|
|
|
|
// prefix.
|
|
|
|
var = this->Prefix + var;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!value.empty()) {
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->AddDefinition(var, value.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->RemoveDefinition(var);
|
2002-11-20 23:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-11-20 23:00:02 +00:00
|
|
|
}
|