From 07a9052fcadd29e6e26c8d5c965598f1c71c8646 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 May 2019 12:41:35 +0200 Subject: [PATCH] [libcalamares] Also output size of locale-tables --- src/libcalamares/locale/cldr-extractor.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/locale/cldr-extractor.py b/src/libcalamares/locale/cldr-extractor.py index 06fb69e3b..4e279337b 100644 --- a/src/libcalamares/locale/cldr-extractor.py +++ b/src/libcalamares/locale/cldr-extractor.py @@ -251,7 +251,6 @@ def make_identifier(classname): else: identifier.append(c) - identifier.append("_table") return "".join(identifier) @@ -260,17 +259,27 @@ def export_class(cls, data): Given a @p cls and a list of @p data objects from that class, print (to stdout) a C++ file for that data. """ + identifier = make_identifier(cls.cpp_classname) + with open("{!s}_p.cpp".format(cls.cpp_classname), "wt", encoding="UTF-8") as f: f.write(cpp_header_comment) f.write(cls.cpp_declaration) - f.write("\nstatic const {!s} {!s}[] = {!s}\n".format( + f.write("\nstatic constexpr int const {!s}_size = {!s};\n".format( + identifier, + len(data))) + f.write("\nstatic const {!s} {!s}_table[] = {!s}\n".format( cls.cpp_classname, - make_identifier(cls.cpp_classname), + identifier, "{")) for d in data: f.write(str(d)) f.write("\n") f.write("};\n\n"); + f.write("static_assert( (sizeof({!s}_table) / sizeof({!s})) == {!s}_size, \"Table size mismatch for {!s}\" );\n\n".format( + identifier, + cls.cpp_classname, + identifier, + cls.cpp_classname)) f.write(cpp_footer_comment)