summaryrefslogtreecommitdiffstats
path: root/Source/cmFileCommand.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx180
1 files changed, 120 insertions, 60 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index d994659..f740020 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -15,7 +15,10 @@
#include "cmHexFileConverter.h"
#include "cmInstallType.h"
#include "cmFileTimeComparison.h"
+#include "cmLocalGenerator.h"
+#include "cmGlobalGenerator.h"
#include "cmCryptoHash.h"
+#include "cmAlgorithms.h"
#include "cmTimestamp.h"
@@ -63,7 +66,7 @@ static mode_t mode_setuid = S_ISUID;
static mode_t mode_setgid = S_ISGID;
#endif
-#if defined(WIN32) && defined(CMAKE_ENCODING_UTF8)
+#if defined(_WIN32) && defined(CMAKE_ENCODING_UTF8)
// libcurl doesn't support file:// urls for unicode filenames on Windows.
// Convert string from UTF-8 to ACP if this is a file:// URL.
static std::string fix_file_url_windows(const std::string& url)
@@ -71,7 +74,7 @@ static std::string fix_file_url_windows(const std::string& url)
std::string ret = url;
if(strncmp(url.c_str(), "file://", 7) == 0)
{
- cmsys_stl::wstring wurl = cmsys::Encoding::ToWide(url);
+ std::wstring wurl = cmsys::Encoding::ToWide(url);
if(!wurl.empty())
{
int mblen = WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1,
@@ -217,7 +220,6 @@ bool cmFileCommand
bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
bool append)
{
- std::string message;
std::vector<std::string>::const_iterator i = args.begin();
i++; // Get rid of subcommand
@@ -225,16 +227,12 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
std::string fileName = *i;
if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
{
- fileName = this->Makefile->GetCurrentDirectory();
+ fileName = this->Makefile->GetCurrentSourceDirectory();
fileName += "/" + *i;
}
i++;
- for(;i != args.end(); ++i)
- {
- message += *i;
- }
if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) )
{
std::string e
@@ -272,6 +270,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
this->SetError(error);
return false;
}
+ std::string message = cmJoin(cmRange(i, args.end()), std::string());
file << message;
file.close();
if(mode)
@@ -310,7 +309,7 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
std::string fileName = fileNameArg.GetString();
if ( !cmsys::SystemTools::FileIsFullPath(fileName.c_str()) )
{
- fileName = this->Makefile->GetCurrentDirectory();
+ fileName = this->Makefile->GetCurrentSourceDirectory();
fileName += "/" + fileNameArg.GetString();
}
@@ -446,7 +445,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
std::string fileName = args[1];
if(!cmsys::SystemTools::FileIsFullPath(fileName.c_str()))
{
- fileName = this->Makefile->GetCurrentDirectory();
+ fileName = this->Makefile->GetCurrentSourceDirectory();
fileName += "/" + args[1];
}
@@ -646,7 +645,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
if (hex_conversion_enabled)
{
// TODO: should work without temp file, but just on a memory buffer
- std::string binaryFileName = this->Makefile->GetCurrentOutputDirectory();
+ std::string binaryFileName = this->Makefile->GetCurrentBinaryDirectory();
binaryFileName += cmake::GetCMakeFilesDirectory();
binaryFileName += "/FileCommandStringsBinaryFile";
if(cmHexFileConverter::TryConvert(fileName.c_str(),binaryFileName.c_str()))
@@ -907,13 +906,13 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
{
switch(status)
{
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
g.RecurseThroughSymlinksOff();
break;
case cmPolicies::OLD:
case cmPolicies::WARN:
- case cmPolicies::REQUIRED_IF_USED:
- case cmPolicies::REQUIRED_ALWAYS:
g.RecurseThroughSymlinksOn();
break;
}
@@ -923,6 +922,35 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
bool first = true;
for ( ; i != args.end(); ++i )
{
+ if( *i == "LIST_DIRECTORIES" )
+ {
+ ++i;
+ if(i != args.end())
+ {
+ if(cmSystemTools::IsOn(i->c_str()))
+ {
+ g.SetListDirs(true);
+ g.SetRecurseListDirs(true);
+ }
+ else if(cmSystemTools::IsOff(i->c_str()))
+ {
+ g.SetListDirs(false);
+ g.SetRecurseListDirs(false);
+ }
+ else
+ {
+ this->SetError("LIST_DIRECTORIES missing bool value.");
+ return false;
+ }
+ }
+ else
+ {
+ this->SetError("LIST_DIRECTORIES missing bool value.");
+ return false;
+ }
+ ++i;
+ }
+
if ( recurse && (*i == "FOLLOW_SYMLINKS") )
{
explicitFollowSymlinks = true;
@@ -953,23 +981,50 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
}
}
+ cmsys::Glob::GlobMessages globMessages;
if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
{
- std::string expr = this->Makefile->GetCurrentDirectory();
+ std::string expr = this->Makefile->GetCurrentSourceDirectory();
// Handle script mode
if (!expr.empty())
{
expr += "/" + *i;
- g.FindFiles(expr);
+ g.FindFiles(expr, &globMessages);
}
else
{
- g.FindFiles(*i);
+ g.FindFiles(*i, &globMessages);
}
}
else
{
- g.FindFiles(*i);
+ g.FindFiles(*i, &globMessages);
+ }
+
+ if(!globMessages.empty())
+ {
+ bool shouldExit = false;
+ for(cmsys::Glob::GlobMessagesIterator it=globMessages.begin();
+ it != globMessages.end(); ++it)
+ {
+ if(it->type == cmsys::Glob::cyclicRecursion)
+ {
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ "Cyclic recursion detected while globbing for '"
+ + *i + "':\n" + it->content);
+ }
+ else
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "Error has occured while globbing for '"
+ + *i + "' - " + it->content);
+ shouldExit = true;
+ }
+ }
+ if(shouldExit)
+ {
+ return false;
+ }
}
std::vector<std::string>::size_type cc;
@@ -989,6 +1044,8 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
{
switch (status)
{
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
// Correct behavior, yay!
break;
@@ -1001,17 +1058,9 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
if(g.GetFollowedSymlinkCount() != 0)
{
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
- this->Makefile->GetPolicies()->
- GetPolicyWarning(cmPolicies::CMP0009));
+ cmPolicies::GetPolicyWarning(cmPolicies::CMP0009));
}
break;
- case cmPolicies::REQUIRED_IF_USED:
- case cmPolicies::REQUIRED_ALWAYS:
- this->SetError("policy CMP0009 error");
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
- this->Makefile->GetPolicies()->
- GetRequiredPolicyError(cmPolicies::CMP0009));
- return false;
}
}
@@ -1036,7 +1085,7 @@ bool cmFileCommand::HandleMakeDirectoryCommand(
const std::string* cdir = &(*i);
if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
{
- expr = this->Makefile->GetCurrentDirectory();
+ expr = this->Makefile->GetCurrentSourceDirectory();
expr += "/" + *i;
cdir = &expr;
}
@@ -1501,7 +1550,7 @@ bool cmFileCopier::CheckValue(std::string const& arg)
}
else
{
- std::string file = this->Makefile->GetCurrentDirectory();
+ std::string file = this->Makefile->GetCurrentSourceDirectory();
file += "/" + arg;
this->Files.push_back(file);
}
@@ -1513,7 +1562,7 @@ bool cmFileCopier::CheckValue(std::string const& arg)
}
else
{
- this->Destination = this->Makefile->GetCurrentOutputDirectory();
+ this->Destination = this->Makefile->GetCurrentBinaryDirectory();
this->Destination += "/" + arg;
}
this->Doing = DoingNone;
@@ -1843,7 +1892,7 @@ bool cmFileCopier::InstallDirectory(const char* source,
if(!(strcmp(dir.GetFile(fileNum), ".") == 0 ||
strcmp(dir.GetFile(fileNum), "..") == 0))
{
- cmsys_stl::string fromPath = source;
+ std::string fromPath = source;
fromPath += "/";
fromPath += dir.GetFile(fileNum);
std::string toPath = destination;
@@ -2603,13 +2652,13 @@ bool cmFileCommand::HandleRename(std::vector<std::string> const& args)
std::string oldname = args[1];
if(!cmsys::SystemTools::FileIsFullPath(oldname.c_str()))
{
- oldname = this->Makefile->GetCurrentDirectory();
+ oldname = this->Makefile->GetCurrentSourceDirectory();
oldname += "/" + args[1];
}
std::string newname = args[2];
if(!cmsys::SystemTools::FileIsFullPath(newname.c_str()))
{
- newname = this->Makefile->GetCurrentDirectory();
+ newname = this->Makefile->GetCurrentSourceDirectory();
newname += "/" + args[2];
}
@@ -2643,7 +2692,7 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
std::string fileName = *i;
if(!cmsys::SystemTools::FileIsFullPath(fileName.c_str()))
{
- fileName = this->Makefile->GetCurrentDirectory();
+ fileName = this->Makefile->GetCurrentSourceDirectory();
fileName += "/" + *i;
}
@@ -2745,13 +2794,36 @@ namespace {
static size_t
- cmFileCommandCurlDebugCallback(CURL *, curl_infotype, char *chPtr,
+ cmFileCommandCurlDebugCallback(CURL *, curl_infotype type, char *chPtr,
size_t size, void *data)
{
cmFileCommandVectorOfChar *vec
= static_cast<cmFileCommandVectorOfChar*>(data);
- vec->insert(vec->end(), chPtr, chPtr + size);
- return size;
+ switch(type)
+ {
+ case CURLINFO_TEXT:
+ case CURLINFO_HEADER_IN:
+ case CURLINFO_HEADER_OUT:
+ vec->insert(vec->end(), chPtr, chPtr + size);
+ break;
+ case CURLINFO_DATA_IN:
+ case CURLINFO_DATA_OUT:
+ case CURLINFO_SSL_DATA_IN:
+ case CURLINFO_SSL_DATA_OUT:
+ {
+ char buf[128];
+ int n = sprintf(buf, "[%" cmIML_INT_PRIu64 " bytes data]\n",
+ static_cast<cmIML_INT_uint64_t>(size));
+ if (n > 0)
+ {
+ vec->insert(vec->end(), buf, buf + n);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return 0;
}
@@ -2910,7 +2982,7 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
long timeout = 0;
long inactivity_timeout = 0;
- std::string verboseLog;
+ std::string logVar;
std::string statusVar;
bool tls_verify = this->Makefile->IsOn("CMAKE_TLS_VERIFY");
const char* cainfo = this->Makefile->GetDefinition("CMAKE_TLS_CAINFO");
@@ -2955,7 +3027,7 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
this->SetError("DOWNLOAD missing VAR for LOG.");
return false;
}
- verboseLog = *i;
+ logVar = *i;
}
else if(*i == "STATUS")
{
@@ -3084,7 +3156,7 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
return false;
}
-#if defined(WIN32) && defined(CMAKE_ENCODING_UTF8)
+#if defined(_WIN32) && defined(CMAKE_ENCODING_UTF8)
url = fix_file_url_windows(url);
#endif
@@ -3147,7 +3219,7 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
check_curl_result(res, "DOWNLOAD cannot set follow-redirect option: ");
- if(!verboseLog.empty())
+ if(!logVar.empty())
{
res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
check_curl_result(res, "DOWNLOAD cannot set verbose: ");
@@ -3234,22 +3306,10 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
}
}
- if(!chunkDebug.empty())
+ if (!logVar.empty())
{
chunkDebug.push_back(0);
- if(CURLE_OPERATION_TIMEOUTED == res)
- {
- std::string output = &*chunkDebug.begin();
-
- if(!verboseLog.empty())
- {
- this->Makefile->AddDefinition(verboseLog,
- &*chunkDebug.begin());
- }
- }
-
- this->Makefile->AddDefinition(verboseLog,
- &*chunkDebug.begin());
+ this->Makefile->AddDefinition(logVar, &*chunkDebug.begin());
}
return true;
@@ -3351,7 +3411,7 @@ cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
unsigned long file_size = cmsys::SystemTools::FileLength(filename);
-#if defined(WIN32) && defined(CMAKE_ENCODING_UTF8)
+#if defined(_WIN32) && defined(CMAKE_ENCODING_UTF8)
url = fix_file_url_windows(url);
#endif
@@ -3369,6 +3429,7 @@ cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
// enable HTTP ERROR parsing
::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+ check_curl_result(res, "UPLOAD cannot set fail on error flag: ");
// enable uploading
res = ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
@@ -3512,8 +3573,7 @@ void cmFileCommand::AddEvaluationFile(const std::string &inputName,
cmsys::auto_ptr<cmCompiledGeneratorExpression> conditionCge
= conditionGe.Parse(condition);
- this->Makefile->GetLocalGenerator()
- ->GetGlobalGenerator()->AddEvaluationFile(inputName,
+ this->Makefile->GetGlobalGenerator()->AddEvaluationFile(inputName,
outputCge,
this->Makefile,
conditionCge,
@@ -3687,7 +3747,7 @@ bool cmFileCommand::HandleLockCommand(
if (!cmsys::SystemTools::FileIsFullPath(path))
{
- path = this->Makefile->GetCurrentDirectory() + ("/" + path);
+ path = this->Makefile->GetCurrentSourceDirectory() + ("/" + path);
}
// Unify path (remove '//', '/../', ...)
@@ -3716,8 +3776,8 @@ bool cmFileCommand::HandleLockCommand(
fclose(file);
// Actual lock/unlock
- cmFileLockPool& lockPool = this->Makefile->GetLocalGenerator()->
- GetGlobalGenerator()->GetFileLockPool();
+ cmFileLockPool& lockPool = this->Makefile->GetGlobalGenerator()
+ ->GetFileLockPool();
cmFileLockResult fileLockResult(cmFileLockResult::MakeOk());
if (release)