summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2024-02-02 21:22:16 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-02-04 10:47:07 +0000
commit8dcf9dd90d0225ca4a1712a78bcfce7389c9b19a (patch)
treee434a006f84538aeb75774bc0a47aa9c902d5e78
parent732ad4cd43f54b6d09dbea8573d4c45fe880fee1 (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.6 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>
-rw-r--r--src/qdoc/qdoc/src/qdoc/helpprojectwriter.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/qdoc/qdoc/src/qdoc/helpprojectwriter.cpp b/src/qdoc/qdoc/src/qdoc/helpprojectwriter.cpp
index 4d9edbdf7..86e85bcaa 100644
--- a/src/qdoc/qdoc/src/qdoc/helpprojectwriter.cpp
+++ b/src/qdoc/qdoc/src/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);