CMake/Source/CPack/cmCPackLog.cxx

183 lines
4.2 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-03 00:14:21 +03:00
#include "cmCPackLog.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
2006-01-03 00:14:21 +03:00
2016-09-07 01:21:35 +03:00
#include <iostream>
2006-01-03 00:14:21 +03:00
cmCPackLog::cmCPackLog()
{
2006-03-10 21:06:26 +03:00
this->Verbose = false;
this->Debug = false;
this->Quiet = false;
this->NewLine = true;
2006-01-03 00:14:21 +03:00
2006-03-10 21:06:26 +03:00
this->LastTag = cmCPackLog::NOTAG;
2006-01-03 00:14:21 +03:00
#undef cerr
#undef cout
2006-03-10 21:06:26 +03:00
this->DefaultOutput = &std::cout;
this->DefaultError = &std::cerr;
2016-06-27 23:44:16 +03:00
this->LogOutput = CM_NULLPTR;
2006-03-10 21:06:26 +03:00
this->LogOutputCleanup = false;
2006-01-03 00:14:21 +03:00
}
cmCPackLog::~cmCPackLog()
{
2016-06-27 23:44:16 +03:00
this->SetLogOutputStream(CM_NULLPTR);
2006-01-03 00:14:21 +03:00
}
2006-01-03 01:22:39 +03:00
void cmCPackLog::SetLogOutputStream(std::ostream* os)
2006-01-03 00:14:21 +03:00
{
if (this->LogOutputCleanup && this->LogOutput) {
2006-03-10 21:06:26 +03:00
delete this->LogOutput;
}
2006-03-10 21:06:26 +03:00
this->LogOutputCleanup = false;
this->LogOutput = os;
2006-01-03 00:14:21 +03:00
}
bool cmCPackLog::SetLogOutputFile(const char* fname)
{
2016-06-27 23:44:16 +03:00
cmGeneratedFileStream* cg = CM_NULLPTR;
if (fname) {
2006-01-03 00:14:21 +03:00
cg = new cmGeneratedFileStream(fname);
}
if (cg && !*cg) {
2006-01-03 00:14:21 +03:00
delete cg;
2016-06-27 23:44:16 +03:00
cg = CM_NULLPTR;
}
2006-01-03 00:14:21 +03:00
this->SetLogOutputStream(cg);
if (!cg) {
2006-01-03 00:14:21 +03:00
return false;
}
2006-03-10 21:06:26 +03:00
this->LogOutputCleanup = true;
2006-01-03 00:14:21 +03:00
return true;
}
void cmCPackLog::Log(int tag, const char* file, int line, const char* msg,
size_t length)
2006-01-03 00:14:21 +03:00
{
// By default no logging
bool display = false;
// Display file and line number if debug
2006-03-10 21:06:26 +03:00
bool useFileAndLine = this->Debug;
2006-01-03 00:14:21 +03:00
bool output = false;
bool debug = false;
2006-01-03 00:14:21 +03:00
bool warning = false;
bool error = false;
2006-01-03 00:14:21 +03:00
bool verbose = false;
// When writing in file, add list of tags whenever tag changes.
std::string tagString;
bool needTagString = false;
if (this->LogOutput && this->LastTag != tag) {
2006-01-03 00:14:21 +03:00
needTagString = true;
}
2006-01-03 00:14:21 +03:00
if (tag & LOG_OUTPUT) {
2006-01-03 00:14:21 +03:00
output = true;
display = true;
if (needTagString) {
if (!tagString.empty()) {
tagString += ",";
2006-01-03 00:14:21 +03:00
}
tagString = "VERBOSE";
2006-01-03 00:14:21 +03:00
}
}
if (tag & LOG_WARNING) {
2006-01-03 00:14:21 +03:00
warning = true;
display = true;
if (needTagString) {
if (!tagString.empty()) {
tagString += ",";
2006-01-03 00:14:21 +03:00
}
tagString = "WARNING";
2006-01-03 00:14:21 +03:00
}
}
if (tag & LOG_ERROR) {
2006-01-03 00:14:21 +03:00
error = true;
display = true;
if (needTagString) {
if (!tagString.empty()) {
tagString += ",";
2006-01-03 00:14:21 +03:00
}
tagString = "ERROR";
2006-01-03 00:14:21 +03:00
}
}
if (tag & LOG_DEBUG && this->Debug) {
2006-01-03 00:14:21 +03:00
debug = true;
display = true;
if (needTagString) {
if (!tagString.empty()) {
tagString += ",";
2006-01-03 00:14:21 +03:00
}
tagString = "DEBUG";
2006-01-03 00:14:21 +03:00
}
useFileAndLine = true;
}
if (tag & LOG_VERBOSE && this->Verbose) {
2006-01-03 00:14:21 +03:00
verbose = true;
display = true;
if (needTagString) {
if (!tagString.empty()) {
tagString += ",";
2006-01-03 00:14:21 +03:00
}
tagString = "VERBOSE";
2006-01-03 00:14:21 +03:00
}
}
if (this->Quiet) {
2006-01-03 00:14:21 +03:00
display = false;
}
if (this->LogOutput) {
if (needTagString) {
*this->LogOutput << "[" << file << ":" << line << " " << tagString
<< "] ";
2006-01-03 00:14:21 +03:00
}
2006-03-10 21:06:26 +03:00
this->LogOutput->write(msg, length);
}
2006-03-10 21:06:26 +03:00
this->LastTag = tag;
if (!display) {
2006-01-03 00:14:21 +03:00
return;
}
if (this->NewLine) {
if (error && !this->ErrorPrefix.empty()) {
*this->DefaultError << this->ErrorPrefix;
} else if (warning && !this->WarningPrefix.empty()) {
*this->DefaultError << this->WarningPrefix;
} else if (output && !this->OutputPrefix.empty()) {
*this->DefaultOutput << this->OutputPrefix;
} else if (verbose && !this->VerbosePrefix.empty()) {
*this->DefaultOutput << this->VerbosePrefix;
} else if (debug && !this->DebugPrefix.empty()) {
*this->DefaultOutput << this->DebugPrefix;
} else if (!this->Prefix.empty()) {
*this->DefaultOutput << this->Prefix;
}
if (useFileAndLine) {
if (error || warning) {
2006-03-10 21:06:26 +03:00
*this->DefaultError << file << ":" << line << " ";
} else {
2006-03-10 21:06:26 +03:00
*this->DefaultOutput << file << ":" << line << " ";
2006-01-03 00:14:21 +03:00
}
}
}
if (error || warning) {
2006-03-10 21:06:26 +03:00
this->DefaultError->write(msg, length);
this->DefaultError->flush();
} else {
2006-03-10 21:06:26 +03:00
this->DefaultOutput->write(msg, length);
this->DefaultOutput->flush();
}
if (msg[length - 1] == '\n' || length > 2) {
2006-03-10 21:06:26 +03:00
this->NewLine = true;
}
if (error) {
cmSystemTools::SetErrorOccured();
}
2006-01-03 00:14:21 +03:00
}