CMake: Fix test_operations
Fix test_operations and do some small mypy cleanups along the way Change-Id: I6586b5d3491e5dcf44252c098516f0922fa60420 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
140b65e36f
commit
5fe8a38af3
@ -367,6 +367,7 @@ def generate_find_package_info(lib: LibraryMapping, use_qt_find_package: bool=Tr
|
|||||||
extra.remove("REQUIRED")
|
extra.remove("REQUIRED")
|
||||||
|
|
||||||
cmake_target_name = lib.targetName
|
cmake_target_name = lib.targetName
|
||||||
|
assert(cmake_target_name);
|
||||||
|
|
||||||
# _nolink or not does not matter at this point:
|
# _nolink or not does not matter at this point:
|
||||||
if cmake_target_name.endswith('_nolink') or cmake_target_name.endswith('/nolink'):
|
if cmake_target_name.endswith('_nolink') or cmake_target_name.endswith('/nolink'):
|
||||||
|
@ -43,7 +43,8 @@ from sympy.logic import (simplify_logic, And, Or, Not,)
|
|||||||
import pyparsing as pp
|
import pyparsing as pp
|
||||||
|
|
||||||
from helper import map_qt_library, map_3rd_party_library, is_known_3rd_party_library, \
|
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 shutil import copyfile
|
||||||
from special_case_helper import SpecialCaseHandler
|
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:
|
class Operation:
|
||||||
def __init__(self, value):
|
def __init__(self, value: typing.List[str]):
|
||||||
if isinstance(value, list):
|
self._value = value
|
||||||
self._value = value
|
|
||||||
else:
|
|
||||||
self._value = [str(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)
|
assert(False)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -234,7 +233,8 @@ class Operation:
|
|||||||
|
|
||||||
|
|
||||||
class AddOperation(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)
|
return input + transformer(self._value)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -242,7 +242,8 @@ class AddOperation(Operation):
|
|||||||
|
|
||||||
|
|
||||||
class UniqueAddOperation(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
|
result = input
|
||||||
for v in transformer(self._value):
|
for v in transformer(self._value):
|
||||||
if v not in result:
|
if v not in result:
|
||||||
@ -254,10 +255,11 @@ class UniqueAddOperation(Operation):
|
|||||||
|
|
||||||
|
|
||||||
class SetOperation(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]
|
values = [] # typing.List[str]
|
||||||
for v in self._value:
|
for v in self._value:
|
||||||
if v != '$$' + key:
|
if v != '$${}'.format(key):
|
||||||
values.append(v)
|
values.append(v)
|
||||||
else:
|
else:
|
||||||
values += input
|
values += input
|
||||||
@ -275,7 +277,8 @@ class RemoveOperation(Operation):
|
|||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
super().__init__(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)
|
input_set = set(input)
|
||||||
value_set = set(self._value)
|
value_set = set(self._value)
|
||||||
result = []
|
result = []
|
||||||
@ -305,8 +308,8 @@ class Scope(object):
|
|||||||
file: typing.Optional[str] = None, condition: str = '',
|
file: typing.Optional[str] = None, condition: str = '',
|
||||||
base_dir: str = '',
|
base_dir: str = '',
|
||||||
operations: typing.Mapping[str, typing.List[Operation]] = {
|
operations: typing.Mapping[str, typing.List[Operation]] = {
|
||||||
'QT_SOURCE_TREE': [SetOperation('${PROJECT_SOURCE_DIR}')],
|
'QT_SOURCE_TREE': [SetOperation(['${PROJECT_SOURCE_DIR}'])],
|
||||||
'QT_BUILD_TREE': [SetOperation('${PROJECT_BUILD_DIR}')],
|
'QT_BUILD_TREE': [SetOperation(['${PROJECT_BUILD_DIR}'])],
|
||||||
}) -> None:
|
}) -> None:
|
||||||
if parent_scope:
|
if parent_scope:
|
||||||
parent_scope._add_child(self)
|
parent_scope._add_child(self)
|
||||||
|
@ -32,26 +32,26 @@ from pro2cmake import AddOperation, SetOperation, UniqueAddOperation, RemoveOper
|
|||||||
def test_add_operation():
|
def test_add_operation():
|
||||||
op = AddOperation(['bar', 'buz'])
|
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
|
assert ['foo', 'bar', 'bar', 'buz'] == result
|
||||||
|
|
||||||
|
|
||||||
def test_uniqueadd_operation():
|
def test_uniqueadd_operation():
|
||||||
op = UniqueAddOperation(['bar', 'buz'])
|
op = UniqueAddOperation(['bar', 'buz'])
|
||||||
|
|
||||||
result = op.process(['foo', 'bar'])
|
result = op.process(['foo', 'bar'], ['foo', 'bar'], lambda x: x)
|
||||||
assert ['foo', 'bar', 'buz'] == result
|
assert ['foo', 'bar', 'buz'] == result
|
||||||
|
|
||||||
|
|
||||||
def test_set_operation():
|
def test_set_operation():
|
||||||
op = SetOperation(['bar', 'buz'])
|
op = SetOperation(['bar', 'buz'])
|
||||||
|
|
||||||
result = op.process(['foo', 'bar'])
|
result = op.process(['foo', 'bar'], ['foo', 'bar'], lambda x: x)
|
||||||
assert ['bar', 'buz'] == result
|
assert ['bar', 'buz'] == result
|
||||||
|
|
||||||
|
|
||||||
def test_remove_operation():
|
def test_remove_operation():
|
||||||
op = RemoveOperation(['bar', 'buz'])
|
op = RemoveOperation(['bar', 'buz'])
|
||||||
|
|
||||||
result = op.process(['foo', 'bar'])
|
result = op.process(['foo', 'bar'], ['foo', 'bar'], lambda x: x)
|
||||||
assert ['foo', '-buz'] == result
|
assert ['foo', '-buz'] == result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user