From 5fe8a38af34d1530f14c3b695dee5a33e4a85554 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 17 May 2019 15:05:49 +0200 Subject: CMake: Fix test_operations Fix test_operations and do some small mypy cleanups along the way Change-Id: I6586b5d3491e5dcf44252c098516f0922fa60420 Reviewed-by: Alexandru Croitor --- util/cmake/helper.py | 1 + util/cmake/pro2cmake.py | 31 +++++++++++++++++-------------- util/cmake/tests/test_operations.py | 8 ++++---- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/util/cmake/helper.py b/util/cmake/helper.py index 99d9242eba..ee4274abd7 100644 --- a/util/cmake/helper.py +++ b/util/cmake/helper.py @@ -367,6 +367,7 @@ def generate_find_package_info(lib: LibraryMapping, use_qt_find_package: bool=Tr extra.remove("REQUIRED") cmake_target_name = lib.targetName + assert(cmake_target_name); # _nolink or not does not matter at this point: if cmake_target_name.endswith('_nolink') or cmake_target_name.endswith('/nolink'): diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 0851181a25..5b6b3847d8 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -43,7 +43,8 @@ from sympy.logic import (simplify_logic, And, Or, Not,) import pyparsing as pp from helper import map_qt_library, map_3rd_party_library, is_known_3rd_party_library, \ - featureName, map_platform, find_library_info_for_target, generate_find_package_info + featureName, map_platform, find_library_info_for_target, generate_find_package_info, \ + LibraryMapping from shutil import copyfile from special_case_helper import SpecialCaseHandler @@ -205,13 +206,11 @@ def handle_vpath(source: str, base_dir: str, vpath: typing.List[str]) -> str: class Operation: - def __init__(self, value): - if isinstance(value, list): - self._value = value - else: - self._value = [str(value), ] + def __init__(self, value: typing.List[str]): + self._value = value - def process(self, key, input, transformer): + def process(self, key: str, input: typing.List[str], + transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]: assert(False) def __repr__(self): @@ -234,7 +233,8 @@ class Operation: class AddOperation(Operation): - def process(self, key, input, transformer): + def process(self, key: str, input: typing.List[str], + transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]: return input + transformer(self._value) def __repr__(self): @@ -242,7 +242,8 @@ class AddOperation(Operation): class UniqueAddOperation(Operation): - def process(self, key, input, transformer): + def process(self, key: str, input: typing.List[str], + transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]: result = input for v in transformer(self._value): if v not in result: @@ -254,10 +255,11 @@ class UniqueAddOperation(Operation): class SetOperation(Operation): - def process(self, key, input, transformer): + def process(self, key: str, input: typing.List[str], + transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]: values = [] # typing.List[str] for v in self._value: - if v != '$$' + key: + if v != '$${}'.format(key): values.append(v) else: values += input @@ -275,7 +277,8 @@ class RemoveOperation(Operation): def __init__(self, value): super().__init__(value) - def process(self, key, input, transformer): + def process(self, key: str, input: typing.List[str], + transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]: input_set = set(input) value_set = set(self._value) result = [] @@ -305,8 +308,8 @@ class Scope(object): file: typing.Optional[str] = None, condition: str = '', base_dir: str = '', operations: typing.Mapping[str, typing.List[Operation]] = { - 'QT_SOURCE_TREE': [SetOperation('${PROJECT_SOURCE_DIR}')], - 'QT_BUILD_TREE': [SetOperation('${PROJECT_BUILD_DIR}')], + 'QT_SOURCE_TREE': [SetOperation(['${PROJECT_SOURCE_DIR}'])], + 'QT_BUILD_TREE': [SetOperation(['${PROJECT_BUILD_DIR}'])], }) -> None: if parent_scope: parent_scope._add_child(self) diff --git a/util/cmake/tests/test_operations.py b/util/cmake/tests/test_operations.py index 3ea2f76a43..c1e5f1b250 100755 --- a/util/cmake/tests/test_operations.py +++ b/util/cmake/tests/test_operations.py @@ -32,26 +32,26 @@ from pro2cmake import AddOperation, SetOperation, UniqueAddOperation, RemoveOper def test_add_operation(): op = AddOperation(['bar', 'buz']) - result = op.process(['foo', 'bar']) + result = op.process(['foo', 'bar'], ['foo', 'bar'], lambda x: x) assert ['foo', 'bar', 'bar', 'buz'] == result def test_uniqueadd_operation(): op = UniqueAddOperation(['bar', 'buz']) - result = op.process(['foo', 'bar']) + result = op.process(['foo', 'bar'], ['foo', 'bar'], lambda x: x) assert ['foo', 'bar', 'buz'] == result def test_set_operation(): op = SetOperation(['bar', 'buz']) - result = op.process(['foo', 'bar']) + result = op.process(['foo', 'bar'], ['foo', 'bar'], lambda x: x) assert ['bar', 'buz'] == result def test_remove_operation(): op = RemoveOperation(['bar', 'buz']) - result = op.process(['foo', 'bar']) + result = op.process(['foo', 'bar'], ['foo', 'bar'], lambda x: x) assert ['foo', '-buz'] == result -- cgit v1.2.3