aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmldom
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2021-08-09 12:20:35 +0200
committerFawzi Mohamed <fawzi@gmx.ch>2021-09-06 14:03:11 +0200
commit7331f651c1c16217a31f3cdec700f014057b7268 (patch)
tree8a3d166ade9ee970a3329bd2e8f1cce99d2d9f89 /tools/qmldom
parent06e96fdcdeee76fc65569cb64e5da26850b19c00 (diff)
qmldom: pass optional fileType to loadFile
If filetype is given use it to specify the type of the file to load (otherwise guess it from the file extension). Can be used to load qmltypes files as "plain" qml files (for reformatting). Ths enables the reformatting of .qmltypes (for API comparison) Change-Id: Ib65647c2a8dc8b37b7e955acb3aec2193d36666d Pick-to: 6.2 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmldom')
-rw-r--r--tools/qmldom/qmldomtool.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/tools/qmldom/qmldomtool.cpp b/tools/qmldom/qmldomtool.cpp
index 8efa652082..c70b77b520 100644
--- a/tools/qmldom/qmldomtool.cpp
+++ b/tools/qmldom/qmldomtool.cpp
@@ -41,6 +41,7 @@
#include <QtQmlDom/private/qqmldomfieldfilter_p.h>
#include <cstdio>
+#include <optional>
#if QT_CONFIG(commandlineparser)
# include <QtCore/qcommandlineparser.h>
@@ -152,6 +153,10 @@ int main(int argc, char *argv[])
}
}
+ std::optional<DomType> fileType;
+ if (parser.isSet(reformatOption))
+ fileType = DomType::QmlFile;
+
Dependencies dep = Dependencies::None;
for (QString depName : parser.values(dependenciesOption)) {
QMetaEnum metaEnum = QMetaEnum::fromType<Dependencies>();
@@ -230,15 +235,22 @@ int main(int argc, char *argv[])
if (dep != Dependencies::None)
env.loadBuiltins();
foreach (QString s, positionalArguments) {
- env.loadFile(s, QString(), nullptr, LoadOption::DefaultLoad);
+ env.loadFile(s, QString(), nullptr, LoadOption::DefaultLoad, fileType);
}
envPtr->loadPendingDependencies(env);
+ bool hadFailures = false;
+ const qsizetype largestFileSizeToCheck = 32000;
if (parser.isSet(reformatOption)) {
for (auto s : positionalArguments) {
- DomItem qmlFile = env.path(Paths::qmldirFilePath(s));
+ DomItem qmlFile = env.path(Paths::qmlFilePath(QFileInfo(s).canonicalFilePath()));
if (qmlFile) {
qDebug() << "reformatting" << s;
FileWriter fw;
+ LineWriterOptions lwOptions;
+ WriteOutChecks checks = WriteOutCheck::Default;
+ if (std::shared_ptr<QmlFile> qmlFilePtr = qmlFile.ownerAs<QmlFile>())
+ if (qmlFilePtr->code().size() > largestFileSizeToCheck)
+ checks = WriteOutCheck::None;
QString target = s;
QString rDir = parser.value(reformatDirOption);
if (!rDir.isEmpty()) {
@@ -246,16 +258,8 @@ int main(int argc, char *argv[])
QDir d(rDir);
target = d.filePath(f.fileName());
}
- switch (fw.write(
- target,
- [&qmlFile, target](QTextStream &ts) {
- LineWriter lw([&ts](QStringView s) { ts << s; }, target);
- OutWriter ow(lw);
- qmlFile.writeOut(ow);
- ow.eof();
- return true;
- },
- nBackups)) {
+ MutableDomItem res = qmlFile.writeOut(target, nBackups, lwOptions, &fw, checks);
+ switch (fw.status) {
case FileWriter::Status::ShouldWrite:
case FileWriter::Status::SkippedDueToFailure:
qWarning() << "failure reformatting " << s;
@@ -266,10 +270,10 @@ int main(int argc, char *argv[])
case FileWriter::Status::SkippedEqual:
qDebug() << "no change";
}
+ hadFailures = hadFailures || !bool(res);
}
}
- }
- if (parser.isSet(dumpOption) || !parser.isSet(reformatOption)) {
+ } else if (parser.isSet(dumpOption) || !parser.isSet(reformatOption)) {
qDebug() << "will dump\n";
QTextStream ts(stdout);
auto sink = [&ts](QStringView v) {