Gentoo Archives: gentoo-commits

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: kde-frameworks/kunitconversion/, kde-frameworks/kunitconversion/files/
Date: Mon, 30 Aug 2021 17:59:10
Message-Id: 1630346224.023672ffe5fabfe84fded3a555312764ca3894c0.asturm@gentoo
1 commit: 023672ffe5fabfe84fded3a555312764ca3894c0
2 Author: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
3 AuthorDate: Mon Aug 30 17:56:11 2021 +0000
4 Commit: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
5 CommitDate: Mon Aug 30 17:57:04 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=023672ff
7
8 kde-frameworks/kunitconversion: Fix currency runner
9
10 Upstream commits:
11 6e41104426a3ae59bcb90be708abcc3092155436
12 2a57f9d1c6b2f8d9e2babcdaca66f1cf2a3c5849
13
14 KDE-bug: https://bugs.kde.org/show_bug.cgi?id=441337
15 Package-Manager: Portage-3.0.22, Repoman-3.0.3
16 Signed-off-by: Andreas Sturmlechner <asturm <AT> gentoo.org>
17
18 ...itconversion-5.85.0-fix-24h-currency-sync.patch | 91 ++++++++
19 ...onversion-5.85.0-fix-currency-values-init.patch | 235 +++++++++++++++++++++
20 .../kunitconversion-5.85.0-r1.ebuild | 33 +++
21 3 files changed, 359 insertions(+)
22
23 diff --git a/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-24h-currency-sync.patch b/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-24h-currency-sync.patch
24 new file mode 100644
25 index 00000000000..056a2e8b1e5
26 --- /dev/null
27 +++ b/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-24h-currency-sync.patch
28 @@ -0,0 +1,91 @@
29 +From 6e41104426a3ae59bcb90be708abcc3092155436 Mon Sep 17 00:00:00 2001
30 +From: Andreas Cord-Landwehr <cordlandwehr@×××.org>
31 +Date: Tue, 24 Aug 2021 21:06:47 +0200
32 +Subject: [PATCH] Fix automatic currency file sync after 24h
33 +
34 +Conversion plugin in Krunner depends on automatic refresh of currency
35 +table. std::call_once does not work there, because process is never
36 +stopped.
37 +
38 +BUG: 441337
39 +---
40 + autotests/convertertest.cpp | 16 ++++++++++++++++
41 + autotests/convertertest.h | 6 ++++++
42 + src/currency.cpp | 9 ++++++---
43 + 3 files changed, 28 insertions(+), 3 deletions(-)
44 +
45 +diff --git a/autotests/convertertest.cpp b/autotests/convertertest.cpp
46 +index aa0ccae..e36b7fe 100644
47 +--- a/autotests/convertertest.cpp
48 ++++ b/autotests/convertertest.cpp
49 +@@ -8,9 +8,11 @@
50 + #include <QStandardPaths>
51 + #include <QThread>
52 + #include <QVector>
53 ++#include <currency_p.h>
54 + #include <kunitconversion/unitcategory.h>
55 +
56 + using namespace KUnitConversion;
57 ++using namespace std::chrono_literals;
58 +
59 + void ConverterTest::initTestCase()
60 + {
61 +@@ -113,4 +115,18 @@ void ConverterTest::testCurrency()
62 + qDeleteAll(threads);
63 + }
64 +
65 ++void ConverterTest::testCurrencyConversionTableUpdate()
66 ++{
67 ++ const QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/libkunitconversion/currency.xml");
68 ++
69 ++ // Missing conversion table must lead to update of table
70 ++ // note that this is the same code path as for last modified updates
71 ++ QFile::remove(cache);
72 ++ QVERIFY(Currency::lastConversionTableUpdate().isNull());
73 ++ Converter c;
74 ++ Value input = Value(1000, Eur);
75 ++ Value v = c.convert(input, QStringLiteral("$"));
76 ++ QVERIFY(!Currency::lastConversionTableUpdate().isNull());
77 ++}
78 ++
79 + QTEST_MAIN(ConverterTest)
80 +diff --git a/autotests/convertertest.h b/autotests/convertertest.h
81 +index 21d5213..d3d6303 100644
82 +--- a/autotests/convertertest.h
83 ++++ b/autotests/convertertest.h
84 +@@ -23,6 +23,12 @@ private Q_SLOTS:
85 + void testConvert();
86 + void testInvalid();
87 + void testCurrency();
88 ++ /**
89 ++ * Checks that conversion tables are updated after timeout
90 ++ *
91 ++ * Regression test for https://bugs.kde.org/show_bug.cgi?id=441337
92 ++ */
93 ++ void testCurrencyConversionTableUpdate();
94 + };
95 +
96 + #endif // CONVERTERTEST_H
97 +diff --git a/src/currency.cpp b/src/currency.cpp
98 +index 038e928..ead7ce5 100644
99 +--- a/src/currency.cpp
100 ++++ b/src/currency.cpp
101 +@@ -745,9 +745,12 @@ void CurrencyCategoryPrivate::syncConversionTable(std::chrono::seconds updateSki
102 + Value CurrencyCategoryPrivate::convert(const Value &value, const Unit &to)
103 + {
104 + // TODO KF6 remove this blocking call and change behavior that explicit call to syncConversionTable is mandatory before
105 +- // right now, if a sync is performed at application start, then this call will not block anymore for 24 hours
106 +- static std::once_flag updateFlag;
107 +- std::call_once(updateFlag, &CurrencyCategoryPrivate::syncConversionTable, this, 24h);
108 ++ // first access to converted data, also to make syncs more explicit
109 ++ static QMutex updateFlag;
110 ++ {
111 ++ QMutexLocker locker(&updateFlag);
112 ++ CurrencyCategoryPrivate::syncConversionTable(24h);
113 ++ }
114 +
115 + Value v = UnitCategoryPrivate::convert(value, to);
116 + return v;
117 +--
118 +GitLab
119 +
120
121 diff --git a/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-currency-values-init.patch b/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-currency-values-init.patch
122 new file mode 100644
123 index 00000000000..01ee8a6fa57
124 --- /dev/null
125 +++ b/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-currency-values-init.patch
126 @@ -0,0 +1,235 @@
127 +From 2a57f9d1c6b2f8d9e2babcdaca66f1cf2a3c5849 Mon Sep 17 00:00:00 2001
128 +From: Andreas Cord-Landwehr <cordlandwehr@×××.org>
129 +Date: Sat, 28 Aug 2021 11:42:06 +0200
130 +Subject: [PATCH] Fix initialization of currency values
131 +
132 +If there is already a recent currency.xml file provided then use this to
133 +initialize the currency converter.
134 +
135 +BUG: 441337
136 +---
137 + autotests/CMakeLists.txt | 8 ++++
138 + autotests/currencytableinittest.cpp | 33 +++++++++++++++
139 + autotests/currencytableinittest.h | 26 ++++++++++++
140 + autotests/currencytableinittest/currency.xml | 43 ++++++++++++++++++++
141 + autotests/currencytableinittest/data.qrc | 5 +++
142 + autotests/valuetest.cpp | 6 +++
143 + src/currency.cpp | 10 +++--
144 + 7 files changed, 128 insertions(+), 3 deletions(-)
145 + create mode 100644 autotests/currencytableinittest.cpp
146 + create mode 100644 autotests/currencytableinittest.h
147 + create mode 100644 autotests/currencytableinittest/currency.xml
148 + create mode 100644 autotests/currencytableinittest/data.qrc
149 +
150 +diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
151 +index ec457a5..8225bf2 100644
152 +--- a/autotests/CMakeLists.txt
153 ++++ b/autotests/CMakeLists.txt
154 +@@ -8,3 +8,11 @@ ecm_add_tests(
155 + convertertest.cpp
156 + LINK_LIBRARIES KF5::UnitConversion KF5::I18n Qt5::Test
157 + )
158 ++
159 ++qt5_add_resources(CURRENCY_TEST_RESOURCES currencytableinittest/data.qrc)
160 ++ecm_add_test(
161 ++ currencytableinittest.cpp
162 ++ ${CURRENCY_TEST_RESOURCES}
163 ++ TEST_NAME currencytableinittest
164 ++ LINK_LIBRARIES KF5::UnitConversion KF5::I18n Qt5::Test
165 ++)
166 +diff --git a/autotests/currencytableinittest.cpp b/autotests/currencytableinittest.cpp
167 +new file mode 100644
168 +index 0000000..c83709a
169 +--- /dev/null
170 ++++ b/autotests/currencytableinittest.cpp
171 +@@ -0,0 +1,33 @@
172 ++/*
173 ++ * SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@×××.org>
174 ++ *
175 ++ * SPDX-License-Identifier: LGPL-2.0-or-later
176 ++ */
177 ++
178 ++#include "currencytableinittest.h"
179 ++#include <QStandardPaths>
180 ++#include <cmath>
181 ++
182 ++using namespace KUnitConversion;
183 ++
184 ++void CurrencyTableInitTest::testCategoryInit()
185 ++{
186 ++ QStandardPaths::setTestModeEnabled(true);
187 ++ const QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/libkunitconversion/currency.xml");
188 ++
189 ++ QVERIFY(QFile::exists(QLatin1String(":/currency.xml")));
190 ++ if (QFile::exists(cache)) {
191 ++ QFile::remove(cache);
192 ++ }
193 ++ // note: copy of file updates the file's modified timestamp and thus file is seen as recently downloaded file
194 ++ QVERIFY(QFile::copy(QLatin1String(":/currency.xml"), cache));
195 ++
196 ++ Converter c;
197 ++ Value input = Value(1000, Eur);
198 ++ Value v = c.convert(input, QStringLiteral("$"));
199 ++ qDebug() << "converted value to:" << v.number();
200 ++ QVERIFY(v.isValid());
201 ++ QVERIFY(!std::isnan(v.number()));
202 ++}
203 ++
204 ++QTEST_MAIN(CurrencyTableInitTest)
205 +diff --git a/autotests/currencytableinittest.h b/autotests/currencytableinittest.h
206 +new file mode 100644
207 +index 0000000..0b835d0
208 +--- /dev/null
209 ++++ b/autotests/currencytableinittest.h
210 +@@ -0,0 +1,26 @@
211 ++/*
212 ++ * SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@×××.org>
213 ++ *
214 ++ * SPDX-License-Identifier: LGPL-2.0-or-later
215 ++ */
216 ++
217 ++#ifndef CURRENCYTABLEINIT_TEST_H
218 ++#define CURRENCYTABLEINIT_TEST_H
219 ++
220 ++#include <QObject>
221 ++#include <QTest>
222 ++#include <kunitconversion/converter.h>
223 ++
224 ++using namespace KUnitConversion;
225 ++
226 ++class CurrencyTableInitTest : public QObject
227 ++{
228 ++ Q_OBJECT
229 ++private Q_SLOTS:
230 ++ /**
231 ++ * Check that the currency converter is correctly initialized when currency.xml is recent and available
232 ++ */
233 ++ void testCategoryInit();
234 ++};
235 ++
236 ++#endif
237 +diff --git a/autotests/currencytableinittest/currency.xml b/autotests/currencytableinittest/currency.xml
238 +new file mode 100644
239 +index 0000000..dca42d5
240 +--- /dev/null
241 ++++ b/autotests/currencytableinittest/currency.xml
242 +@@ -0,0 +1,43 @@
243 ++<?xml version="1.0" encoding="UTF-8"?>
244 ++<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
245 ++ <gesmes:subject>Reference rates</gesmes:subject>
246 ++ <gesmes:Sender>
247 ++ <gesmes:name>European Central Bank</gesmes:name>
248 ++ </gesmes:Sender>
249 ++ <Cube>
250 ++ <Cube time='2021-08-24'>
251 ++ <Cube currency='USD' rate='1.1740'/>
252 ++ <Cube currency='JPY' rate='128.74'/>
253 ++ <Cube currency='BGN' rate='1.9558'/>
254 ++ <Cube currency='CZK' rate='25.533'/>
255 ++ <Cube currency='DKK' rate='7.4370'/>
256 ++ <Cube currency='GBP' rate='0.85578'/>
257 ++ <Cube currency='HUF' rate='349.69'/>
258 ++ <Cube currency='PLN' rate='4.5792'/>
259 ++ <Cube currency='RON' rate='4.9280'/>
260 ++ <Cube currency='SEK' rate='10.2090'/>
261 ++ <Cube currency='CHF' rate='1.0711'/>
262 ++ <Cube currency='ISK' rate='150.00'/>
263 ++ <Cube currency='NOK' rate='10.4003'/>
264 ++ <Cube currency='HRK' rate='7.4938'/>
265 ++ <Cube currency='RUB' rate='86.7484'/>
266 ++ <Cube currency='TRY' rate='9.8836'/>
267 ++ <Cube currency='AUD' rate='1.6203'/>
268 ++ <Cube currency='BRL' rate='6.2681'/>
269 ++ <Cube currency='CAD' rate='1.4822'/>
270 ++ <Cube currency='CNY' rate='7.6042'/>
271 ++ <Cube currency='HKD' rate='9.1448'/>
272 ++ <Cube currency='IDR' rate='16897.00'/>
273 ++ <Cube currency='ILS' rate='3.7789'/>
274 ++ <Cube currency='INR' rate='87.0625'/>
275 ++ <Cube currency='KRW' rate='1369.00'/>
276 ++ <Cube currency='MXN' rate='23.8606'/>
277 ++ <Cube currency='MYR' rate='4.9525'/>
278 ++ <Cube currency='NZD' rate='1.6893'/>
279 ++ <Cube currency='PHP' rate='58.783'/>
280 ++ <Cube currency='SGD' rate='1.5918'/>
281 ++ <Cube currency='THB' rate='38.595'/>
282 ++ <Cube currency='ZAR' rate='17.6902'/>
283 ++ </Cube>
284 ++ </Cube>
285 ++</gesmes:Envelope>
286 +\ No newline at end of file
287 +diff --git a/autotests/currencytableinittest/data.qrc b/autotests/currencytableinittest/data.qrc
288 +new file mode 100644
289 +index 0000000..19f9d69
290 +--- /dev/null
291 ++++ b/autotests/currencytableinittest/data.qrc
292 +@@ -0,0 +1,5 @@
293 ++<RCC>
294 ++ <qresource prefix="/">
295 ++ <file>currency.xml</file>
296 ++ </qresource>
297 ++</RCC>
298 +diff --git a/autotests/valuetest.cpp b/autotests/valuetest.cpp
299 +index 0b348d7..53be1b7 100644
300 +--- a/autotests/valuetest.cpp
301 ++++ b/autotests/valuetest.cpp
302 +@@ -55,6 +55,12 @@ void ValueTest::testInvalid()
303 +
304 + void ValueTest::testCurrencyNotDownloaded()
305 + {
306 ++ // ensure that no local conversion table is available
307 ++ const QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/libkunitconversion/currency.xml");
308 ++ if (!QFile::exists(cache)) {
309 ++ QFile::remove(cache);
310 ++ }
311 ++
312 + auto pounds = Value(100, Gbp);
313 + auto eur = pounds.convertTo(Eur);
314 + QVERIFY(!eur.isValid());
315 +diff --git a/src/currency.cpp b/src/currency.cpp
316 +index ead7ce5..43161e2 100644
317 +--- a/src/currency.cpp
318 ++++ b/src/currency.cpp
319 +@@ -47,6 +47,7 @@ public:
320 + Value convert(const Value &value, const Unit &toUnit) override;
321 + bool hasOnlineConversionTable() const override;
322 + void syncConversionTable(std::chrono::seconds updateSkipSeconds) override;
323 ++ bool m_initialized{false}; //!< indicates if units are prepared from currency table
324 + };
325 +
326 + bool CurrencyCategoryPrivate::hasOnlineConversionTable() const
327 +@@ -668,12 +669,12 @@ QDateTime Currency::lastConversionTableUpdate()
328 + void CurrencyCategoryPrivate::syncConversionTable(std::chrono::seconds updateSkipPeriod)
329 + {
330 + // sync call is expected to be guarded as being called only once
331 +- auto updateCurrencyConversionTable = [this](const QString &cachePath) {
332 ++ auto updateCurrencyConversionTable = [this](const QString &cachePath, bool performNetworkSync) {
333 + qCDebug(LOG_KUNITCONVERSION) << "currency conversion table sync started";
334 + static QMutex mutex;
335 + QMutexLocker locker(&mutex);
336 + bool updateError{false};
337 +- if (isConnected()) {
338 ++ if (performNetworkSync && isConnected()) {
339 + // Bug 345750: QNetworkReply does not work without an event loop and doesn't implement waitForReadyRead()
340 + QEventLoop loop;
341 + QNetworkAccessManager manager;
342 +@@ -733,12 +734,15 @@ void CurrencyCategoryPrivate::syncConversionTable(std::chrono::seconds updateSki
343 + }
344 + }
345 + }
346 ++ m_initialized = !updateError;
347 + return !updateError;
348 + };
349 +
350 + QFileInfo info(cacheLocation());
351 + if (!info.exists() || info.lastModified().secsTo(QDateTime::currentDateTime()) > updateSkipPeriod.count()) {
352 +- updateCurrencyConversionTable(cacheLocation());
353 ++ updateCurrencyConversionTable(cacheLocation(), true);
354 ++ } else if (!m_initialized) {
355 ++ updateCurrencyConversionTable(cacheLocation(), false);
356 + }
357 + }
358 +
359 +--
360 +GitLab
361 +
362
363 diff --git a/kde-frameworks/kunitconversion/kunitconversion-5.85.0-r1.ebuild b/kde-frameworks/kunitconversion/kunitconversion-5.85.0-r1.ebuild
364 new file mode 100644
365 index 00000000000..1a8a5753d91
366 --- /dev/null
367 +++ b/kde-frameworks/kunitconversion/kunitconversion-5.85.0-r1.ebuild
368 @@ -0,0 +1,33 @@
369 +# Copyright 1999-2021 Gentoo Authors
370 +# Distributed under the terms of the GNU General Public License v2
371 +
372 +EAPI=7
373 +
374 +PVCUT=$(ver_cut 1-2)
375 +QTMIN=5.15.2
376 +inherit ecm kde.org
377 +
378 +DESCRIPTION="Framework for converting units"
379 +LICENSE="LGPL-2+"
380 +KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~riscv ~x86"
381 +IUSE=""
382 +
383 +DEPEND="
384 + >=dev-qt/qtnetwork-${QTMIN}:5
385 + =kde-frameworks/ki18n-${PVCUT}*:5
386 +"
387 +RDEPEND="${DEPEND}"
388 +
389 +PATCHES=( # KDE-bug 441337
390 + "${FILESDIR}"/${P}-fix-24h-currency-sync.patch
391 + "${FILESDIR}"/${P}-fix-currency-values-init.patch
392 +)
393 +
394 +src_test() {
395 + # bug 623938 - needs internet connection
396 + local myctestargs=(
397 + -E "(convertertest)"
398 + )
399 +
400 + LC_NUMERIC="C" ecm_src_test # bug 694804
401 +}