diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2019-09-23 13:19:22 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2019-09-23 13:09:58 +0000 |
commit | 8049ef3d4d1e6c458211a3c86ea35e9fe9b29ff5 (patch) | |
tree | 6ccda7a8331e3c9c222df01fc65519e690767393 | |
parent | 6ff123be879bcb8d476c11af44a36624e2b626aa (diff) |
cmake: Implement the ~= operator in pro2cmake
Change-Id: I3fadd0038d517d197cce898d10edd6ba452adea9
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rwxr-xr-x | util/cmake/pro2cmake.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 649aacc28d..8765c870f6 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -676,7 +676,6 @@ class AddOperation(Operation): def __repr__(self): return f"+({self._dump()})" - class UniqueAddOperation(Operation): def process( self, key: str, sinput: List[str], transformer: Callable[[List[str]], List[str]] @@ -690,6 +689,37 @@ class UniqueAddOperation(Operation): def __repr__(self): return f"*({self._dump()})" +class ReplaceOperation(Operation): + def process( + self, key: str, sinput: List[str], transformer: Callable[[List[str]], List[str]] + ) -> List[str]: + result = [] + for s in sinput: + for v in transformer(self._value): + pattern, replacement = self.split_rex(v) + result.append(re.sub(pattern, replacement, s)) + return result + + def split_rex(self, s): + pattern = "" + replacement = "" + if len(s) < 4: + return pattern, replacement + sep = s[1] + s = s[2:] + rex = re.compile(f"[^\\\\]{sep}") + m = rex.search(s) + if not m: + return pattern, replacement + pattern = s[:m.start() + 1] + replacement = s[m.end():] + m = rex.search(replacement) + if m: + replacement = replacement[:m.start() + 1] + return pattern, replacement + + def __repr__(self): + return f"*({self._dump()})" class SetOperation(Operation): def process( @@ -864,6 +894,8 @@ class Scope(object): scope._append_operation(key, AddOperation(value)) elif operation == "*=": scope._append_operation(key, UniqueAddOperation(value)) + elif operation == "~=": + scope._append_operation(key, ReplaceOperation(value)) else: print(f'Unexpected operation "{operation}" in scope "{scope}".') assert False @@ -1250,7 +1282,7 @@ class QmakeParser: Values = add_element("Values", pp.ZeroOrMore(Value)("value")) Op = add_element( - "OP", pp.Literal("=") | pp.Literal("-=") | pp.Literal("+=") | pp.Literal("*=") + "OP", pp.Literal("=") | pp.Literal("-=") | pp.Literal("+=") | pp.Literal("*=") | pp.Literal("~=") ) Key = add_element("Key", Identifier) |