summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Köhne <kai.koehne@qt.io>2023-03-27 12:22:22 +0200
committerKai Köhne <kai.koehne@qt.io>2023-03-31 10:45:35 +0000
commitc96c31fa2d84a7f81dbcb220dff53f9cbb16805d (patch)
tree3aef63a664b41476a0f45a2577f4f74e3686a85b
parent4d75d3393b1e6c16d53d7d2a28001f7e1c6ddc99 (diff)
downloadqttools-c96c31fa2d84a7f81dbcb220dff53f9cbb16805d.tar.gz
Allow to opt out of source path checks
Commit 454ab5ffd5b07 ff let qtattributionsscanner bail out if the content of the "Path" and "Files" properties are not valid relative file paths at the time qtattributionsscanner runs. For Qt for MCU tough, the relative path to third-party files does differ between the git checkout, and the source SDK as given to the user. This patch, therefore, allows opting out of the check by adding a --no-path-checks option. Pick-to: 6.5 Change-Id: I809b52e233a6b56194feb1b5b8168f36ba1b9972 Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r--src/qtattributionsscanner/main.cpp14
-rw-r--r--src/qtattributionsscanner/scanner.cpp24
-rw-r--r--src/qtattributionsscanner/scanner.h8
3 files changed, 31 insertions, 15 deletions
diff --git a/src/qtattributionsscanner/main.cpp b/src/qtattributionsscanner/main.cpp
index b429f5b39..9a03c879d 100644
--- a/src/qtattributionsscanner/main.cpp
+++ b/src/qtattributionsscanner/main.cpp
@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName(u"Qt Attributions Scanner"_s);
- a.setApplicationVersion(u"1.1"_s);
+ a.setApplicationVersion(u"1.2"_s);
QCommandLineParser parser;
parser.setApplicationDescription(tr("Processes attribution files in Qt sources."));
@@ -47,6 +47,9 @@ int main(int argc, char *argv[])
tr("Paths in documentation are made relative to this "
"directory."),
u"directory"_s);
+ QCommandLineOption noCheckPathsOption(
+ u"no-check-paths"_s,
+ tr("Do not check whether referenced file paths exist in basedir."));
QCommandLineOption outputOption({ u"o"_s, u"output"_s },
tr("Write generated data to <file>."),
u"file"_s);
@@ -57,12 +60,17 @@ int main(int argc, char *argv[])
parser.addOption(inputFormatOption);
parser.addOption(filterOption);
parser.addOption(baseDirOption);
+ parser.addOption(noCheckPathsOption);
parser.addOption(outputOption);
parser.addOption(verboseOption);
parser.addOption(silentOption);
parser.process(a.arguments());
+ using Scanner::Checks, Scanner::Check;
+ Checks checks = Check::All;
+ checks.setFlag(Check::Paths, !parser.isSet(noCheckPathsOption));
+
LogLevel logLevel = NormalLog;
if (parser.isSet(verboseOption) && parser.isSet(silentOption)) {
std::cerr << qPrintable(tr("--verbose and --silent cannot be set simultaneously.")) << std::endl;
@@ -99,12 +107,12 @@ int main(int argc, char *argv[])
if (logLevel == VerboseLog)
std::cerr << qPrintable(tr("Recursively scanning %1 for attribution files...").arg(
QDir::toNativeSeparators(path))) << std::endl;
- std::optional<QList<Package>> p = Scanner::scanDirectory(path, formats, logLevel);
+ std::optional<QList<Package>> p = Scanner::scanDirectory(path, formats, checks, logLevel);
if (!p)
return 1;
packages = *p;
} else if (pathInfo.isFile()) {
- std::optional<QList<Package>> p = Scanner::readFile(path, logLevel);
+ std::optional<QList<Package>> p = Scanner::readFile(path, checks, logLevel);
if (!p)
return 1;
packages = *p;
diff --git a/src/qtattributionsscanner/scanner.cpp b/src/qtattributionsscanner/scanner.cpp
index 897954e69..460e21a7f 100644
--- a/src/qtattributionsscanner/scanner.cpp
+++ b/src/qtattributionsscanner/scanner.cpp
@@ -24,7 +24,7 @@ static void missingPropertyWarning(const QString &filePath, const QString &prope
QDir::toNativeSeparators(filePath), property)) << std::endl;
}
-static bool validatePackage(Package &p, const QString &filePath, LogLevel logLevel)
+static bool validatePackage(Package &p, const QString &filePath, Checks checks, LogLevel logLevel)
{
bool validPackage = true;
@@ -82,6 +82,9 @@ static bool validatePackage(Package &p, const QString &filePath, LogLevel logLev
}
}
+ if (!(checks & Check::Paths))
+ return validPackage;
+
const QDir dir = p.path;
if (!dir.exists()) {
std::cerr << qPrintable(
@@ -197,7 +200,7 @@ static bool autoDetectLicenseFiles(Package &p)
// Transforms a JSON object into a Package object
static std::optional<Package> readPackage(const QJsonObject &object, const QString &filePath,
- LogLevel logLevel)
+ Checks checks, LogLevel logLevel)
{
Package p;
bool validPackage = true;
@@ -338,7 +341,7 @@ static std::optional<Package> readPackage(const QJsonObject &object, const QStri
if (p.licenseFiles.isEmpty() && !autoDetectLicenseFiles(p))
return std::nullopt;
- if (!validatePackage(p, filePath, logLevel) || !validPackage)
+ if (!validatePackage(p, filePath, checks, logLevel) || !validPackage)
return std::nullopt;
return p;
@@ -415,12 +418,12 @@ static Package parseChromiumFile(QFile &file, const QString &filePath, LogLevel
}
// let's ignore warnings regarding Chromium files for now
- Q_UNUSED(validatePackage(p, filePath, logLevel));
+ Q_UNUSED(validatePackage(p, filePath, {}, logLevel));
return p;
}
-std::optional<QList<Package>> readFile(const QString &filePath, LogLevel logLevel)
+std::optional<QList<Package>> readFile(const QString &filePath, Checks checks, LogLevel logLevel)
{
QList<Package> packages;
bool errorsFound = false;
@@ -450,7 +453,8 @@ std::optional<QList<Package>> readFile(const QString &filePath, LogLevel logLeve
}
if (document.isObject()) {
- std::optional<Package> p = readPackage(document.object(), file.fileName(), logLevel);
+ std::optional<Package> p =
+ readPackage(document.object(), file.fileName(), checks, logLevel);
if (p) {
packages << *p;
} else {
@@ -462,7 +466,7 @@ std::optional<QList<Package>> readFile(const QString &filePath, LogLevel logLeve
QJsonValue value = array.at(i);
if (value.isObject()) {
std::optional<Package> p =
- readPackage(value.toObject(), file.fileName(), logLevel);
+ readPackage(value.toObject(), file.fileName(), checks, logLevel);
if (p) {
packages << *p;
} else {
@@ -503,7 +507,7 @@ std::optional<QList<Package>> readFile(const QString &filePath, LogLevel logLeve
}
std::optional<QList<Package>> scanDirectory(const QString &directory, InputFormats inputFormats,
- LogLevel logLevel)
+ Checks checks, LogLevel logLevel)
{
QDir dir(directory);
QList<Package> packages;
@@ -524,13 +528,13 @@ std::optional<QList<Package>> scanDirectory(const QString &directory, InputForma
for (const QFileInfo &info : entries) {
if (info.isDir()) {
std::optional<QList<Package>> ps =
- scanDirectory(info.filePath(), inputFormats, logLevel);
+ scanDirectory(info.filePath(), inputFormats, checks, logLevel);
if (!ps)
errorsFound = true;
else
packages += *ps;
} else {
- std::optional p = readFile(info.filePath(), logLevel);
+ std::optional p = readFile(info.filePath(), checks, logLevel);
if (!p)
errorsFound = true;
else
diff --git a/src/qtattributionsscanner/scanner.h b/src/qtattributionsscanner/scanner.h
index 77edaf30c..01c9a8b61 100644
--- a/src/qtattributionsscanner/scanner.h
+++ b/src/qtattributionsscanner/scanner.h
@@ -21,9 +21,13 @@ enum class InputFormat {
Q_DECLARE_FLAGS(InputFormats, InputFormat)
Q_DECLARE_OPERATORS_FOR_FLAGS(InputFormats)
-std::optional<QList<Package>> readFile(const QString &filePath, LogLevel logLevel);
+enum class Check { Paths = 0x1, All = Paths };
+Q_DECLARE_FLAGS(Checks, Check)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Checks)
+
+std::optional<QList<Package>> readFile(const QString &filePath, Checks checks, LogLevel logLevel);
std::optional<QList<Package>> scanDirectory(const QString &directory, InputFormats inputFormats,
- LogLevel logLevel);
+ Checks checks, LogLevel logLevel);
}
#endif // SCANNER_H