1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmCPackSTGZGenerator.h"
11 #include "cmsys/FStream.hxx"
13 #include "cm_sys_stat.h"
15 #include "cmArchiveWrite.h"
16 #include "cmCPackGenerator.h"
17 #include "cmCPackLog.h"
18 #include "cmSystemTools.h"
21 cmCPackSTGZGenerator::cmCPackSTGZGenerator()
22 : cmCPackArchiveGenerator(cmArchiveWrite::CompressGZip
, "paxr", ".sh")
26 cmCPackSTGZGenerator::~cmCPackSTGZGenerator() = default;
28 int cmCPackSTGZGenerator::InitializeInternal()
30 this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
32 std::string inFile
= this->FindTemplate("CPack.STGZ_Header.sh.in");
34 cmCPackLogger(cmCPackLog::LOG_ERROR
,
35 "Cannot find template file: " << inFile
<< std::endl
);
38 this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile
);
39 this->SetOptionIfNotSet("CPACK_AT_SIGN", "@");
41 return this->Superclass::InitializeInternal();
44 int cmCPackSTGZGenerator::PackageFiles()
47 if (!this->Superclass::PackageFiles()) {
51 /* TGZ generator (our Superclass) may
52 * have generated several packages (component packaging)
53 * so we must iterate over generated packages.
55 for (std::string
const& pfn
: this->packageFileNames
) {
56 retval
&= static_cast<bool>(
57 cmSystemTools::SetPermissions(pfn
.c_str(),
58 #if defined(_MSC_VER) || defined(__MINGW32__)
59 S_IREAD
| S_IWRITE
| S_IEXEC
61 S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
|
62 S_IWGRP
| S_IXGRP
| S_IROTH
| S_IWOTH
|
70 int cmCPackSTGZGenerator::GenerateHeader(std::ostream
* os
)
72 cmCPackLogger(cmCPackLog::LOG_DEBUG
, "Writing header" << std::endl
);
75 std::string inLicFile
= this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
77 cmsys::ifstream
ilfs(inLicFile
.c_str());
78 std::string licenseText
;
79 while (cmSystemTools::GetLineFromStream(ilfs
, line
)) {
80 licenseText
+= line
+ "\n";
82 this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT", licenseText
);
84 const char headerLengthTag
[] = "###CPACK_HEADER_LENGTH###";
87 std::string inFile
= this->GetOption("CPACK_STGZ_HEADER_FILE");
88 cmsys::ifstream
ifs(inFile
.c_str());
89 std::string packageHeaderText
;
90 while (cmSystemTools::GetLineFromStream(ifs
, line
)) {
91 packageHeaderText
+= line
+ "\n";
94 // Configure in the values
96 this->ConfigureString(packageHeaderText
, res
);
99 const char* ptr
= res
.c_str();
107 cmCPackLogger(cmCPackLog::LOG_DEBUG
,
108 "Number of lines: " << counter
<< std::endl
);
110 snprintf(buffer
, sizeof(buffer
), "%d", counter
);
111 cmSystemTools::ReplaceString(res
, headerLengthTag
, buffer
);
115 return this->Superclass::GenerateHeader(os
);