cmake/Source/CPack/cmCPackSTGZGenerator.cxx

113 lines
3.1 KiB
C++
Raw Normal View History

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