build/windows: Port meson.build check of test-installer-langs.sh to Python

This commit is contained in:
Bruno Lopes 2025-04-22 14:33:06 -03:00
parent ae514268b5
commit 3e439868fa
No known key found for this signature in database
3 changed files with 24 additions and 36 deletions

View file

@ -11,31 +11,39 @@ MESON_SOURCE_ROOT = Path(os.environ.get("MESON_SOURCE_ROOT",sys.argv[2])).as_pos
## Get list of Inno and GIMP supported languages
po_inno_files = sorted(glob.glob(os.path.join(MESON_SOURCE_ROOT,'po-windows-installer/*.po')))
po_inno_array = [re.sub(r'^po-windows-installer/|\.po$', '', f) for f in po_inno_files]
po_inno_array = [os.path.splitext(os.path.basename(f))[0] for f in po_inno_files]
with open(os.path.join(MESON_SOURCE_ROOT,'build/windows/installer/lang/meson.build'), "r", encoding="utf-8") as meson_file:
meson_content = meson_file.read()
meson_langs = sorted(re.findall(r"'code': *'([^']*)'", meson_content))
meson_set = set(lang for lang in meson_langs if lang != "en")
po_files = sorted(glob.glob(os.path.join(MESON_SOURCE_ROOT,'po/*.po')))
po_array = [re.sub(r'^po/|\.po$', '', f) for f in po_files]
po_array = [os.path.splitext(os.path.basename(f))[0] for f in po_files]
## Get strings for GIMP and Inno supported languages
xml_file = os.path.join(MESON_SOURCE_ROOT, 'build/windows/installer/lang/iso_639_custom.xml')
tree = ET.parse(xml_file)
root = tree.getroot()
faultingmsg_list = ''
faultingmeson_list = ''
faultingcmp_list = ''
## Create list of lang [Languages]
if sys.argv[1] == 'msg':
msg_list = []
faultingmsg_list = ''
for po in po_inno_array:
# Change po
po = po.replace('\\', '').replace('//', '').replace('..', '').replace('po-windows-installer', '')
# Change isl
inno_code = None
for entry in root.findall('.//iso_639_entry'):
if entry.get('dl_code') == po:
inno_code = entry.get('inno_code').replace('\\\\', '\\')
break
# Check if everything is alright
if inno_code is None:
faultingmsg_list = faultingmsg_list + f"{po} "
if po not in meson_set:
faultingmeson_list = faultingmeson_list + f"{po} "
# Create line
if inno_code is not None:
msg_line = f'Name: "{po}"; MessagesFile: "compiler:{inno_code},{{#ASSETS_DIR}}\\lang\\{po}.setup.isl"'
@ -43,18 +51,19 @@ if sys.argv[1] == 'msg':
output_file = os.path.join(MESON_BUILD_ROOT, 'build/windows/installer/base_po-msg.list')
with open(output_file, 'w', encoding='utf-8') as f:
f.write('\n'.join(msg_list))
# If something is not right, explain why
if faultingmsg_list != '':
print("Error: languages listed in iso_639_custom.xml do not match the .po files in po-windows-installer/.")
print(f"- Faulting 'inno_code' on iso_639_custom.xml: {faultingmsg_list}")
sys.exit(1)
print("Error: languages listed in iso_639_custom.xml do not match the .po files in po-windows-installer/.")
print(f"- Faulting 'inno_code' on iso_639_custom.xml: {faultingmsg_list}")
if faultingmeson_list != '':
print("Error: languages listed in the build/windows/installer/lang/meson.build script do not match the .po files in po-windows-installer/.")
print(f"- Faulting 'code' on build/windows/installer/lang/meson.build: {faultingmeson_list}")
## Create list of lang [Components]
elif sys.argv[1] == 'cmp':
cmp_list = []
faultingcmp_list = ''
for po in po_array:
# Change po
po = po.replace('\\', '').replace('//', '').replace('..', '').replace('po', '')
po_clean = po.replace('@', '_')
# Change desc
desc = None
@ -62,6 +71,7 @@ elif sys.argv[1] == 'cmp':
if entry.get('dl_code') == po:
desc = entry.get('name')
break
# Check if everything is alright
if desc is None:
faultingcmp_list = faultingcmp_list + f"{po} "
# Create line
@ -71,17 +81,16 @@ elif sys.argv[1] == 'cmp':
output_file = os.path.join(MESON_BUILD_ROOT, 'build/windows/installer/base_po-cmp.list')
with open(output_file, 'w', encoding='utf-8') as f:
f.write('\n'.join(cmp_list))
# If something is not right, explain why
if faultingcmp_list != '':
print("Error: languages listed in iso_639_custom.xml do not match the .po files in po/.")
print(f"- Faulting 'dl_code' on iso_639_custom.xml: {faultingcmp_list}")
sys.exit(1)
## Create list of lang [Files]
elif sys.argv[1] == 'files':
files_list = []
for po in po_array:
# Change po
po = po.replace('\\', '').replace('//', '').replace('..', '').replace('po', '')
po_clean = po.replace('@', '_')
# Create line
files_line = f'Source: "{{#GIMP_DIR32}}\\share\\locale\\{po}\\*"; DestDir: "{{app}}\\share\\locale\\{po}"; Components: loc\\{po_clean}; Flags: recursesubdirs restartreplace uninsrestartdelete ignoreversion'
@ -89,3 +98,6 @@ elif sys.argv[1] == 'files':
output_file = os.path.join(MESON_BUILD_ROOT, 'build/windows/installer/base_po-files.list')
with open(output_file, 'w') as f:
f.write('\n'.join(files_list))
if faultingmsg_list != '' or faultingmeson_list != '' or faultingcmp_list != '':
sys.exit(1)

View file

@ -133,10 +133,3 @@ custom_target('base_po-files',
],
build_by_default: true,
)
test('windows-installer-langs',
find_program('test-installer-langs.sh'),
env: [
'GIMP_TESTING_ABS_TOP_SRCDIR=' + meson.project_source_root(),
],
suite: 'build')

View file

@ -1,17 +0,0 @@
#!/bin/sh
# Make sure that the languages specified in the installer match the
# translations present. This check step is necessary to not forget new
# installer translations because we have a manual step.
MESON_LANGS=`grep "'code':" ${GIMP_TESTING_ABS_TOP_SRCDIR}/build/windows/installer/lang/meson.build | \
sed "s/^.*'code': *'\([^']*\)'.*$/\1/" |sort`
MESON_LANGS=`echo "$MESON_LANGS" | tr '\n\r' ' ' | sed 's/\<en\> //'`
if [ "$PO_INSTALLER_LANGS" != "$MESON_LANGS" ]; then
echo "Error: languages listed in the meson script do not match the .po files in po-windows-installer/."
echo "- PO languages: $PO_INSTALLER_LANGS"
echo "- Meson languages: $MESON_LANGS"
echo "Please verify: build/windows/installer/lang/meson.build"
exit 1
fi