Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmltoolingutils.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
6
7#include <QtCore/qfileinfo.h>
8#include <QtCore/qdir.h>
9
10using namespace Qt::StringLiterals;
11
12/*!
13\internal
14
15Helper utils to help QQmlTooling retrieve certain values from the environment or command line
16options.
17It helps to keep the warning messages consistent between tools like qmlls and qmllint when
18they use environment variables, for examples.
19*/
20
21void QQmlToolingUtils::warnForInvalidDirs(const QStringList &dirs, const QString &origin)
22{
23 for (const QString &path : dirs) {
24 QFileInfo info(path);
25 if (!info.exists()) {
26 qWarning().noquote().nospace()
27 << u"Argument \"%1\" %2 does not exist."_s.arg(path, origin);
28 continue;
29 }
30 if (!info.isDir()) {
31 qWarning().noquote().nospace()
32 << "Argument \"" << path << "\" " << origin << " is not a directory.";
33 continue;
34 }
35 }
36}
37
38QStringList
39QQmlToolingUtils::getAndWarnForInvalidDirsFromEnv(const QString &environmentVariableName)
40{
41 const QStringList envPaths = qEnvironmentVariable(environmentVariableName.toUtf8())
42 .split(QDir::listSeparator(), Qt::SkipEmptyParts);
43 warnForInvalidDirs(envPaths,
44 u"from environment variable \"%1\""_s.arg(environmentVariableName));
45 return envPaths;
46}
47
48QStringList QQmlToolingUtils::getAndWarnForInvalidDirsFromOption(const QCommandLineParser &parser,
49 const QCommandLineOption &option)
50{
51 if (!parser.isSet(option))
52 return {};
53
54 const QStringList dirs = parser.values(option);
55 const QString optionName = option.names().constFirst();
56 warnForInvalidDirs(dirs, u"passed to -%1"_s.arg(optionName));
57 return dirs;
58}