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. */
|
2006-01-02 04:21:05 +00:00
|
|
|
#include "cmCPackSTGZGenerator.h"
|
|
|
|
|
2017-04-11 20:00:21 +00:00
|
|
|
#include "cmsys/FStream.hxx"
|
2016-09-06 22:21:35 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string>
|
2016-05-02 19:03:45 +00:00
|
|
|
|
2016-11-25 21:10:40 +00:00
|
|
|
#include "cmCPackGenerator.h"
|
|
|
|
#include "cmCPackLog.h"
|
|
|
|
#include "cmSystemTools.h"
|
2017-03-24 21:58:25 +00:00
|
|
|
#include "cm_sys_stat.h"
|
2016-11-25 21:10:40 +00:00
|
|
|
|
2006-01-02 04:21:05 +00:00
|
|
|
cmCPackSTGZGenerator::cmCPackSTGZGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-04-15 17:02:18 +00:00
|
|
|
int cmCPackSTGZGenerator::InitializeInternal()
|
|
|
|
{
|
|
|
|
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
|
2006-04-18 12:25:24 +00:00
|
|
|
|
|
|
|
std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in");
|
2016-05-16 14:34:04 +00:00
|
|
|
if (inFile.empty()) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Cannot find template file: " << inFile << std::endl);
|
2006-04-18 12:25:24 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-04-18 12:25:24 +00:00
|
|
|
this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
|
2006-05-02 12:49:01 +00:00
|
|
|
this->SetOptionIfNotSet("CPACK_AT_SIGN", "@");
|
2006-04-18 12:25:24 +00:00
|
|
|
|
2006-04-15 17:02:18 +00:00
|
|
|
return this->Superclass::InitializeInternal();
|
|
|
|
}
|
|
|
|
|
2010-08-11 17:48:39 +00:00
|
|
|
int cmCPackSTGZGenerator::PackageFiles()
|
2006-04-18 12:25:24 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
bool retval = true;
|
|
|
|
if (!this->Superclass::PackageFiles()) {
|
2006-04-18 12:25:24 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-03-18 16:52:56 +00:00
|
|
|
|
|
|
|
/* TGZ generator (our Superclass) may
|
|
|
|
* have generated several packages (component packaging)
|
|
|
|
* so we must iterate over generated packages.
|
|
|
|
*/
|
2017-09-15 22:04:51 +00:00
|
|
|
for (std::string const& pfn : packageFileNames) {
|
|
|
|
retval &= cmSystemTools::SetPermissions(pfn.c_str(),
|
2016-05-16 14:34:04 +00:00
|
|
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
|
|
|
S_IREAD | S_IWRITE | S_IEXEC
|
2006-04-18 12:25:24 +00:00
|
|
|
#else
|
2016-05-16 14:34:04 +00:00
|
|
|
S_IRUSR | S_IWUSR | S_IXUSR |
|
|
|
|
S_IRGRP | S_IWGRP | S_IXGRP |
|
|
|
|
S_IROTH | S_IWOTH | S_IXOTH
|
2006-04-18 12:25:24 +00:00
|
|
|
#endif
|
2018-06-01 13:53:41 +00:00
|
|
|
);
|
2012-03-18 16:52:56 +00:00
|
|
|
}
|
|
|
|
return retval;
|
2006-04-18 12:25:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-02 04:21:05 +00:00
|
|
|
int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
|
|
|
|
{
|
2006-01-02 21:14:21 +00:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl);
|
2015-08-20 20:02:20 +00:00
|
|
|
std::ostringstream str;
|
2006-04-18 12:25:24 +00:00
|
|
|
int counter = 0;
|
|
|
|
|
2006-05-01 18:23:15 +00:00
|
|
|
std::string inLicFile = this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
|
|
|
|
std::string line;
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream ilfs(inLicFile.c_str());
|
2006-05-01 18:23:15 +00:00
|
|
|
std::string licenseText;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(ilfs, line)) {
|
2006-05-01 18:23:15 +00:00
|
|
|
licenseText += line + "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT",
|
2006-05-12 18:44:24 +00:00
|
|
|
licenseText.c_str());
|
2006-05-01 18:23:15 +00:00
|
|
|
|
2006-04-18 12:25:24 +00:00
|
|
|
const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###";
|
|
|
|
|
|
|
|
// Create the header
|
|
|
|
std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE");
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream ifs(inFile.c_str());
|
2006-04-18 12:25:24 +00:00
|
|
|
std::string packageHeaderText;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(ifs, line)) {
|
2006-04-18 12:25:24 +00:00
|
|
|
packageHeaderText += line + "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-04-18 12:25:24 +00:00
|
|
|
|
|
|
|
// Configure in the values
|
|
|
|
std::string res;
|
|
|
|
this->ConfigureString(packageHeaderText, res);
|
|
|
|
|
|
|
|
// Count the lines
|
|
|
|
const char* ptr = res.c_str();
|
2016-05-16 14:34:04 +00:00
|
|
|
while (*ptr) {
|
|
|
|
if (*ptr == '\n') {
|
|
|
|
counter++;
|
2006-04-18 12:25:24 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
++ptr;
|
|
|
|
}
|
|
|
|
counter++;
|
2018-06-01 13:53:41 +00:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG,
|
|
|
|
"Number of lines: " << counter << std::endl);
|
2006-04-18 12:25:24 +00:00
|
|
|
char buffer[1024];
|
|
|
|
sprintf(buffer, "%d", counter);
|
|
|
|
cmSystemTools::ReplaceString(res, headerLengthTag, buffer);
|
|
|
|
|
|
|
|
// Write in file
|
2014-03-11 12:35:32 +00:00
|
|
|
*os << res;
|
2006-01-04 20:14:09 +00:00
|
|
|
return this->Superclass::GenerateHeader(os);
|
2006-01-02 04:21:05 +00:00
|
|
|
}
|