2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2006-01-02 07:21:05 +03:00
|
|
|
|
|
|
|
#include "cmCPackSTGZGenerator.h"
|
|
|
|
|
2016-09-07 01:21:35 +03:00
|
|
|
#include "cmCPackGenerator.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCPackLog.h"
|
|
|
|
#include "cmSystemTools.h"
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-09-07 01:21:35 +03:00
|
|
|
#include <sstream>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-05-02 22:03:45 +03:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
// include sys/stat.h after sys/types.h
|
2006-04-18 16:25:24 +04:00
|
|
|
#include <sys/stat.h>
|
2006-01-02 07:21:05 +03:00
|
|
|
|
|
|
|
cmCPackSTGZGenerator::cmCPackSTGZGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-04-15 21:02:18 +04:00
|
|
|
int cmCPackSTGZGenerator::InitializeInternal()
|
|
|
|
{
|
|
|
|
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
|
2006-04-18 16:25:24 +04:00
|
|
|
|
|
|
|
std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (inFile.empty()) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Cannot find template file: " << inFile << std::endl);
|
2006-04-18 16:25:24 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-04-18 16:25:24 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
|
2006-05-02 16:49:01 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_AT_SIGN", "@");
|
2006-04-18 16:25:24 +04:00
|
|
|
|
2006-04-15 21:02:18 +04:00
|
|
|
return this->Superclass::InitializeInternal();
|
|
|
|
}
|
|
|
|
|
2010-08-11 21:48:39 +04:00
|
|
|
int cmCPackSTGZGenerator::PackageFiles()
|
2006-04-18 16:25:24 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
bool retval = true;
|
|
|
|
if (!this->Superclass::PackageFiles()) {
|
2006-04-18 16:25:24 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-18 20:52:56 +04:00
|
|
|
|
|
|
|
/* TGZ generator (our Superclass) may
|
|
|
|
* have generated several packages (component packaging)
|
|
|
|
* so we must iterate over generated packages.
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator it = packageFileNames.begin();
|
|
|
|
it != packageFileNames.end(); ++it) {
|
2012-03-18 20:52:56 +04:00
|
|
|
retval &= cmSystemTools::SetPermissions((*it).c_str(),
|
2016-05-16 17:34:04 +03:00
|
|
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
|
|
|
S_IREAD | S_IWRITE | S_IEXEC
|
2006-04-18 16:25:24 +04:00
|
|
|
#else
|
2016-05-16 17:34:04 +03:00
|
|
|
S_IRUSR | S_IWUSR | S_IXUSR |
|
|
|
|
S_IRGRP | S_IWGRP | S_IXGRP |
|
|
|
|
S_IROTH | S_IWOTH | S_IXOTH
|
2006-04-18 16:25:24 +04:00
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
);
|
2012-03-18 20:52:56 +04:00
|
|
|
}
|
|
|
|
return retval;
|
2006-04-18 16:25:24 +04:00
|
|
|
}
|
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
|
|
|
|
{
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl);
|
2015-08-20 23:02:20 +03:00
|
|
|
std::ostringstream str;
|
2006-04-18 16:25:24 +04:00
|
|
|
int counter = 0;
|
|
|
|
|
2006-05-01 22:23:15 +04:00
|
|
|
std::string inLicFile = this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
|
|
|
|
std::string line;
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream ilfs(inLicFile.c_str());
|
2006-05-01 22:23:15 +04:00
|
|
|
std::string licenseText;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(ilfs, line)) {
|
2006-05-01 22:23:15 +04:00
|
|
|
licenseText += line + "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT",
|
2006-05-12 22:44:24 +04:00
|
|
|
licenseText.c_str());
|
2006-05-01 22:23:15 +04:00
|
|
|
|
2006-04-18 16:25:24 +04:00
|
|
|
const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###";
|
|
|
|
|
|
|
|
// Create the header
|
|
|
|
std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE");
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream ifs(inFile.c_str());
|
2006-04-18 16:25:24 +04:00
|
|
|
std::string packageHeaderText;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(ifs, line)) {
|
2006-04-18 16:25:24 +04:00
|
|
|
packageHeaderText += line + "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-04-18 16:25:24 +04:00
|
|
|
|
|
|
|
// Configure in the values
|
|
|
|
std::string res;
|
|
|
|
this->ConfigureString(packageHeaderText, res);
|
|
|
|
|
|
|
|
// Count the lines
|
|
|
|
const char* ptr = res.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
while (*ptr) {
|
|
|
|
if (*ptr == '\n') {
|
|
|
|
counter++;
|
2006-04-18 16:25:24 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
++ptr;
|
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Number of lines: " << counter
|
|
|
|
<< std::endl);
|
2006-04-18 16:25:24 +04:00
|
|
|
char buffer[1024];
|
|
|
|
sprintf(buffer, "%d", counter);
|
|
|
|
cmSystemTools::ReplaceString(res, headerLengthTag, buffer);
|
|
|
|
|
|
|
|
// Write in file
|
2014-03-11 16:35:32 +04:00
|
|
|
*os << res;
|
2006-01-04 23:14:09 +03:00
|
|
|
return this->Superclass::GenerateHeader(os);
|
2006-01-02 07:21:05 +03:00
|
|
|
}
|