guix/gnu/packages/patches/qtbase-use-TZDIR.patch

142 lines
5.6 KiB
Diff
Raw Normal View History

From 1075606f8b2f9e153c82f8e50cbd69cea9c72e87 Mon Sep 17 00:00:00 2001
From: Edward Welbourne <edward.welbourne@qt.io>
Date: Mon, 11 Sep 2023 11:41:39 +0200
Subject: [PATCH] Support the TZDIR environment variable
gnu: qtbase: Use the store paths for other packages and dynamically loaded libs. Transfer the applicable NixOS patches as of 2018-01-19: - Not adopted: We don't change the .cmake.in and .prf, but use config mechanisms provided by th Qt build system. - src/corelib/tools/qtimezoneprivate_tz.cpp: Adopted patch: Use $TZDIR to search for time-zone data. Thus avoid depending on package "tzdata", which often introduces changes with near-immediate effects, so it's important to be able to update it fast. - src/corelib/kernel/qcoreapplication.cpp: Not adopted: NixOS adds plugin paths derived from PATH. We do not need this, since we already have native-search-path QT_PLUGIN_PATH. - src/network/kernel/qdnslookup_unix.cpp, src/network/kernel/qhostinfo_unix.cpp: Transferred: Use hard-coded path to libresolv. - src/network/ssl/qsslcontext_openssl.cpp: Not adopted: NixOS changes a conditional compilation for Qt 5.9 (but leaves it unchanged for Qt 5.10) to fix compilation with libressl. But Qt does not support libressl anway, see config.tests/openssl/openssl.cpp in qtbase 5.9.4. - src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp: Transferred: Use hard-coded path to libx11. - src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp: Transferred: Use hard-coded path to mess's libGL, no need for a fall-back. - src/plugins/platforms/xcb/qxcbcursor.cpp: Transferred: Use hard-coded path to Xcursor. - src/plugins/platformthemes/gtk3/main.cpp: Not adopted: NixOS changes $XDG_DATA_DIRS and $GIO_EXTRA_MODULES in the code. We already have a search-path-specification for this. - src/testlib/qtestassert.h: Decided not to adopt this for guix. * gnu/packages/patches/qtbase-use-TZDIR.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. * gnu/packages/qt.scm (qtbase): Add comment. [source]: Use new patch. [arguments]<#:phases>'patch-paths': New phase.
2017-11-02 22:03:24 +00:00
On Linux / glibc, this overrides the default system location for the
zone info. So check for files there first. Break out a function to
manage the trying of (now three) zoneinfo directories when opening a
file by name relative to there.
Pick-to: 6.6 6.5
Task-number: QTBUG-116017
Change-Id: I1f97107aabd9015c0a5543639870f1d70654ca67
---
* Rebased on top of v6.5.2.
src/corelib/time/qtimezoneprivate_tz.cpp | 73 ++++++++++++++++--------
1 file changed, 49 insertions(+), 24 deletions(-)
diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp
index 067191d816..a8b2fc894e 100644
--- a/src/corelib/time/qtimezoneprivate_tz.cpp
+++ b/src/corelib/time/qtimezoneprivate_tz.cpp
@@ -51,17 +51,41 @@ typedef QHash<QByteArray, QTzTimeZone> QTzTimeZoneHash;
static bool isTzFile(const QString &name);
+// Open a named file under the zone info directory:
+static bool openZoneInfo(QString name, QFile *file)
+{
+ // At least on Linux / glibc (see man 3 tzset), $TZDIR overrides the system
+ // default location for zone info:
+ const QString tzdir = qEnvironmentVariable("TZDIR");
+ if (!tzdir.isEmpty()) {
+ file->setFileName(QDir(tzdir).filePath(name));
+ if (file->open(QIODevice::ReadOnly))
+ return true;
+ }
+ // Try modern system path first:
+ constexpr auto zoneShare = "/usr/share/zoneinfo/"_L1;
+ if (tzdir != zoneShare && tzdir != zoneShare.chopped(1)) {
+ file->setFileName(zoneShare + name);
+ if (file->open(QIODevice::ReadOnly))
+ return true;
+ }
+ // Fall back to legacy system path:
+ constexpr auto zoneLib = "/usr/lib/zoneinfo/"_L1;
+ if (tzdir != zoneLib && tzdir != zoneLib.chopped(1)) {
+ file->setFileName(zoneShare + name);
+ if (file->open(QIODevice::ReadOnly))
+ return true;
+ }
+ return false;
+}
+
// Parse zone.tab table for territory information, read directories to ensure we
// find all installed zones (many are omitted from zone.tab; even more from
// zone1970.tab).
gnu: qtbase: Use the store paths for other packages and dynamically loaded libs. Transfer the applicable NixOS patches as of 2018-01-19: - Not adopted: We don't change the .cmake.in and .prf, but use config mechanisms provided by th Qt build system. - src/corelib/tools/qtimezoneprivate_tz.cpp: Adopted patch: Use $TZDIR to search for time-zone data. Thus avoid depending on package "tzdata", which often introduces changes with near-immediate effects, so it's important to be able to update it fast. - src/corelib/kernel/qcoreapplication.cpp: Not adopted: NixOS adds plugin paths derived from PATH. We do not need this, since we already have native-search-path QT_PLUGIN_PATH. - src/network/kernel/qdnslookup_unix.cpp, src/network/kernel/qhostinfo_unix.cpp: Transferred: Use hard-coded path to libresolv. - src/network/ssl/qsslcontext_openssl.cpp: Not adopted: NixOS changes a conditional compilation for Qt 5.9 (but leaves it unchanged for Qt 5.10) to fix compilation with libressl. But Qt does not support libressl anway, see config.tests/openssl/openssl.cpp in qtbase 5.9.4. - src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp: Transferred: Use hard-coded path to libx11. - src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp: Transferred: Use hard-coded path to mess's libGL, no need for a fall-back. - src/plugins/platforms/xcb/qxcbcursor.cpp: Transferred: Use hard-coded path to Xcursor. - src/plugins/platformthemes/gtk3/main.cpp: Not adopted: NixOS changes $XDG_DATA_DIRS and $GIO_EXTRA_MODULES in the code. We already have a search-path-specification for this. - src/testlib/qtestassert.h: Decided not to adopt this for guix. * gnu/packages/patches/qtbase-use-TZDIR.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. * gnu/packages/qt.scm (qtbase): Add comment. [source]: Use new patch. [arguments]<#:phases>'patch-paths': New phase.
2017-11-02 22:03:24 +00:00
static QTzTimeZoneHash loadTzTimeZones()
{
- QString path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
- if (!QFile::exists(path))
- path = QStringLiteral("/usr/lib/zoneinfo/zone.tab");
-
- QFile tzif(path);
- if (!tzif.open(QIODevice::ReadOnly))
+ QFile tzif;
+ if (!openZoneInfo("zone.tab"_L1, &tzif))
return QTzTimeZoneHash();
gnu: qtbase: Use the store paths for other packages and dynamically loaded libs. Transfer the applicable NixOS patches as of 2018-01-19: - Not adopted: We don't change the .cmake.in and .prf, but use config mechanisms provided by th Qt build system. - src/corelib/tools/qtimezoneprivate_tz.cpp: Adopted patch: Use $TZDIR to search for time-zone data. Thus avoid depending on package "tzdata", which often introduces changes with near-immediate effects, so it's important to be able to update it fast. - src/corelib/kernel/qcoreapplication.cpp: Not adopted: NixOS adds plugin paths derived from PATH. We do not need this, since we already have native-search-path QT_PLUGIN_PATH. - src/network/kernel/qdnslookup_unix.cpp, src/network/kernel/qhostinfo_unix.cpp: Transferred: Use hard-coded path to libresolv. - src/network/ssl/qsslcontext_openssl.cpp: Not adopted: NixOS changes a conditional compilation for Qt 5.9 (but leaves it unchanged for Qt 5.10) to fix compilation with libressl. But Qt does not support libressl anway, see config.tests/openssl/openssl.cpp in qtbase 5.9.4. - src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp: Transferred: Use hard-coded path to libx11. - src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp: Transferred: Use hard-coded path to mess's libGL, no need for a fall-back. - src/plugins/platforms/xcb/qxcbcursor.cpp: Transferred: Use hard-coded path to Xcursor. - src/plugins/platformthemes/gtk3/main.cpp: Not adopted: NixOS changes $XDG_DATA_DIRS and $GIO_EXTRA_MODULES in the code. We already have a search-path-specification for this. - src/testlib/qtestassert.h: Decided not to adopt this for guix. * gnu/packages/patches/qtbase-use-TZDIR.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. * gnu/packages/qt.scm (qtbase): Add comment. [source]: Use new patch. [arguments]<#:phases>'patch-paths': New phase.
2017-11-02 22:03:24 +00:00
QTzTimeZoneHash zonesHash;
@@ -91,6 +115,7 @@ static QTzTimeZoneHash loadTzTimeZones()
}
}
+ const QString path = tzif.fileName();
const qsizetype cut = path.lastIndexOf(u'/');
Q_ASSERT(cut > 0);
const QDir zoneDir = QDir(path.first(cut));
@@ -761,20 +786,13 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::findEntry(const QByteArray &ianaId)
tzif.setFileName(QStringLiteral("/etc/localtime"));
gnu: qtbase: Use the store paths for other packages and dynamically loaded libs. Transfer the applicable NixOS patches as of 2018-01-19: - Not adopted: We don't change the .cmake.in and .prf, but use config mechanisms provided by th Qt build system. - src/corelib/tools/qtimezoneprivate_tz.cpp: Adopted patch: Use $TZDIR to search for time-zone data. Thus avoid depending on package "tzdata", which often introduces changes with near-immediate effects, so it's important to be able to update it fast. - src/corelib/kernel/qcoreapplication.cpp: Not adopted: NixOS adds plugin paths derived from PATH. We do not need this, since we already have native-search-path QT_PLUGIN_PATH. - src/network/kernel/qdnslookup_unix.cpp, src/network/kernel/qhostinfo_unix.cpp: Transferred: Use hard-coded path to libresolv. - src/network/ssl/qsslcontext_openssl.cpp: Not adopted: NixOS changes a conditional compilation for Qt 5.9 (but leaves it unchanged for Qt 5.10) to fix compilation with libressl. But Qt does not support libressl anway, see config.tests/openssl/openssl.cpp in qtbase 5.9.4. - src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp: Transferred: Use hard-coded path to libx11. - src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp: Transferred: Use hard-coded path to mess's libGL, no need for a fall-back. - src/plugins/platforms/xcb/qxcbcursor.cpp: Transferred: Use hard-coded path to Xcursor. - src/plugins/platformthemes/gtk3/main.cpp: Not adopted: NixOS changes $XDG_DATA_DIRS and $GIO_EXTRA_MODULES in the code. We already have a search-path-specification for this. - src/testlib/qtestassert.h: Decided not to adopt this for guix. * gnu/packages/patches/qtbase-use-TZDIR.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. * gnu/packages/qt.scm (qtbase): Add comment. [source]: Use new patch. [arguments]<#:phases>'patch-paths': New phase.
2017-11-02 22:03:24 +00:00
if (!tzif.open(QIODevice::ReadOnly))
return ret;
- } else {
- // Open named tz, try modern path first, if fails try legacy path
- tzif.setFileName("/usr/share/zoneinfo/"_L1 + QString::fromLocal8Bit(ianaId));
- if (!tzif.open(QIODevice::ReadOnly)) {
- tzif.setFileName("/usr/lib/zoneinfo/"_L1 + QString::fromLocal8Bit(ianaId));
- if (!tzif.open(QIODevice::ReadOnly)) {
- // ianaId may be a POSIX rule, taken from $TZ or /etc/TZ
- auto check = validatePosixRule(ianaId);
- if (check.isValid) {
- ret.m_hasDst = check.hasDst;
- ret.m_posixRule = ianaId;
- }
- return ret;
- }
+ } else if (!openZoneInfo(QString::fromLocal8Bit(ianaId), &tzif)) {
+ // ianaId may be a POSIX rule, taken from $TZ or /etc/TZ
+ auto check = validatePosixRule(ianaId);
+ if (check.isValid) {
+ ret.m_hasDst = check.hasDst;
+ ret.m_posixRule = ianaId;
+ return ret;
gnu: qtbase: Use the store paths for other packages and dynamically loaded libs. Transfer the applicable NixOS patches as of 2018-01-19: - Not adopted: We don't change the .cmake.in and .prf, but use config mechanisms provided by th Qt build system. - src/corelib/tools/qtimezoneprivate_tz.cpp: Adopted patch: Use $TZDIR to search for time-zone data. Thus avoid depending on package "tzdata", which often introduces changes with near-immediate effects, so it's important to be able to update it fast. - src/corelib/kernel/qcoreapplication.cpp: Not adopted: NixOS adds plugin paths derived from PATH. We do not need this, since we already have native-search-path QT_PLUGIN_PATH. - src/network/kernel/qdnslookup_unix.cpp, src/network/kernel/qhostinfo_unix.cpp: Transferred: Use hard-coded path to libresolv. - src/network/ssl/qsslcontext_openssl.cpp: Not adopted: NixOS changes a conditional compilation for Qt 5.9 (but leaves it unchanged for Qt 5.10) to fix compilation with libressl. But Qt does not support libressl anway, see config.tests/openssl/openssl.cpp in qtbase 5.9.4. - src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp: Transferred: Use hard-coded path to libx11. - src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp: Transferred: Use hard-coded path to mess's libGL, no need for a fall-back. - src/plugins/platforms/xcb/qxcbcursor.cpp: Transferred: Use hard-coded path to Xcursor. - src/plugins/platformthemes/gtk3/main.cpp: Not adopted: NixOS changes $XDG_DATA_DIRS and $GIO_EXTRA_MODULES in the code. We already have a search-path-specification for this. - src/testlib/qtestassert.h: Decided not to adopt this for guix. * gnu/packages/patches/qtbase-use-TZDIR.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. * gnu/packages/qt.scm (qtbase): Add comment. [source]: Use new patch. [arguments]<#:phases>'patch-paths': New phase.
2017-11-02 22:03:24 +00:00
}
}
@@ -1317,7 +1335,8 @@ private:
{
// On most distros /etc/localtime is a symlink to a real file so extract
// name from the path
- const auto zoneinfo = "/zoneinfo/"_L1;
+ const QString tzdir = qEnvironmentVariable("TZDIR");
+ constexpr auto zoneinfo = "/zoneinfo/"_L1;
QString path = QStringLiteral("/etc/localtime");
long iteration = getSymloopMax();
// Symlink may point to another symlink etc. before being under zoneinfo/
@@ -1325,9 +1344,15 @@ private:
// symlink, like America/Montreal pointing to America/Toronto
do {
path = QFile::symLinkTarget(path);
- int index = path.indexOf(zoneinfo);
- if (index >= 0) // Found zoneinfo file; extract zone name from path:
- return QStringView{ path }.mid(index + zoneinfo.size()).toUtf8();
+ // If it's a zoneinfo file, extract the zone name from its path:
+ int index = tzdir.isEmpty() ? -1 : path.indexOf(tzdir);
+ if (index >= 0) {
+ const auto tail = QStringView{ path }.sliced(index + tzdir.size()).toUtf8();
+ return tail.startsWith(u'/') ? tail.sliced(1) : tail;
+ }
+ index = path.indexOf(zoneinfo);
+ if (index >= 0)
+ return QStringView{ path }.sliced(index + zoneinfo.size()).toUtf8();
} while (!path.isEmpty() && --iteration > 0);
return QByteArray();
base-commit: af457a9f0f7eb1a2a7d11f495da508faab91a442
--
2.41.0