diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-01-31 14:26:06 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-02-11 09:35:29 +0000 |
commit | 64e3c8bb190b95ab4da581dc5667864d8f4a176c (patch) | |
tree | 42bc397b963c0d26fbe1f2839729258cce2f25df /util/cmake | |
parent | 73f5036be58c52ab0c8a101e5e34ea6de12b9a29 (diff) |
CMake: pro2cmake: Fix handling of chained scopes with else branches
Fix handling of things like:
foo:bar:buz: {
do something
} else: wat {
do something else
}
The else relates to foo AND bar AND buz, not just to buz in this case.
Change-Id: I40d1fa295b4d6dd95ae5e1ce2d58372edc807b86
Reviewed-by: Albert Astals Cid <albert.astals.cid@kdab.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'util/cmake')
-rwxr-xr-x | util/cmake/pro2cmake.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 4f4303e3d1..891e42003a 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -288,6 +288,31 @@ class Scope(object): def currentdir(self) -> str: return self._currentdir + def can_merge_condition(self): + if self._condition == 'else': + return False + if self._operations: + return False + + child_count = len(self._children) + if child_count == 0 or child_count > 2: + return False + assert child_count != 1 or self._children[0]._condition != 'else' + return child_count == 1 or self._children[1]._condition == 'else' + + def settle_condition(self): + new_children: typing.List[scope] = [] + for c in self._children: + c.settle_condition() + + if c.can_merge_condition(): + child = c._children[0] + child._condition = '({}) AND ({})'.format(c._condition, child._condition) + new_children += c._children + else: + new_children.append(c) + self._children = new_children + @staticmethod def FromDict(parent_scope: typing.Optional['Scope'], file: str, statements, cond: str = '', base_dir: str = '') -> Scope: @@ -333,7 +358,7 @@ class Scope(object): else_statements = statement.get('else_statements') if else_statements: Scope.FromDict(scope, file, else_statements, - 'NOT ' + condition, scope.basedir) + 'else', scope.basedir) continue loaded = statement.get('loaded') @@ -355,6 +380,8 @@ class Scope(object): scope.currentdir))) continue + scope.settle_condition() + if scope.scope_debug: print('..... [SCOPE_DEBUG]: Created scope {}:'.format(scope)) scope.dump(indent=1) |