diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index ff814efcf2..b87b20a8c2 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -154,6 +154,7 @@ class Operation: result.append(str(i)) return '"' + '", "'.join(result) + '"' + class AddOperation(Operation): def process(self, input): return input + self._value @@ -346,7 +347,8 @@ class Scope: print('{} -- NONE --'.format(ind)) else: 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)) if not self._children: print('{} -- NONE --'.format(ind)) @@ -358,7 +360,7 @@ class Scope: return self._operations.keys() def visited_keys(self): - return self._visited_keys; + return self._visited_keys def get(self, key: str, default=None) -> typing.List[str]: self._visited_keys.add(key) @@ -404,13 +406,13 @@ class QmakeParser: Substitution \ = pp.Combine(pp.Literal('$') + (((pp.Literal('$') + Identifier - + pp.Optional(pp.nestedExpr())) - | (pp.Literal('(') + Identifier + pp.Literal(')')) - | (pp.Literal('{') + Identifier + pp.Literal('}')) - | (pp.Literal('$') + pp.Literal('{') + + pp.Optional(pp.nestedExpr())) + | (pp.Literal('(') + Identifier + pp.Literal(')')) + | (pp.Literal('{') + Identifier + pp.Literal('}')) + | (pp.Literal('$') + pp.Literal('{') + Identifier + pp.Optional(pp.nestedExpr()) + pp.Literal('}')) - | (pp.Literal('$') + pp.Literal('[') + Identifier + | (pp.Literal('$') + pp.Literal('[') + Identifier + pp.Literal(']')) ))) # 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, *, - indent: int = 0, known_libraries=set()) -> typing.Set[str]: + indent: int = 0, known_libraries=set()) \ + -> typing.Set[str]: ind = spaces(indent) - scope.reset_visited_keys(); + scope.reset_visited_keys() 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: - 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: result = '' for k in sorted(ignored_keys): 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 values = scope.get(k) - value_string = '' if not values else '"' + '" "'.join(scope.get(k)) + '"' + value_string = '' if not values \ + else '"' + '" "'.join(scope.get(k)) + '"' result += '{}# {} = {}\n'.format(indent, k, value_string) return result @@ -721,27 +726,32 @@ def write_extend_target(cm_fh: typing.IO[str], target: str, if not total_condition: total_condition = parent_condition 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) 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): - total_condition = '{} AND ({})'.format(parent_condition, total_condition) + total_condition = '{} AND ({})'.format(parent_condition, + total_condition) else: - total_condition = '({}) AND ({})'.format(parent_condition, total_condition) + total_condition = '({}) AND ({})'.format(parent_condition, + total_condition) extend_qt_io_string = io.StringIO() ignored_keys = write_sources_section(extend_qt_io_string, scope) 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: ignored_keys_report = '\n' + ignored_keys_report extend_scope = '\n{}extend_target({} CONDITION {}\n' \ '{}{})\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 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)) 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: cm_fh.write(ignored_keys_report) @@ -912,7 +923,8 @@ def do_include(scope: Scope, *, debug: bool = False) -> None: if not include_file: continue if '/3rdparty/' in include_file: - print(' ****: Ignoring include file in 3rdparty: {}.'.format(include_file)) + print(' ****: Ignoring include file in 3rdparty: {}.' + .format(include_file)) continue if not os.path.isfile(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 \ = Scope.FromDict(None, include_file, 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) diff --git a/util/cmake/tests/test_parsing.py b/util/cmake/tests/test_parsing.py index 78ac7fed26..0802fe4742 100755 --- a/util/cmake/tests/test_parsing.py +++ b/util/cmake/tests/test_parsing.py @@ -49,7 +49,9 @@ def evaluate_condition(to_validate): assert 'condition' 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): @@ -105,22 +107,28 @@ def test_else2(): def test_else3(): validate_default_else_test(_tests_path + '/data/else3.pro') + def test_else4(): validate_default_else_test(_tests_path + '/data/else4.pro') + def test_else5(): validate_default_else_test(_tests_path + '/data/else5.pro') + def test_else6(): validate_default_else_test(_tests_path + '/data/else6.pro') + def test_else7(): result = parse_file(_tests_path + '/data/else7.pro') assert len(result) == 1 + def test_else8(): validate_default_else_test(_tests_path + '/data/else8.pro') + def test_include(): result = parse_file(_tests_path + '/data/include.pro') assert len(result) == 3 @@ -130,6 +138,7 @@ def test_include(): assert include.get('included', '') == 'foo' validate_op('B', '=', ['23'], result[2]) + def test_load(): result = parse_file(_tests_path + '/data/load.pro') assert len(result) == 3 @@ -139,24 +148,29 @@ def test_load(): assert load.get('loaded', '') == 'foo' validate_op('B', '=', ['23'], result[2]) + def test_definetest(): result = parse_file(_tests_path + '/data/definetest.pro') assert len(result) == 1 assert result[0] == [] + def test_unset(): result = parse_file(_tests_path + '/data/unset.pro') assert len(result) == 1 assert result[0] == [] + def test_quoted(): result = parse_file(_tests_path + '/data/quoted.pro') assert len(result) == 1 + def test_complex_values(): result = parse_file(_tests_path + '/data/complex_values.pro') assert len(result) == 1 + def test_function_if(): result = parse_file(_tests_path + '/data/function_if.pro') assert len(result) == 1