summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <[email protected]>2024-06-03 17:29:47 +0200
committerEdward Welbourne <[email protected]>2024-06-11 15:43:04 +0200
commita9446b1c3b5e077c0321b9a7b59305b14d699d92 (patch)
treed3d6d91b8a602e05209601b94c2a7a3023f522a9
parent97f50aee9deedd6461d7609faa41edf0e7c27ac0 (diff)
QLocaleXml: include Qt version in the localeDatabase tag
Also move the CLDR version into the tag. The version numbers are plain ASCII, with no special characters, so can safely be attributes. In the process, fix a mistake in __openTag()'s handling of attributes; join with plain space, no comma. Having the Qt version in the XML makes it possible to assert compatibility between the Qt version that generated it and the one that's consuming it. Change-Id: I6fa6b668b072ff3616955d81af2cffaba5b67250 Reviewed-by: Mate Barany <[email protected]>
-rwxr-xr-xutil/locale_database/cldr2qlocalexml.py3
-rw-r--r--util/locale_database/localetools.py16
-rw-r--r--util/locale_database/qlocalexml.py52
-rw-r--r--util/locale_database/qlocalexml.rnc3
4 files changed, 47 insertions, 27 deletions
diff --git a/util/locale_database/cldr2qlocalexml.py b/util/locale_database/cldr2qlocalexml.py
index 374e42bf661..f13a77c601c 100755
--- a/util/locale_database/cldr2qlocalexml.py
+++ b/util/locale_database/cldr2qlocalexml.py
@@ -91,9 +91,8 @@ def main(argv, out, err):
# Use stderr for logging if stdout is where our XML is going:
err.write if out is emit else out.write,
err.write)
- writer = QLocaleXmlWriter(emit.write)
+ writer = QLocaleXmlWriter(reader.root.cldrVersion, emit.write)
- writer.version(reader.root.cldrVersion)
writer.enumData(reader.root.englishNaming)
writer.likelySubTags(reader.likelySubTags())
writer.zoneData(*reader.zoneData()) # Locale-independent zone data.
diff --git a/util/locale_database/localetools.py b/util/locale_database/localetools.py
index 02ec7cafc7a..a7fcd087273 100644
--- a/util/locale_database/localetools.py
+++ b/util/locale_database/localetools.py
@@ -26,6 +26,22 @@ class Error (Exception):
def __str__(self):
return self.message
+def qtVersion(root = qtbase_root, pfx = 'set(QT_REPO_MODULE_VERSION '):
+ with open(root.joinpath('.cmake.conf')) as fd:
+ for line in fd:
+ if line.startswith(pfx):
+ tail = line[len(pfx):].strip()
+ assert tail, ('No Qt version given', line)
+ if tail.startswith('"') or tail.startswith("'"):
+ cut = tail.index(tail[0], 1) # assert: doesn't ValueError
+ assert cut > 5, ('Truncated Qt version', tail)
+ version = tail[1:cut].strip()
+ assert all(x.isdigit() for x in version.split('.')), version
+ return version
+ raise Error(f'Missing quotes on Qt version: {tail}')
+ raise Error(f'Failed to find {pfx}...) line in {root.joinpath(".cmake.conf")}')
+qtVersion = qtVersion()
+
def unicode2hex(s):
lst = []
for x in s:
diff --git a/util/locale_database/qlocalexml.py b/util/locale_database/qlocalexml.py
index dae1894cd23..b33876775ad 100644
--- a/util/locale_database/qlocalexml.py
+++ b/util/locale_database/qlocalexml.py
@@ -21,7 +21,7 @@ package manager lacks the jing package.
from xml.sax.saxutils import escape
-from localetools import Error
+from localetools import Error, qtVersion
# Tools used by Locale:
def camel(seq):
@@ -66,7 +66,13 @@ class QLocaleXmlReader (object):
self.__landByName = {v[1]: (v[0], v[2]) for v in territories}
# Other properties:
self.__dupes = set(v[1] for v in languages) & set(v[1] for v in territories)
- self.cldrVersion = self.__firstChildText(self.root, "version")
+
+ self.cldrVersion = self.root.attributes['versionCldr'].nodeValue
+ self.qtVersion = self.root.attributes['versionQt'].nodeValue
+ assert self.qtVersion == qtVersion, (
+ 'Using QLocaleXml file from incompatible Qt version',
+ self.qtVersion, qtVersion
+ )
def loadLocaleMap(self, calendars, grumble = lambda text: None):
kid = self.__firstChildText
@@ -290,27 +296,28 @@ class QLocaleXmlWriter (object):
The output saved by this should conform to qlocalexml.rnc's
schema."""
- def __init__(self, save = None, space = Spacer(4)):
+ def __init__(self, cldrVersion, save = None, space = Spacer(4)):
"""Set up to write digested CLDR data as QLocale XML.
- Arguments are both optional.
-
- First argument, save, is None (its default) or a callable that
- will write content to where you intend to save it. If None, it
- is replaced with a callable that prints the given content,
- suppressing the newline (but see the following); this is
- equivalent to passing sys.stdout.write.
-
- Second argument, space, is an object to call on each text
- output to prepend indentation and append newlines, or not as
- the case may be. The default is a Spacer(4), which grows
- indent by four spaces after each unmatched new tag and shrinks
- back on a close-tag (its parsing is naive, but adequate to how
- this class uses it), while adding a newline to each line.
- """
+ First argument is the version of CLDR whose data we'll be
+ writing. Other arguments are optional.
+
+ Second argument, save, is None (its default) or a callable that will
+ write content to where you intend to save it. If None, it is replaced
+ with a callable that prints the given content, suppressing the newline
+ (but see the following); this is equivalent to passing
+ sys.stdout.write.
+
+ Third argument, space, is an object to call on each text output to
+ prepend indentation and append newlines, or not as the case may be. The
+ default is a Spacer(4), which grows indent by four spaces after each
+ unmatched new tag and shrinks back on a close-tag (its parsing is
+ naive, but adequate to how this class uses it), while adding a newline
+ to each line."""
self.__rawOutput = self.__printit if save is None else save
self.__wrap = space
- self.__write('<localeDatabase>')
+ self.__openTag('localeDatabase', versionCldr = cldrVersion,
+ versionQt = qtVersion)
# Output of various sections, in their usual order:
def enumData(self, code2name):
@@ -394,16 +401,13 @@ class QLocaleXmlWriter (object):
self.__closeTag('locale')
self.__closeTag('localeList')
- def version(self, cldrVersion):
- self.inTag('version', cldrVersion)
-
def inTag(self, tag, text):
self.__write(f'<{tag}>{text}</{tag}>')
def close(self, grumble):
"""Finish writing and grumble about any issues discovered."""
if self.__rawOutput != self.__complain:
- self.__write('</localeDatabase>')
+ self.__closeTag('localeDatabase')
self.__rawOutput = self.__complain
if self.__languages or self.__scripts or self.__territories:
@@ -458,7 +462,7 @@ class QLocaleXmlWriter (object):
def __openTag(self, tag, **attrs):
if attrs:
- text = ', '.join(f'{k}="{v}"' for k, v in attrs.items())
+ text = ' '.join(f'{k}="{v}"' for k, v in attrs.items())
tag = f'{tag} {text}'
self.__write(f'<{tag}>')
def __closeTag(self, tag):
diff --git a/util/locale_database/qlocalexml.rnc b/util/locale_database/qlocalexml.rnc
index f8efe9204f9..0a2aa28f6b1 100644
--- a/util/locale_database/qlocalexml.rnc
+++ b/util/locale_database/qlocalexml.rnc
@@ -11,7 +11,8 @@
# package manager lacks the jing package.
start = element localeDatabase {
- element version { text },
+ attribute versionCldr { text },
+ attribute versionQt { text },
element languageList { Language+ },
element scriptList { Script+ },
element territoryList { Territory+ },