diff options
Diffstat (limited to 'src/qtattributionsscanner/qdocgenerator.cpp')
-rw-r--r-- | src/qtattributionsscanner/qdocgenerator.cpp | 100 |
1 files changed, 32 insertions, 68 deletions
diff --git a/src/qtattributionsscanner/qdocgenerator.cpp b/src/qtattributionsscanner/qdocgenerator.cpp index 6c264b752..b21a06938 100644 --- a/src/qtattributionsscanner/qdocgenerator.cpp +++ b/src/qtattributionsscanner/qdocgenerator.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "qdocgenerator.h" @@ -32,6 +7,8 @@ #include <iostream> +using namespace Qt::Literals::StringLiterals; + namespace QDocGenerator { // See definition of idstring and licenseid in https://spdx.org/spdx-specification-21-web-version @@ -53,21 +30,29 @@ static QString languageJoin(const QStringList &list) { QString result; for (int i = 0; i < list.size(); ++i) { - QString delimiter = QStringLiteral(", "); + QString delimiter = u", "_s; if (i == list.size() - 1) // last item delimiter.clear(); else if (list.size() == 2) - delimiter = QStringLiteral(" and "); + delimiter = u" and "_s; else if (list.size() > 2 && i == list.size() - 2) - delimiter = QStringLiteral(", and "); // oxford comma + delimiter = u", and "_s; // oxford comma result += list[i] + delimiter; } return result; } -static void generate(QTextStream &out, const Package &package, const QDir &baseDir, - LogLevel logLevel) +// Embed source code between \badcode ... \endbadcode +// Also, avoid '*/' breaking qdoc by passing the star as argument +static void sourceCode(QTextStream &out, const QString &src) +{ + out << "\\badcode *\n"; + out << QString(src).replace(u"*/"_s, u"\\1/"_s); + out << "\n\\endcode\n\n"; +} + +static void generate(QTextStream &out, const Package &package, const QDir &baseDir) { out << "/*!\n\n"; for (const QString &part : package.qtParts) { @@ -75,12 +60,13 @@ static void generate(QTextStream &out, const Package &package, const QDir &baseD out << "\\ingroup attributions-" << part << "\n"; } - if (package.qtParts.contains(QLatin1String("libs"))) { + if (package.qtParts.contains("libs"_L1)) { // show up in xxx-index.html page of module out << "\\ingroup attributions-" << package.qdocModule << "\n"; // include in '\generatelist annotatedattributions' out << "\\page " << package.qdocModule << "-attribution-" << package.id - << ".html attribution\n"; + << ".html\n"; + out << "\\attribution\n"; } else { out << "\\page " << package.qdocModule << "-attribution-" << package.id << ".html \n"; @@ -132,50 +118,28 @@ static void generate(QTextStream &out, const Package &package, const QDir &baseD QString copyright; if (!package.copyright.isEmpty()) copyright = package.copyright; + else if (!package.copyrightFileContents.isEmpty()) + copyright = package.copyrightFileContents; - if (!package.copyrightFile.isEmpty()) { - const QDir packageDir(package.path); - QFile file(QDir(package.path).absoluteFilePath(package.copyrightFile)); - if (!file.open(QIODevice::ReadOnly)) { - if (logLevel != SilentLog) { - std::cerr << qPrintable( - tr("Path %1 : cannot open copyright file %2.\n") - .arg(QDir::toNativeSeparators(package.path)) - .arg(QDir::toNativeSeparators(package.copyrightFile))); - } - } else { - copyright = QString::fromUtf8(file.readAll()); - } + if (!copyright.isEmpty()) { + out << "\n"; + sourceCode(out, copyright); } - if (!copyright.isEmpty()) - out << "\n\\badcode\n" << copyright << "\n\\endcode\n\n"; - - if (isSpdxLicenseId(package.licenseId) && package.licenseId != QLatin1String("NONE")) { + if (isSpdxLicenseId(package.licenseId) && !package.licenseId.startsWith("LicenseRef-"_L1) + && package.licenseId != "NONE"_L1) { out << "\\l{https://spdx.org/licenses/" << package.licenseId << ".html}" << "{" << package.license << "}.\n\n"; - } else if (package.licenseId.startsWith(QLatin1String("urn:dje:license:"))) { + } else if (package.licenseId.startsWith("urn:dje:license:"_L1)) { out << "\\l{https://enterprise.dejacode.com/licenses/public/" << package.licenseId.mid(16) << "/}{" << package.license << "}.\n\n"; } else { out << package.license << ".\n\n"; } - foreach (const QString &licenseFile, package.licenseFiles) { - QFile file(licenseFile); - if (!file.open(QIODevice::ReadOnly)) { - if (logLevel != SilentLog) { - std::cerr << qPrintable(tr("Path %1 : cannot open license file %2.\n") - .arg(QDir::toNativeSeparators(package.path)) - .arg(QDir::toNativeSeparators(licenseFile))); - out << "*/\n"; - } - return; - } - out << "\\badcode\n"; - out << QString::fromUtf8(file.readAll()).trimmed(); - out << "\n\\endcode\n\n"; - } + for (const QString &license : package.licenseFilesContents) + sourceCode(out, license); + out << "*/\n"; } @@ -187,7 +151,7 @@ void generate(QTextStream &out, const QList<Package> &packages, const QString &b QDir baseDir(baseDirectory); for (const Package &package : packages) - generate(out, package, baseDir, logLevel); + generate(out, package, baseDir); } } // namespace QDocGenerator |