CMake/Source/CPack/cmCPackSTGZGenerator.cxx

118 lines
3.3 KiB
C++
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 22:01:08 +03: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 07:21:05 +03:00
#include "cmCPackSTGZGenerator.h"
2016-09-07 01:21:35 +03:00
#include "cmCPackGenerator.h"
#include "cmCPackLog.h"
#include "cmSystemTools.h"
2006-01-02 07:21:05 +03:00
#include <cmsys/FStream.hxx>
2016-09-07 01:21:35 +03:00
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
#include <sys/types.h>
// include sys/stat.h after sys/types.h
#include <sys/stat.h>
2006-01-02 07:21:05 +03: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");
if (inFile.empty()) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Cannot find template file: " << inFile << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str());
this->SetOptionIfNotSet("CPACK_AT_SIGN", "@");
return this->Superclass::InitializeInternal();
}
int cmCPackSTGZGenerator::PackageFiles()
{
bool retval = true;
if (!this->Superclass::PackageFiles()) {
return 0;
}
/* TGZ generator (our Superclass) may
* have generated several packages (component packaging)
* so we must iterate over generated packages.
*/
for (std::vector<std::string>::iterator it = packageFileNames.begin();
it != packageFileNames.end(); ++it) {
retval &= cmSystemTools::SetPermissions((*it).c_str(),
#if defined(_MSC_VER) || defined(__MINGW32__)
S_IREAD | S_IWRITE | S_IEXEC
#else
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH
#endif
);
}
return retval;
}
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);
std::ostringstream str;
int counter = 0;
std::string inLicFile = this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
std::string line;
cmsys::ifstream ilfs(inLicFile.c_str());
std::string licenseText;
while (cmSystemTools::GetLineFromStream(ilfs, line)) {
licenseText += line + "\n";
}
this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT",
2006-05-12 22:44:24 +04:00
licenseText.c_str());
const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###";
// Create the header
std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE");
cmsys::ifstream ifs(inFile.c_str());
std::string packageHeaderText;
while (cmSystemTools::GetLineFromStream(ifs, line)) {
packageHeaderText += line + "\n";
}
// Configure in the values
std::string res;
this->ConfigureString(packageHeaderText, res);
// Count the lines
const char* ptr = res.c_str();
while (*ptr) {
if (*ptr == '\n') {
counter++;
}
++ptr;
}
counter++;
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
*os << res;
return this->Superclass::GenerateHeader(os);
2006-01-02 07:21:05 +03:00
}