diff options
author | Paul Wicking <paul.wicking@qt.io> | 2024-02-02 21:22:16 +0100 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2024-02-05 14:54:12 +0100 |
commit | 0d6bffcd1bfd5b08e5b8984c9385b08d5137480c (patch) | |
tree | f6914035beddb11061c166afa6d70d1ef3c30a32 | |
parent | 4be03918a2cd32a0341a69b2c7b4ae2f6467d4e3 (diff) |
QDoc: Ensure help project QHP SHA1s work cross platform
QDoc can generate Qt Help Project files (`.qhp`-files) through its
`HelpProjectWriter` interface. When it does, it also generates a
`.sha1` file for the generated `.qhp` file. The SHA1 hash it generates
on Windows differs from that it generates on other platforms. This
issue was uncovered when restructuring QDoc's tests for the files it
generates.
Upon investigating the problem, the initial hypothesis was that it was
possibly caused by differing line endings on different platforms. This
theory led to the discovery of a forum.qt.io discussion about a similar
problem:
https://forum.qt.io/topic/124177/qcryptographichash-results-mismatches/3
The forum discussion suggests dropping the `QFile::Text` flag when
opening the file for writing. Indeed, the documentation for
`QIODeviceBase::Text` (the implementation of said flag) states that
"When writing, the end-of-line terminators are translated
to the local encoding, for example '\r\n' for Win32."
This means that on Windows, the `QFile::Text` flag can cause line
ending conversions when writing files. Dropping that flag when opening
the output file ensures that the data is written without any automatic
line ending conversions, thus the result should be consistent across
different platforms.
This means QDoc must open the hashFile in binary mode by not passing
the `QFile::Text` flag. The reason for this is that, on Windows, the
`QFile::Text` flag can cause line ending conversions when reading or
writing text files.
Validating the fix is challenging, as `HelpProjectWriter` isn't covered
by any unit tests. However; the change that follows this makes use of
the QHP-generating capabilities of QDoc in a test, and serves to
validate this fix.
Fixes: QTBUG-121850
Task-number: QTBUG-119500
Pick-to: 6.5
Change-Id: I9c3c2242c7698e1b7bc031dd33cdbd305d96c713
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
(cherry picked from commit 473fbb486926ba8629447d2b91483d982075b4fb)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 8dcf9dd90d0225ca4a1712a78bcfce7389c9b19a)
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
-rw-r--r-- | src/qdoc/qdoc/helpprojectwriter.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/qdoc/qdoc/helpprojectwriter.cpp b/src/qdoc/qdoc/helpprojectwriter.cpp index 4d9edbdf7..86e85bcaa 100644 --- a/src/qdoc/qdoc/helpprojectwriter.cpp +++ b/src/qdoc/qdoc/helpprojectwriter.cpp @@ -466,7 +466,7 @@ void HelpProjectWriter::writeHashFile(QFile &file) hash.addData(&file); QFile hashFile(file.fileName() + ".sha1"); - if (!hashFile.open(QFile::WriteOnly | QFile::Text)) + if (!hashFile.open(QFile::WriteOnly)) return; hashFile.write(hash.result().toHex()); @@ -578,7 +578,7 @@ void HelpProjectWriter::generateProject(HelpProject &project) project.m_keywords.clear(); QFile file(m_outputDir + QDir::separator() + project.m_fileName); - if (!file.open(QFile::WriteOnly | QFile::Text)) + if (!file.open(QFile::WriteOnly)) return; QXmlStreamWriter writer(&file); |