CMake: pro2cmake.py: Fix pyls warnings
Fix pyls warnings in pro2cmake.py as well as its tests. Change-Id: Ib8ee1daa9b97735d13c0fde43616daa46de9e171 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
e2ff9e3b99
commit
1c1bb53c55
@ -154,6 +154,7 @@ class Operation:
|
|||||||
result.append(str(i))
|
result.append(str(i))
|
||||||
return '"' + '", "'.join(result) + '"'
|
return '"' + '", "'.join(result) + '"'
|
||||||
|
|
||||||
|
|
||||||
class AddOperation(Operation):
|
class AddOperation(Operation):
|
||||||
def process(self, input):
|
def process(self, input):
|
||||||
return input + self._value
|
return input + self._value
|
||||||
@ -346,7 +347,8 @@ class Scope:
|
|||||||
print('{} -- NONE --'.format(ind))
|
print('{} -- NONE --'.format(ind))
|
||||||
else:
|
else:
|
||||||
for k in sorted(keys):
|
for k in sorted(keys):
|
||||||
print('{} {} = "{}"'.format(ind, k, self._operations.get(k, [])))
|
print('{} {} = "{}"'
|
||||||
|
.format(ind, k, self._operations.get(k, [])))
|
||||||
print('{} Children:'.format(ind))
|
print('{} Children:'.format(ind))
|
||||||
if not self._children:
|
if not self._children:
|
||||||
print('{} -- NONE --'.format(ind))
|
print('{} -- NONE --'.format(ind))
|
||||||
@ -358,7 +360,7 @@ class Scope:
|
|||||||
return self._operations.keys()
|
return self._operations.keys()
|
||||||
|
|
||||||
def visited_keys(self):
|
def visited_keys(self):
|
||||||
return self._visited_keys;
|
return self._visited_keys
|
||||||
|
|
||||||
def get(self, key: str, default=None) -> typing.List[str]:
|
def get(self, key: str, default=None) -> typing.List[str]:
|
||||||
self._visited_keys.add(key)
|
self._visited_keys.add(key)
|
||||||
@ -404,13 +406,13 @@ class QmakeParser:
|
|||||||
Substitution \
|
Substitution \
|
||||||
= pp.Combine(pp.Literal('$')
|
= pp.Combine(pp.Literal('$')
|
||||||
+ (((pp.Literal('$') + Identifier
|
+ (((pp.Literal('$') + Identifier
|
||||||
+ pp.Optional(pp.nestedExpr()))
|
+ pp.Optional(pp.nestedExpr()))
|
||||||
| (pp.Literal('(') + Identifier + pp.Literal(')'))
|
| (pp.Literal('(') + Identifier + pp.Literal(')'))
|
||||||
| (pp.Literal('{') + Identifier + pp.Literal('}'))
|
| (pp.Literal('{') + Identifier + pp.Literal('}'))
|
||||||
| (pp.Literal('$') + pp.Literal('{')
|
| (pp.Literal('$') + pp.Literal('{')
|
||||||
+ Identifier + pp.Optional(pp.nestedExpr())
|
+ Identifier + pp.Optional(pp.nestedExpr())
|
||||||
+ pp.Literal('}'))
|
+ pp.Literal('}'))
|
||||||
| (pp.Literal('$') + pp.Literal('[') + Identifier
|
| (pp.Literal('$') + pp.Literal('[') + Identifier
|
||||||
+ pp.Literal(']'))
|
+ pp.Literal(']'))
|
||||||
)))
|
)))
|
||||||
# Do not match word ending in '\' since that breaks line
|
# Do not match word ending in '\' since that breaks line
|
||||||
@ -612,9 +614,10 @@ def write_scope_header(cm_fh: typing.IO[str], *, indent: int = 0):
|
|||||||
|
|
||||||
|
|
||||||
def write_sources_section(cm_fh: typing.IO[str], scope: Scope, *,
|
def write_sources_section(cm_fh: typing.IO[str], scope: Scope, *,
|
||||||
indent: int = 0, known_libraries=set()) -> typing.Set[str]:
|
indent: int = 0, known_libraries=set()) \
|
||||||
|
-> typing.Set[str]:
|
||||||
ind = spaces(indent)
|
ind = spaces(indent)
|
||||||
scope.reset_visited_keys();
|
scope.reset_visited_keys()
|
||||||
|
|
||||||
plugin_type = scope.get('PLUGIN_TYPE')
|
plugin_type = scope.get('PLUGIN_TYPE')
|
||||||
|
|
||||||
@ -688,17 +691,19 @@ def write_sources_section(cm_fh: typing.IO[str], scope: Scope, *,
|
|||||||
|
|
||||||
|
|
||||||
def is_simple_condition(condition: str) -> bool:
|
def is_simple_condition(condition: str) -> bool:
|
||||||
return ' ' not in condition or (condition.startswith('NOT ') and ' ' not in condition[4:])
|
return ' ' not in condition \
|
||||||
|
or (condition.startswith('NOT ') and ' ' not in condition[4:])
|
||||||
|
|
||||||
|
|
||||||
def write_ignored_keys(scope: Scope, ignored_keys, indent) -> str:
|
def write_ignored_keys(scope: Scope, ignored_keys, indent) -> str:
|
||||||
result = ''
|
result = ''
|
||||||
for k in sorted(ignored_keys):
|
for k in sorted(ignored_keys):
|
||||||
if k == '_INCLUDED' or k == 'TARGET' or k == 'QMAKE_DOCS':
|
if k == '_INCLUDED' or k == 'TARGET' or k == 'QMAKE_DOCS':
|
||||||
# All these keys are actually reported using "non-standard" means:-)
|
# All these keys are actually reported already
|
||||||
continue
|
continue
|
||||||
values = scope.get(k)
|
values = scope.get(k)
|
||||||
value_string = '<EMPTY>' if not values else '"' + '" "'.join(scope.get(k)) + '"'
|
value_string = '<EMPTY>' if not values \
|
||||||
|
else '"' + '" "'.join(scope.get(k)) + '"'
|
||||||
result += '{}# {} = {}\n'.format(indent, k, value_string)
|
result += '{}# {} = {}\n'.format(indent, k, value_string)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -721,27 +726,32 @@ def write_extend_target(cm_fh: typing.IO[str], target: str,
|
|||||||
if not total_condition:
|
if not total_condition:
|
||||||
total_condition = parent_condition
|
total_condition = parent_condition
|
||||||
else:
|
else:
|
||||||
if is_simple_condition(parent_condition) and is_simple_condition(total_condition):
|
if is_simple_condition(parent_condition) \
|
||||||
|
and is_simple_condition(total_condition):
|
||||||
total_condition = '{} AND {}'.format(parent_condition,
|
total_condition = '{} AND {}'.format(parent_condition,
|
||||||
total_condition)
|
total_condition)
|
||||||
elif is_simple_condition(total_condition):
|
elif is_simple_condition(total_condition):
|
||||||
total_condition = '({}) AND {}'.format(parent_condition, total_condition)
|
total_condition = '({}) AND {}'.format(parent_condition,
|
||||||
|
total_condition)
|
||||||
elif is_simple_condition(parent_condition):
|
elif is_simple_condition(parent_condition):
|
||||||
total_condition = '{} AND ({})'.format(parent_condition, total_condition)
|
total_condition = '{} AND ({})'.format(parent_condition,
|
||||||
|
total_condition)
|
||||||
else:
|
else:
|
||||||
total_condition = '({}) AND ({})'.format(parent_condition, total_condition)
|
total_condition = '({}) AND ({})'.format(parent_condition,
|
||||||
|
total_condition)
|
||||||
|
|
||||||
extend_qt_io_string = io.StringIO()
|
extend_qt_io_string = io.StringIO()
|
||||||
ignored_keys = write_sources_section(extend_qt_io_string, scope)
|
ignored_keys = write_sources_section(extend_qt_io_string, scope)
|
||||||
extend_qt_string = extend_qt_io_string.getvalue()
|
extend_qt_string = extend_qt_io_string.getvalue()
|
||||||
|
|
||||||
ignored_keys_report = write_ignored_keys(scope, ignored_keys, spaces(indent + 1))
|
ignored_keys_report = write_ignored_keys(scope, ignored_keys,
|
||||||
|
spaces(indent + 1))
|
||||||
if extend_qt_string and ignored_keys_report:
|
if extend_qt_string and ignored_keys_report:
|
||||||
ignored_keys_report = '\n' + ignored_keys_report
|
ignored_keys_report = '\n' + ignored_keys_report
|
||||||
|
|
||||||
extend_scope = '\n{}extend_target({} CONDITION {}\n' \
|
extend_scope = '\n{}extend_target({} CONDITION {}\n' \
|
||||||
'{}{})\n'.format(spaces(indent), target, total_condition,
|
'{}{})\n'.format(spaces(indent), target, total_condition,
|
||||||
extend_qt_string, ignored_keys_report)
|
extend_qt_string, ignored_keys_report)
|
||||||
|
|
||||||
if not extend_qt_string:
|
if not extend_qt_string:
|
||||||
if ignored_keys_report:
|
if ignored_keys_report:
|
||||||
@ -778,7 +788,8 @@ def write_main_part(cm_fh: typing.IO[str], name: str, typename: str,
|
|||||||
cm_fh.write('{} {}\n'.format(spaces(indent), extra_line))
|
cm_fh.write('{} {}\n'.format(spaces(indent), extra_line))
|
||||||
|
|
||||||
ignored_keys = write_sources_section(cm_fh, scope, indent=indent, **kwargs)
|
ignored_keys = write_sources_section(cm_fh, scope, indent=indent, **kwargs)
|
||||||
ignored_keys_report = write_ignored_keys(scope, ignored_keys, spaces(indent + 1))
|
ignored_keys_report = write_ignored_keys(scope, ignored_keys,
|
||||||
|
spaces(indent + 1))
|
||||||
if ignored_keys_report:
|
if ignored_keys_report:
|
||||||
cm_fh.write(ignored_keys_report)
|
cm_fh.write(ignored_keys_report)
|
||||||
|
|
||||||
@ -912,7 +923,8 @@ def do_include(scope: Scope, *, debug: bool = False) -> None:
|
|||||||
if not include_file:
|
if not include_file:
|
||||||
continue
|
continue
|
||||||
if '/3rdparty/' in include_file:
|
if '/3rdparty/' in include_file:
|
||||||
print(' ****: Ignoring include file in 3rdparty: {}.'.format(include_file))
|
print(' ****: Ignoring include file in 3rdparty: {}.'
|
||||||
|
.format(include_file))
|
||||||
continue
|
continue
|
||||||
if not os.path.isfile(include_file):
|
if not os.path.isfile(include_file):
|
||||||
print(' XXXX: Failed to include {}.'.format(include_file))
|
print(' XXXX: Failed to include {}.'.format(include_file))
|
||||||
@ -922,7 +934,7 @@ def do_include(scope: Scope, *, debug: bool = False) -> None:
|
|||||||
include_scope \
|
include_scope \
|
||||||
= Scope.FromDict(None, include_file,
|
= Scope.FromDict(None, include_file,
|
||||||
include_result.asDict().get('statements'),
|
include_result.asDict().get('statements'),
|
||||||
'', dir) # This scope will be merged into scope, so no parent_scope!
|
'', dir) # This scope will be merged into scope!
|
||||||
|
|
||||||
do_include(include_scope)
|
do_include(include_scope)
|
||||||
|
|
||||||
|
@ -49,7 +49,9 @@ def evaluate_condition(to_validate):
|
|||||||
assert 'condition' in to_validate
|
assert 'condition' in to_validate
|
||||||
assert 'statements' in to_validate
|
assert 'statements' in to_validate
|
||||||
|
|
||||||
return (to_validate['condition'], to_validate['statements'], to_validate.get('else_statements', {}))
|
return (to_validate['condition'],
|
||||||
|
to_validate['statements'],
|
||||||
|
to_validate.get('else_statements', {}))
|
||||||
|
|
||||||
|
|
||||||
def validate_default_else_test(file_name):
|
def validate_default_else_test(file_name):
|
||||||
@ -105,22 +107,28 @@ def test_else2():
|
|||||||
def test_else3():
|
def test_else3():
|
||||||
validate_default_else_test(_tests_path + '/data/else3.pro')
|
validate_default_else_test(_tests_path + '/data/else3.pro')
|
||||||
|
|
||||||
|
|
||||||
def test_else4():
|
def test_else4():
|
||||||
validate_default_else_test(_tests_path + '/data/else4.pro')
|
validate_default_else_test(_tests_path + '/data/else4.pro')
|
||||||
|
|
||||||
|
|
||||||
def test_else5():
|
def test_else5():
|
||||||
validate_default_else_test(_tests_path + '/data/else5.pro')
|
validate_default_else_test(_tests_path + '/data/else5.pro')
|
||||||
|
|
||||||
|
|
||||||
def test_else6():
|
def test_else6():
|
||||||
validate_default_else_test(_tests_path + '/data/else6.pro')
|
validate_default_else_test(_tests_path + '/data/else6.pro')
|
||||||
|
|
||||||
|
|
||||||
def test_else7():
|
def test_else7():
|
||||||
result = parse_file(_tests_path + '/data/else7.pro')
|
result = parse_file(_tests_path + '/data/else7.pro')
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_else8():
|
def test_else8():
|
||||||
validate_default_else_test(_tests_path + '/data/else8.pro')
|
validate_default_else_test(_tests_path + '/data/else8.pro')
|
||||||
|
|
||||||
|
|
||||||
def test_include():
|
def test_include():
|
||||||
result = parse_file(_tests_path + '/data/include.pro')
|
result = parse_file(_tests_path + '/data/include.pro')
|
||||||
assert len(result) == 3
|
assert len(result) == 3
|
||||||
@ -130,6 +138,7 @@ def test_include():
|
|||||||
assert include.get('included', '') == 'foo'
|
assert include.get('included', '') == 'foo'
|
||||||
validate_op('B', '=', ['23'], result[2])
|
validate_op('B', '=', ['23'], result[2])
|
||||||
|
|
||||||
|
|
||||||
def test_load():
|
def test_load():
|
||||||
result = parse_file(_tests_path + '/data/load.pro')
|
result = parse_file(_tests_path + '/data/load.pro')
|
||||||
assert len(result) == 3
|
assert len(result) == 3
|
||||||
@ -139,24 +148,29 @@ def test_load():
|
|||||||
assert load.get('loaded', '') == 'foo'
|
assert load.get('loaded', '') == 'foo'
|
||||||
validate_op('B', '=', ['23'], result[2])
|
validate_op('B', '=', ['23'], result[2])
|
||||||
|
|
||||||
|
|
||||||
def test_definetest():
|
def test_definetest():
|
||||||
result = parse_file(_tests_path + '/data/definetest.pro')
|
result = parse_file(_tests_path + '/data/definetest.pro')
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
assert result[0] == []
|
assert result[0] == []
|
||||||
|
|
||||||
|
|
||||||
def test_unset():
|
def test_unset():
|
||||||
result = parse_file(_tests_path + '/data/unset.pro')
|
result = parse_file(_tests_path + '/data/unset.pro')
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
assert result[0] == []
|
assert result[0] == []
|
||||||
|
|
||||||
|
|
||||||
def test_quoted():
|
def test_quoted():
|
||||||
result = parse_file(_tests_path + '/data/quoted.pro')
|
result = parse_file(_tests_path + '/data/quoted.pro')
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_complex_values():
|
def test_complex_values():
|
||||||
result = parse_file(_tests_path + '/data/complex_values.pro')
|
result = parse_file(_tests_path + '/data/complex_values.pro')
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_function_if():
|
def test_function_if():
|
||||||
result = parse_file(_tests_path + '/data/function_if.pro')
|
result = parse_file(_tests_path + '/data/function_if.pro')
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user