diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2006-10-13 14:52:34 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2006-10-13 14:52:34 (GMT) |
commit | 72b38e3aa7ba5fa4a70144e05de36bc99fda173a (patch) | |
tree | 744005aab47678a2a742267a01799a8f53dd0cf7 /Source/CPack | |
parent | 8883613cc022d0ae2c96d84adf79dd82b74df658 (diff) | |
download | CMake-72b38e3aa7ba5fa4a70144e05de36bc99fda173a.zip CMake-72b38e3aa7ba5fa4a70144e05de36bc99fda173a.tar.gz CMake-72b38e3aa7ba5fa4a70144e05de36bc99fda173a.tar.bz2 |
ENH: merge changes from the main tree to the 2.4 branch
Diffstat (limited to 'Source/CPack')
-rw-r--r-- | Source/CPack/cmCPackNSISGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/CPack/cmCPackTarCompressGenerator.cxx | 267 | ||||
-rw-r--r-- | Source/CPack/cmCPackTarCompressGenerator.h | 1 | ||||
-rw-r--r-- | Source/CPack/cmCPackZIPGenerator.cxx | 25 | ||||
-rw-r--r-- | Source/CPack/cpack.cxx | 78 |
5 files changed, 233 insertions, 140 deletions
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index bac5d74..8b1c879 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -248,7 +248,7 @@ bool cmCPackNSISGenerator::GetListOfSubdirectories(const char* topdir, if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") && strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),"..")) { - kwsys_stl::string fullPath = topdir; + cmsys_stl::string fullPath = topdir; fullPath += "/"; fullPath += dir.GetFile(static_cast<unsigned long>(fileNum)); if(cmsys::SystemTools::FileIsDirectory(fullPath.c_str()) && diff --git a/Source/CPack/cmCPackTarCompressGenerator.cxx b/Source/CPack/cmCPackTarCompressGenerator.cxx index b911005..65ff6a7 100644 --- a/Source/CPack/cmCPackTarCompressGenerator.cxx +++ b/Source/CPack/cmCPackTarCompressGenerator.cxx @@ -26,19 +26,25 @@ #include "cmCPackLog.h" #include <cmsys/SystemTools.hxx> +#include <cmcompress/cmcompress.h> +#include <libtar/libtar.h> +#include <memory> // auto_ptr +#include <fcntl.h> +#include <errno.h> -// Includes needed for implementation of RenameFile. This is not in -// system tools because it is not implemented robustly enough to move -// files across directories. -#ifdef _WIN32 -# include <windows.h> -# include <sys/stat.h> -#endif +//---------------------------------------------------------------------- +class cmCPackTarCompressGeneratorForward +{ +public: + static int GenerateHeader(cmCPackTarCompressGenerator* gg, std::ostream* os) + { + return gg->GenerateHeader(os); + } +}; //---------------------------------------------------------------------- cmCPackTarCompressGenerator::cmCPackTarCompressGenerator() { - this->Compress = false; } //---------------------------------------------------------------------- @@ -47,123 +53,192 @@ cmCPackTarCompressGenerator::~cmCPackTarCompressGenerator() } //---------------------------------------------------------------------- -int cmCPackTarCompressGenerator::InitializeInternal() +class cmCPackTarCompress_Data { - this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1"); - std::vector<std::string> path; - std::string pkgPath = cmSystemTools::FindProgram("compress", path, false); - if ( pkgPath.empty() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find Compress" << std::endl); - return 0; - } - this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found Compress program: " - << pkgPath.c_str() - << std::endl); +public: + cmCPackTarCompress_Data(cmCPackTarCompressGenerator* gen) : + OutputStream(0), Generator(gen) {} + std::ostream* OutputStream; + cmCPackTarCompressGenerator* Generator; + cmcompress_stream CMCompressStream; +}; - return this->Superclass::InitializeInternal(); +//---------------------------------------------------------------------- +extern "C" { + // For cmTar + int cmCPackTarCompress_Data_Open(void *client_data, const char* name, + int oflags, mode_t mode); + ssize_t cmCPackTarCompress_Data_Write(void *client_data, void *buff, + size_t n); + int cmCPackTarCompress_Data_Close(void *client_data); + + // For cmCompress + int cmCPackTarCompress_Compress_Output(void* cdata, const char* data, + int len); } + //---------------------------------------------------------------------- -int cmCPackTarCompressGenerator::CompressFiles(const char* outFileName, - const char* toplevel, const std::vector<std::string>& files) +int cmCPackTarCompress_Data_Open(void *client_data, const char* pathname, + int, mode_t) { - std::string packageDirFileName - = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); - packageDirFileName += ".tar"; - std::string output; - int retVal = -1; - if ( !this->Superclass::CompressFiles(packageDirFileName.c_str(), - toplevel, files) ) + cmCPackTarCompress_Data *mydata = (cmCPackTarCompress_Data*)client_data; + + if ( !cmcompress_compress_initialize(&mydata->CMCompressStream) ) { - return 0; + return -1; } - cmOStringStream dmgCmd1; - dmgCmd1 << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM") - << "\" \"" << packageDirFileName - << "\""; - retVal = -1; - int res = cmSystemTools::RunSingleCommand(dmgCmd1.str().c_str(), &output, - &retVal, toplevel, this->GeneratorVerbose, 0); - if ( !res || retVal ) + mydata->CMCompressStream.client_data = mydata; + mydata->CMCompressStream.output_stream = cmCPackTarCompress_Compress_Output; + + cmGeneratedFileStream* gf = new cmGeneratedFileStream; + // Open binary + gf->Open(pathname, false, true); + mydata->OutputStream = gf; + if ( !*mydata->OutputStream ) { - std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - tmpFile += "/CompressCompress.log"; - cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << dmgCmd1.str().c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; - cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running Compress command: " - << dmgCmd1.str().c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); - return 0; + return -1; } - std::string compressOutFile = packageDirFileName + ".Z"; - if ( !cmSystemTools::SameFile(compressOutFile.c_str(), outFileName ) ) + if ( !cmcompress_compress_start(&mydata->CMCompressStream) ) { - if ( !this->RenameFile(compressOutFile.c_str(), outFileName) ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem renaming: \"" - << compressOutFile.c_str() << "\" to \"" - << outFileName << std::endl); - return 0; + return -1; } + + + if ( !cmCPackTarCompressGeneratorForward::GenerateHeader( + mydata->Generator,gf)) + { + return -1; } - return 1; + return 0; } -//---------------------------------------------------------------------------- -int cmCPackTarCompressGenerator::RenameFile(const char* oldname, - const char* newname) +//---------------------------------------------------------------------- +ssize_t cmCPackTarCompress_Data_Write(void *client_data, void *buff, size_t n) { -#ifdef _WIN32 - /* On Windows the move functions will not replace existing files. - Check if the destination exists. */ - struct stat newFile; - if(stat(newname, &newFile) == 0) + cmCPackTarCompress_Data *mydata = (cmCPackTarCompress_Data*)client_data; + + if ( !cmcompress_compress(&mydata->CMCompressStream, buff, n) ) { - /* The destination exists. We have to replace it carefully. The - MoveFileEx function does what we need but is not available on - Win9x. */ - OSVERSIONINFO osv; - DWORD attrs; - - /* Make sure the destination is not read only. */ - attrs = GetFileAttributes(newname); - if(attrs & FILE_ATTRIBUTE_READONLY) + return 0; + } + return n; +} + +//---------------------------------------------------------------------- +int cmCPackTarCompress_Data_Close(void *client_data) +{ + cmCPackTarCompress_Data *mydata = (cmCPackTarCompress_Data*)client_data; + + if ( !cmcompress_compress_finalize(&mydata->CMCompressStream) ) { - SetFileAttributes(newname, attrs & ~FILE_ATTRIBUTE_READONLY); + delete mydata->OutputStream; + return -1; } - /* Check the windows version number. */ - osv.dwOSVersionInfoSize = sizeof(osv); - GetVersionEx(&osv); - if(osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) + delete mydata->OutputStream; + mydata->OutputStream = 0; + return (0); +} + +//---------------------------------------------------------------------- +int cmCPackTarCompressGenerator::InitializeInternal() +{ + this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1"); + return this->Superclass::InitializeInternal(); +} + +//---------------------------------------------------------------------- +int cmCPackTarCompressGenerator::CompressFiles(const char* outFileName, + const char* toplevel, const std::vector<std::string>& files) +{ + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); + cmCPackTarCompress_Data mydata(this); + TAR *t; + char buf[TAR_MAXPATHLEN]; + char pathname[TAR_MAXPATHLEN]; + + tartype_t compressType = { + (openfunc_t)cmCPackTarCompress_Data_Open, + (closefunc_t)cmCPackTarCompress_Data_Close, + (readfunc_t)0, + (writefunc_t)cmCPackTarCompress_Data_Write, + &mydata + }; + + // Ok, this libtar is not const safe. for now use auto_ptr hack + char* realName = new char[ strlen(outFileName) + 1 ]; + std::auto_ptr<char> realNamePtr(realName); + strcpy(realName, outFileName); + int flags = O_WRONLY | O_CREAT; + if (tar_open(&t, realName, + &compressType, + flags, 0644, + (this->GeneratorVerbose?TAR_VERBOSE:0) + | 0) == -1) { - /* This is Win9x. There is no MoveFileEx implementation. We - cannot quite rename the file atomically. Just delete the - destination and then move the file. */ - DeleteFile(newname); - return MoveFile(oldname, newname); + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_open(): " + << strerror(errno) << std::endl); + return 0; } - else + + std::vector<std::string>::const_iterator fileIt; + for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt ) + { + std::string rp = cmSystemTools::RelativePath(toplevel, fileIt->c_str()); + strncpy(pathname, fileIt->c_str(), sizeof(pathname)); + pathname[sizeof(pathname)-1] = 0; + strncpy(buf, rp.c_str(), sizeof(buf)); + buf[sizeof(buf)-1] = 0; + if (tar_append_tree(t, pathname, buf) != 0) { - /* This is not Win9x. Use the MoveFileEx implementation. */ - return MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING); + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem with tar_append_tree(\"" << buf << "\", \"" + << pathname << "\"): " + << strerror(errno) << std::endl); + tar_close(t); + return 0; + } + } + if (tar_append_eof(t) != 0) + { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_append_eof(): " + << strerror(errno) << std::endl); + tar_close(t); + return 0; } + + if (tar_close(t) != 0) + { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_close(): " + << strerror(errno) << std::endl); + return 0; } - else + return 1; +} + +//---------------------------------------------------------------------- +int cmCPackTarCompress_Compress_Output(void* client_data, + const char* data, int data_length) +{ + cmcompress_stream *cstream = static_cast<cmcompress_stream*>(client_data); + cmCPackTarCompress_Data *mydata + = static_cast<cmCPackTarCompress_Data*>(cstream->client_data); + mydata->OutputStream->write(data, data_length); + + if ( !mydata->OutputStream ) { - /* The destination does not exist. Just move the file. */ - return MoveFile(oldname, newname); + return 0; } -#else - /* On UNIX we have an OS-provided call to do this atomically. */ - return rename(oldname, newname) == 0; -#endif + return data_length; } +//---------------------------------------------------------------------- +int cmCPackTarCompressGenerator::GenerateHeader(std::ostream* os) +{ + (void)os; + return 1; +} diff --git a/Source/CPack/cmCPackTarCompressGenerator.h b/Source/CPack/cmCPackTarCompressGenerator.h index efd5579..75adb22 100644 --- a/Source/CPack/cmCPackTarCompressGenerator.h +++ b/Source/CPack/cmCPackTarCompressGenerator.h @@ -42,6 +42,7 @@ protected: virtual const char* GetOutputExtension() { return "tar.Z"; } int RenameFile(const char* oldname, const char* newname); + int GenerateHeader(std::ostream* os); }; #endif diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx index 3d46f80..1b12f07 100644 --- a/Source/CPack/cmCPackZIPGenerator.cxx +++ b/Source/CPack/cmCPackZIPGenerator.cxx @@ -91,20 +91,22 @@ int cmCPackZIPGenerator::CompressFiles(const char* outFileName, const char* toplevel, const std::vector<std::string>& files) { std::string tempFileName; + tempFileName = toplevel; + tempFileName += "/winZip.filelist"; + bool needQuotesInFile = false; cmOStringStream dmgCmd; switch ( this->ZipStyle ) { case cmCPackZIPGenerator::StyleWinZip: - tempFileName = toplevel; - tempFileName += "/winZip.filelist"; dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM") << "\" -P \"" << outFileName - << "\" @\"" << tempFileName.c_str() << "\""; + << "\" @winZip.filelist"; + needQuotesInFile = true; break; case cmCPackZIPGenerator::StyleUnixZip: dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM") - << "\" \"" << outFileName - << "\""; + << "\" -r \"" << outFileName + << "\" . -i@winZip.filelist"; break; default: cmCPackLogger(cmCPackLog::LOG_ERROR, "Unknown ZIP style" @@ -117,9 +119,16 @@ int cmCPackZIPGenerator::CompressFiles(const char* outFileName, std::vector<std::string>::const_iterator fileIt; for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt ) { - out << "\"" - << cmSystemTools::RelativePath(toplevel, fileIt->c_str()) - << "\"" << std::endl; + if ( needQuotesInFile ) + { + out << "\""; + } + out << cmSystemTools::RelativePath(toplevel, fileIt->c_str()); + if ( needQuotesInFile ) + { + out << "\""; + } + out << std::endl; } } else diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 90421f9..d6d1cea 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -308,6 +308,8 @@ int main (int argc, char *argv[]) "CPack generator not specified" << std::endl); parsed = 0; } + else + { std::vector<std::string> generatorsVector; cmSystemTools::ExpandListArgument(genList, generatorsVector); @@ -370,6 +372,47 @@ int main (int argc, char *argv[]) << std::endl); parsed = 0; } + if ( parsed ) + { +#ifdef _WIN32 + std::string comspec = "cmw9xcom.exe"; + cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str()); +#endif + + const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME"); + cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: " + << cpackGenerator->GetNameOfClass() << std::endl); + cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: " + << projName << std::endl); + + const char* projVersion = + mf->GetDefinition("CPACK_PACKAGE_VERSION"); + if ( !projVersion ) + { + const char* projVersionMajor + = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR"); + const char* projVersionMinor + = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR"); + const char* projVersionPatch + = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"); + cmOStringStream ostr; + ostr << projVersionMajor << "." << projVersionMinor << "." + << projVersionPatch; + mf->AddDefinition("CPACK_PACKAGE_VERSION", + ostr.str().c_str()); + } + + int res = cpackGenerator->ProcessGenerator(); + if ( !res ) + { + cmCPack_Log(&log, cmCPackLog::LOG_ERROR, + "Error when generating package: " << projName << std::endl); + return 1; + } + } + } + } + } } } @@ -405,41 +448,6 @@ int main (int argc, char *argv[]) #define cout no_cout_use_cmCPack_Log } -#ifdef _WIN32 - std::string comspec = "cmw9xcom.exe"; - cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str()); -#endif - - const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME"); - cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: " - << cpackGenerator->GetNameOfClass() << std::endl); - cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: " - << projName << std::endl); - - const char* projVersion = mf->GetDefinition("CPACK_PACKAGE_VERSION"); - if ( !projVersion ) - { - const char* projVersionMajor - = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR"); - const char* projVersionMinor - = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR"); - const char* projVersionPatch - = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"); - cmOStringStream ostr; - ostr << projVersionMajor << "." << projVersionMinor << "." - << projVersionPatch; - mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str().c_str()); - } - - int res = cpackGenerator->ProcessGenerator(); - if ( !res ) - { - cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Error when generating package: " << projName << std::endl); - return 1; - } - } - } return 0; } |