From e6880b27dee9fa01841ad877c2b49e391708ce0a Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Wed, 24 Mar 2021 18:00:58 +0000 Subject: [PATCH] [#891]: Fix building the Arabic dictionary on windows. --- .gitignore | 1 + src/windows/data.vcxproj | 2 +- tests/windows-data.test | 76 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 tests/windows-data.test diff --git a/.gitignore b/.gitignore index 393fe665..8b33abb4 100644 --- a/.gitignore +++ b/.gitignore @@ -116,6 +116,7 @@ tests/*.check !tests/mbrola.test !tests/dictionary.test !tests/cmd_options.test +!tests/windows-data.test !tests/windows-installer.test espeak-ng.pc diff --git a/src/windows/data.vcxproj b/src/windows/data.vcxproj index 3580c8b1..31501581 100644 --- a/src/windows/data.vcxproj +++ b/src/windows/data.vcxproj @@ -325,5 +325,5 @@ - + diff --git a/tests/windows-data.test b/tests/windows-data.test new file mode 100644 index 00000000..27e2fdf2 --- /dev/null +++ b/tests/windows-data.test @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import sys +import os +import xml.etree.ElementTree as etree + +passed = True + +def check_result(check, message): + global passed + if check: + print('passed') + elif message: + print('failed: ' + message) + passed = False + else: + print('failed') + passed = False + +def check_missing(items, target): + missing = [] + for item in items: + if not item in target: + missing.append(item) + check_result(len(missing) == 0, ', '.join(missing)) + return missing + +def all_descendants(proj, name): + for e in proj.iter(): + if e.tag == '{http://schemas.microsoft.com/developer/msbuild/2003}' + name: + yield e + +def children(e, name): + for c in e: + if not isinstance(c, str): + if c.tag == '{http://schemas.microsoft.com/developer/msbuild/2003}' + name: + yield c + +def element_map(proj, name): + print('testing for duplicate \'' + name + '\' names ... ', end='') + items = {} + duplicates = [] + for e in all_descendants(proj, name): + id = e.attrib.get("Name") + if id in items.keys(): + duplicates.append(id) + else: + items[id] = e + check_result(len(duplicates) == 0 , ', '.join(duplicates)) + return items + +def list_dictionaries(): + for file in os.listdir('dictsource'): + if file.endswith('_rules'): + yield file.split('_')[0] + +# 1. Check for missing/duplicate names ################################################################################# + +proj = etree.parse('src/windows/data.vcxproj').getroot() +targets = element_map(proj, 'Target') + +# 2. Check for missing dictionaries #################################################################################### + +dictionaries = list(list_dictionaries()) +depends_on_dictionaries = targets['Dictionaries'].attrib.get('DependsOnTargets').split(';') + +print('testing for missing dictionary targets ... ', end='') +check_missing(depends_on_dictionaries, targets.keys()) + +print('testing for missing dependencies on dictionaries ... ', end='') +check_missing(set.intersection(set(dictionaries), set(targets.keys())), depends_on_dictionaries) + +######################################################################################################################## + +if not passed: + sys.exit(-1)