2018-10-24 13:20:27 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#############################################################################
|
|
|
|
##
|
|
|
|
## Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
## Contact: https://www.qt.io/licensing/
|
|
|
|
##
|
|
|
|
## This file is part of the plugins of the Qt Toolkit.
|
|
|
|
##
|
|
|
|
## $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
|
|
|
## Commercial License Usage
|
|
|
|
## Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
## accordance with the commercial license agreement provided with the
|
|
|
|
## Software or, alternatively, in accordance with the terms contained in
|
|
|
|
## a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
## and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
## information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
##
|
|
|
|
## GNU General Public License Usage
|
|
|
|
## Alternatively, this file may be used under the terms of the GNU
|
|
|
|
## General Public License version 3 as published by the Free Software
|
|
|
|
## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
## included in the packaging of this file. Please review the following
|
|
|
|
## information to ensure the GNU General Public License requirements will
|
|
|
|
## be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
##
|
|
|
|
## $QT_END_LICENSE$
|
|
|
|
##
|
|
|
|
#############################################################################
|
|
|
|
|
2019-01-24 15:01:17 +00:00
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
from argparse import ArgumentParser
|
2019-01-24 15:01:17 +00:00
|
|
|
import copy
|
2018-10-24 13:20:27 +00:00
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
import io
|
|
|
|
import typing
|
|
|
|
|
2019-01-23 15:40:23 +00:00
|
|
|
from sympy.logic import (simplify_logic, And, Or, Not,)
|
2018-10-24 13:20:27 +00:00
|
|
|
import pyparsing as pp
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
from helper import map_qt_library, map_qt_base_library, featureName, \
|
|
|
|
substitute_platform, substitute_libs
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _parse_commandline():
|
2018-12-21 11:13:38 +00:00
|
|
|
parser = ArgumentParser(description='Generate CMakeLists.txt files from .'
|
|
|
|
'pro files.')
|
2018-10-24 13:20:27 +00:00
|
|
|
parser.add_argument('--debug', dest='debug', action='store_true',
|
|
|
|
help='Turn on all debug output')
|
2018-12-21 11:13:38 +00:00
|
|
|
parser.add_argument('--debug-parser', dest='debug_parser',
|
|
|
|
action='store_true',
|
2018-10-24 13:20:27 +00:00
|
|
|
help='Print debug output from qmake parser.')
|
2018-12-21 11:13:38 +00:00
|
|
|
parser.add_argument('--debug-parse-result', dest='debug_parse_result',
|
|
|
|
action='store_true',
|
2018-10-24 13:20:27 +00:00
|
|
|
help='Dump the qmake parser result.')
|
2018-12-21 11:13:38 +00:00
|
|
|
parser.add_argument('--debug-parse-dictionary',
|
|
|
|
dest='debug_parse_dictionary', action='store_true',
|
2018-10-24 13:20:27 +00:00
|
|
|
help='Dump the qmake parser result as dictionary.')
|
2018-12-21 11:13:38 +00:00
|
|
|
parser.add_argument('--debug-pro-structure', dest='debug_pro_structure',
|
|
|
|
action='store_true',
|
2018-10-24 13:20:27 +00:00
|
|
|
help='Dump the structure of the qmake .pro-file.')
|
2018-12-21 11:13:38 +00:00
|
|
|
parser.add_argument('--debug-full-pro-structure',
|
|
|
|
dest='debug_full_pro_structure', action='store_true',
|
|
|
|
help='Dump the full structure of the qmake .pro-file '
|
|
|
|
'(with includes).')
|
|
|
|
parser.add_argument('files', metavar='<.pro/.pri file>', type=str,
|
|
|
|
nargs='+', help='The .pro/.pri file to process')
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def spaces(indent: int) -> str:
|
|
|
|
return ' ' * indent
|
|
|
|
|
|
|
|
|
|
|
|
def map_to_file(f: str, top_dir: str, current_dir: str,
|
|
|
|
want_absolute_path: bool = False) -> typing.Optional[str]:
|
|
|
|
if f == '$$NO_PCH_SOURCES':
|
|
|
|
return None
|
|
|
|
if f.startswith('$$PWD/') or f == '$$PWD': # INCLUDEPATH += $$PWD
|
|
|
|
return os.path.join(os.path.relpath(current_dir, top_dir), f[6:])
|
|
|
|
if f.startswith('$$OUT_PWD/'):
|
|
|
|
return "${CMAKE_CURRENT_BUILD_DIR}/" + f[10:]
|
|
|
|
if f.startswith('$$QT_SOURCE_TREE'):
|
|
|
|
return "${PROJECT_SOURCE_DIR}/" + f[17:]
|
|
|
|
if f.startswith("./"):
|
|
|
|
return os.path.join(current_dir, f)
|
|
|
|
if want_absolute_path and not os.path.isabs(f):
|
|
|
|
return os.path.join(current_dir, f)
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def map_source_to_cmake(source: str, base_dir: str,
|
|
|
|
vpath: typing.List[str]) -> str:
|
2018-10-24 13:20:27 +00:00
|
|
|
if not source or source == '$$NO_PCH_SOURCES':
|
2018-12-21 11:13:38 +00:00
|
|
|
return ''
|
2018-10-24 13:20:27 +00:00
|
|
|
if source.startswith('$$PWD/'):
|
|
|
|
return source[6:]
|
|
|
|
if source == '.':
|
|
|
|
return "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
|
|
if source.startswith('$$QT_SOURCE_TREE/'):
|
|
|
|
return "${PROJECT_SOURCE_DIR}/" + source[17:]
|
2018-12-20 09:41:56 +00:00
|
|
|
|
|
|
|
if os.path.exists(os.path.join(base_dir, source)):
|
|
|
|
return source
|
|
|
|
|
|
|
|
for v in vpath:
|
|
|
|
fullpath = os.path.join(v, source)
|
|
|
|
if os.path.exists(fullpath):
|
|
|
|
relpath = os.path.relpath(fullpath, base_dir)
|
|
|
|
return relpath
|
|
|
|
|
|
|
|
print(' XXXX: Source {}: Not found.'.format(source))
|
|
|
|
return '{}-NOTFOUND'.format(source)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def map_source_to_fs(base_dir: str, file: str,
|
|
|
|
source: str) -> str:
|
2018-10-24 13:20:27 +00:00
|
|
|
if source is None or source == '$$NO_PCH_SOURCES':
|
2018-12-21 11:13:38 +00:00
|
|
|
return ''
|
2018-10-24 13:20:27 +00:00
|
|
|
if source.startswith('$$PWD/'):
|
|
|
|
return os.path.join(os.path.dirname(file), source[6:])
|
|
|
|
if source.startswith('$$QT_SOURCE_TREE/'):
|
|
|
|
return os.path.join('.', source[17:])
|
|
|
|
if source.startswith('${PROJECT_SOURCE_DIR}/'):
|
|
|
|
return os.path.join('.', source[22:])
|
|
|
|
if source.startswith('${CMAKE_CURRENT_SOURCE_DIR}/'):
|
|
|
|
return os.path.join(base_dir, source[28:])
|
|
|
|
return os.path.join(base_dir, source)
|
|
|
|
|
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
class Operation:
|
|
|
|
def __init__(self, value):
|
|
|
|
if isinstance(value, list):
|
|
|
|
self._value = value
|
|
|
|
else:
|
2018-12-21 11:13:38 +00:00
|
|
|
self._value = [str(value), ]
|
2018-12-20 15:15:10 +00:00
|
|
|
|
|
|
|
def process(self, input):
|
|
|
|
assert(False)
|
|
|
|
|
2019-01-17 16:10:17 +00:00
|
|
|
def __repr__(self):
|
2018-12-20 15:15:10 +00:00
|
|
|
assert(False)
|
|
|
|
|
2019-01-22 13:16:41 +00:00
|
|
|
def _dump(self):
|
|
|
|
if not self._value:
|
|
|
|
return '<NOTHING>'
|
|
|
|
|
|
|
|
if not isinstance(self._value, list):
|
|
|
|
return '<NOT A LIST>'
|
|
|
|
|
|
|
|
result = []
|
|
|
|
for i in self._value:
|
|
|
|
if not i:
|
|
|
|
result.append('<NONE>')
|
|
|
|
else:
|
|
|
|
result.append(str(i))
|
|
|
|
return '"' + '", "'.join(result) + '"'
|
2018-12-20 15:15:10 +00:00
|
|
|
|
2019-01-25 14:41:02 +00:00
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
class AddOperation(Operation):
|
|
|
|
def process(self, input):
|
|
|
|
return input + self._value
|
|
|
|
|
2019-01-17 16:10:17 +00:00
|
|
|
def __repr__(self):
|
2019-01-22 13:16:41 +00:00
|
|
|
return '+({})'.format(self._dump())
|
2018-12-20 15:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UniqueAddOperation(Operation):
|
|
|
|
def process(self, input):
|
|
|
|
result = input
|
|
|
|
for v in self._value:
|
2018-12-21 11:13:38 +00:00
|
|
|
if v not in result:
|
|
|
|
result += [v, ]
|
2018-12-20 15:15:10 +00:00
|
|
|
return result
|
|
|
|
|
2019-01-17 16:10:17 +00:00
|
|
|
def __repr__(self):
|
2019-01-22 13:16:41 +00:00
|
|
|
return '*({})'.format(self._dump())
|
2018-12-20 15:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SetOperation(Operation):
|
|
|
|
def process(self, input):
|
|
|
|
return self._value
|
|
|
|
|
2019-01-17 16:10:17 +00:00
|
|
|
def __repr__(self):
|
2019-01-22 13:16:41 +00:00
|
|
|
return '=({})'.format(self._dump())
|
2018-12-20 15:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RemoveOperation(Operation):
|
|
|
|
def __init__(self, value):
|
|
|
|
super().__init__(value)
|
|
|
|
|
|
|
|
def process(self, input):
|
|
|
|
input_set = set(input)
|
|
|
|
result = []
|
|
|
|
for v in self._value:
|
|
|
|
if v in input_set:
|
|
|
|
continue
|
|
|
|
else:
|
2018-12-21 11:13:38 +00:00
|
|
|
result += ['-{}'.format(v), ]
|
2018-12-20 15:15:10 +00:00
|
|
|
return result
|
|
|
|
|
2019-01-17 16:10:17 +00:00
|
|
|
def __repr__(self):
|
2019-01-22 13:16:41 +00:00
|
|
|
return '-({})'.format(self._dump())
|
2018-12-20 15:15:10 +00:00
|
|
|
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
class Scope(object):
|
2019-01-24 15:01:17 +00:00
|
|
|
def __init__(self, *,
|
|
|
|
parent_scope: typing.Optional[Scope],
|
2018-12-21 11:13:38 +00:00
|
|
|
file: typing.Optional[str] = None, condition: str = '',
|
2019-01-24 15:01:17 +00:00
|
|
|
base_dir: str = '',
|
|
|
|
operations: typing.Mapping[str, typing.List[Operation]] = {}) -> None:
|
2018-12-20 15:15:10 +00:00
|
|
|
if parent_scope:
|
|
|
|
parent_scope._add_child(self)
|
|
|
|
else:
|
2018-12-21 11:13:38 +00:00
|
|
|
self._parent = None # type: typing.Optional[Scope]
|
2018-12-20 15:15:10 +00:00
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
self._basedir = base_dir
|
|
|
|
if file:
|
|
|
|
self._currentdir = os.path.dirname(file)
|
|
|
|
if not self._currentdir:
|
|
|
|
self._currentdir = '.'
|
|
|
|
if not self._basedir:
|
|
|
|
self._basedir = self._currentdir
|
|
|
|
|
|
|
|
self._file = file
|
|
|
|
self._condition = map_condition(condition)
|
2018-12-21 11:13:38 +00:00
|
|
|
self._children = [] # type: typing.List[Scope]
|
2019-01-24 15:01:17 +00:00
|
|
|
self._operations = copy.deepcopy(operations)
|
2019-01-18 11:43:11 +00:00
|
|
|
self._visited_keys = set() # type: typing.Set[str]
|
2019-01-22 13:20:47 +00:00
|
|
|
self._total_condition = None # type: typing.Optional[str]
|
2019-01-18 11:43:11 +00:00
|
|
|
|
2019-01-24 14:43:13 +00:00
|
|
|
def __repr__(self):
|
2019-01-31 09:18:14 +00:00
|
|
|
debug_mark = ' [MERGE_DEBUG]' if self.merge_debug else ''
|
|
|
|
return '{}:{}:{}{}'.format(self._basedir, self._file,
|
|
|
|
self._condition or '<NONE>', debug_mark)
|
2019-01-24 14:43:13 +00:00
|
|
|
|
2019-01-18 11:43:11 +00:00
|
|
|
def reset_visited_keys(self):
|
|
|
|
self._visited_keys = set()
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
def merge(self, other: 'Scope') -> None:
|
2019-01-31 09:18:14 +00:00
|
|
|
assert self != other
|
|
|
|
merge_debug = self.merge_debug or other.merge_debug
|
|
|
|
if merge_debug:
|
|
|
|
print('..... [MERGE_DEBUG]: Merging scope {}:'.format(other))
|
|
|
|
other.dump(indent=1)
|
|
|
|
print('..... [MERGE_DEBUG]: ... into scope {}:'.format(self))
|
|
|
|
self.dump(indent=1)
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
for c in other._children:
|
2018-12-20 15:15:10 +00:00
|
|
|
self._add_child(c)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
for key in other._operations.keys():
|
2019-01-17 14:30:56 +00:00
|
|
|
if key in self._operations:
|
|
|
|
self._operations[key] += other._operations[key]
|
|
|
|
else:
|
|
|
|
self._operations[key] = other._operations[key]
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-31 09:18:14 +00:00
|
|
|
if merge_debug:
|
|
|
|
print('..... [MERGE_DEBUG]: Result scope {}:'.format(self))
|
|
|
|
self.dump(indent=1)
|
|
|
|
print('..... [MERGE_DEBUG]: <<END OF MERGE>>')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def merge_debug(self) -> bool:
|
|
|
|
return self.getString('PRO2CMAKE_MERGE_DEBUG', None) != None
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2019-01-24 15:01:17 +00:00
|
|
|
def parent(self) -> typing.Optional[Scope]:
|
|
|
|
return self._parent
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2018-10-24 13:20:27 +00:00
|
|
|
def basedir(self) -> str:
|
|
|
|
return self._basedir
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2018-10-24 13:20:27 +00:00
|
|
|
def currentdir(self) -> str:
|
|
|
|
return self._currentdir
|
|
|
|
|
|
|
|
@staticmethod
|
2018-12-20 15:15:10 +00:00
|
|
|
def FromDict(parent_scope: typing.Optional['Scope'],
|
|
|
|
file: str, statements, cond: str = '', base_dir: str = ''):
|
2019-01-24 15:01:17 +00:00
|
|
|
scope = Scope(parent_scope=parent_scope, file=file, condition=cond, base_dir=base_dir)
|
2018-10-24 13:20:27 +00:00
|
|
|
for statement in statements:
|
|
|
|
if isinstance(statement, list): # Handle skipped parts...
|
|
|
|
assert not statement
|
|
|
|
continue
|
|
|
|
|
|
|
|
operation = statement.get('operation', None)
|
|
|
|
if operation:
|
|
|
|
key = statement.get('key', '')
|
|
|
|
value = statement.get('value', [])
|
|
|
|
assert key != ''
|
|
|
|
|
2019-01-23 11:56:11 +00:00
|
|
|
if key in ('HEADERS', 'SOURCES', 'INCLUDEPATH', 'RESOURCES',) \
|
2018-12-21 11:13:38 +00:00
|
|
|
or key.endswith('_HEADERS') \
|
|
|
|
or key.endswith('_SOURCES'):
|
2019-01-29 09:18:21 +00:00
|
|
|
value = [map_to_file(v, scope.basedir,
|
|
|
|
scope.currentdir) for v in value]
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if operation == '=':
|
2018-12-20 15:15:10 +00:00
|
|
|
scope._append_operation(key, SetOperation(value))
|
2018-10-24 13:20:27 +00:00
|
|
|
elif operation == '-=':
|
2018-12-20 15:15:10 +00:00
|
|
|
scope._append_operation(key, RemoveOperation(value))
|
|
|
|
elif operation == '+=':
|
|
|
|
scope._append_operation(key, AddOperation(value))
|
|
|
|
elif operation == '*=':
|
|
|
|
scope._append_operation(key, UniqueAddOperation(value))
|
2018-10-24 13:20:27 +00:00
|
|
|
else:
|
2019-01-24 14:43:13 +00:00
|
|
|
print('Unexpected operation "{}" in scope "{}".'
|
|
|
|
.format(operation, scope))
|
2018-10-24 13:20:27 +00:00
|
|
|
assert(False)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
condition = statement.get('condition', None)
|
|
|
|
if condition:
|
2018-12-21 11:13:38 +00:00
|
|
|
Scope.FromDict(scope, file,
|
|
|
|
statement.get('statements'), condition,
|
2019-01-29 09:18:21 +00:00
|
|
|
scope.basedir)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
else_statements = statement.get('else_statements')
|
|
|
|
if else_statements:
|
2018-12-21 11:13:38 +00:00
|
|
|
Scope.FromDict(scope, file, else_statements,
|
2019-01-29 09:18:21 +00:00
|
|
|
'NOT ' + condition, scope.basedir)
|
2018-10-24 13:20:27 +00:00
|
|
|
continue
|
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
loaded = statement.get('loaded')
|
2018-10-24 13:20:27 +00:00
|
|
|
if loaded:
|
2018-12-20 15:15:10 +00:00
|
|
|
scope._append_operation('_LOADED', UniqueAddOperation(loaded))
|
2018-10-24 13:20:27 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
option = statement.get('option', None)
|
|
|
|
if option:
|
2018-12-20 15:15:10 +00:00
|
|
|
scope._append_operation('_OPTION', UniqueAddOperation(option))
|
2018-10-24 13:20:27 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
included = statement.get('included', None)
|
|
|
|
if included:
|
2018-12-21 11:13:38 +00:00
|
|
|
scope._append_operation('_INCLUDED',
|
|
|
|
UniqueAddOperation(
|
|
|
|
map_to_file(included,
|
2019-01-29 09:18:21 +00:00
|
|
|
scope.basedir,
|
|
|
|
scope.currentdir)))
|
2018-10-24 13:20:27 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
return scope
|
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
def _append_operation(self, key: str, op: Operation) -> None:
|
|
|
|
if key in self._operations:
|
|
|
|
self._operations[key].append(op)
|
|
|
|
else:
|
2018-12-21 11:13:38 +00:00
|
|
|
self._operations[key] = [op, ]
|
2018-12-20 15:15:10 +00:00
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2018-10-24 13:20:27 +00:00
|
|
|
def file(self) -> str:
|
|
|
|
return self._file or ''
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2018-10-24 13:20:27 +00:00
|
|
|
def cMakeListsFile(self) -> str:
|
2019-01-29 09:18:21 +00:00
|
|
|
assert self.basedir
|
|
|
|
return os.path.join(self.basedir, 'CMakeLists.txt')
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2018-10-24 13:20:27 +00:00
|
|
|
def condition(self) -> str:
|
|
|
|
return self._condition
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2019-01-22 13:20:47 +00:00
|
|
|
def total_condition(self) -> typing.Optional[str]:
|
|
|
|
return self._total_condition
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@total_condition.setter
|
|
|
|
def total_condition(self, condition: str) -> None:
|
|
|
|
self._total_condition = condition
|
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
def _add_child(self, scope: 'Scope') -> None:
|
2018-10-24 13:20:27 +00:00
|
|
|
scope._parent = self
|
|
|
|
self._children.append(scope)
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2018-12-21 11:13:38 +00:00
|
|
|
def children(self) -> typing.List['Scope']:
|
2018-10-24 13:20:27 +00:00
|
|
|
return self._children
|
|
|
|
|
|
|
|
def dump(self, *, indent: int = 0) -> None:
|
|
|
|
ind = ' ' * indent
|
2019-01-24 14:43:13 +00:00
|
|
|
print('{}Scope "{}":'.format(ind, self))
|
2019-01-31 10:54:55 +00:00
|
|
|
if self.total_condition:
|
|
|
|
print('{} Total condition = {}'.format(ind, self.total_condition))
|
2019-01-18 11:40:29 +00:00
|
|
|
print('{} Keys:'.format(ind))
|
2019-01-17 16:10:57 +00:00
|
|
|
keys = self._operations.keys()
|
|
|
|
if not keys:
|
|
|
|
print('{} -- NONE --'.format(ind))
|
|
|
|
else:
|
|
|
|
for k in sorted(keys):
|
2019-01-25 14:41:02 +00:00
|
|
|
print('{} {} = "{}"'
|
|
|
|
.format(ind, k, self._operations.get(k, [])))
|
2019-01-18 11:40:29 +00:00
|
|
|
print('{} Children:'.format(ind))
|
2019-01-17 16:10:57 +00:00
|
|
|
if not self._children:
|
|
|
|
print('{} -- NONE --'.format(ind))
|
|
|
|
else:
|
|
|
|
for c in self._children:
|
|
|
|
c.dump(indent=indent + 1)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2019-01-18 11:43:11 +00:00
|
|
|
def keys(self):
|
|
|
|
return self._operations.keys()
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
2019-01-18 11:43:11 +00:00
|
|
|
def visited_keys(self):
|
2019-01-25 14:41:02 +00:00
|
|
|
return self._visited_keys
|
2019-01-18 11:43:11 +00:00
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def get(self, key: str, default=None) -> typing.List[str]:
|
2019-01-18 11:43:11 +00:00
|
|
|
self._visited_keys.add(key)
|
2018-12-21 11:13:38 +00:00
|
|
|
result = [] # type: typing.List[str]
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
for op in self._operations.get(key, []):
|
|
|
|
result = op.process(result)
|
|
|
|
return result
|
|
|
|
|
|
|
|
def getString(self, key: str, default: str = '') -> str:
|
|
|
|
v = self.get(key, default)
|
|
|
|
if len(v) == 0:
|
|
|
|
return default
|
|
|
|
assert len(v) == 1
|
|
|
|
return v[0]
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
|
|
|
def TEMPLATE(self) -> str:
|
2018-10-24 13:20:27 +00:00
|
|
|
return self.getString('TEMPLATE', 'app')
|
|
|
|
|
|
|
|
def _rawTemplate(self) -> str:
|
|
|
|
return self.getString('TEMPLATE')
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
|
|
|
def TARGET(self) -> str:
|
2018-12-21 11:13:38 +00:00
|
|
|
return self.getString('TARGET') \
|
2019-01-29 09:18:21 +00:00
|
|
|
or os.path.splitext(os.path.basename(self.file))[0]
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
|
|
|
def _INCLUDED(self) -> typing.List[str]:
|
2019-01-18 11:46:08 +00:00
|
|
|
return self.get('_INCLUDED', [])
|
2019-01-17 12:41:17 +00:00
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
class QmakeParser:
|
|
|
|
def __init__(self, *, debug: bool = False) -> None:
|
|
|
|
self._Grammar = self._generate_grammar(debug)
|
|
|
|
|
|
|
|
def _generate_grammar(self, debug: bool):
|
|
|
|
# Define grammar:
|
|
|
|
pp.ParserElement.setDefaultWhitespaceChars(' \t')
|
|
|
|
|
|
|
|
LC = pp.Suppress(pp.Literal('\\') + pp.LineEnd())
|
|
|
|
EOL = pp.Suppress(pp.Optional(pp.pythonStyleComment()) + pp.LineEnd())
|
|
|
|
|
2018-11-01 13:57:31 +00:00
|
|
|
Identifier = pp.Word(pp.alphas + '_', bodyChars=pp.alphanums+'_-./')
|
2018-12-21 11:13:38 +00:00
|
|
|
Substitution \
|
|
|
|
= pp.Combine(pp.Literal('$')
|
|
|
|
+ (((pp.Literal('$') + Identifier
|
2019-01-25 14:41:02 +00:00
|
|
|
+ pp.Optional(pp.nestedExpr()))
|
|
|
|
| (pp.Literal('(') + Identifier + pp.Literal(')'))
|
|
|
|
| (pp.Literal('{') + Identifier + pp.Literal('}'))
|
|
|
|
| (pp.Literal('$') + pp.Literal('{')
|
2018-12-21 11:13:38 +00:00
|
|
|
+ Identifier + pp.Optional(pp.nestedExpr())
|
|
|
|
+ pp.Literal('}'))
|
2019-01-25 14:41:02 +00:00
|
|
|
| (pp.Literal('$') + pp.Literal('[') + Identifier
|
2018-12-21 11:13:38 +00:00
|
|
|
+ pp.Literal(']'))
|
|
|
|
)))
|
|
|
|
# Do not match word ending in '\' since that breaks line
|
|
|
|
# continuation:-/
|
2018-10-24 13:20:27 +00:00
|
|
|
LiteralValuePart = pp.Word(pp.printables, excludeChars='$#{}()')
|
2018-12-21 11:13:38 +00:00
|
|
|
SubstitutionValue \
|
|
|
|
= pp.Combine(pp.OneOrMore(Substitution | LiteralValuePart
|
|
|
|
| pp.Literal('$')))
|
|
|
|
Value = (pp.QuotedString(quoteChar='"', escChar='\\')
|
|
|
|
| SubstitutionValue)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
Values = pp.ZeroOrMore(Value)('value')
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
Op = pp.Literal('=') | pp.Literal('-=') | pp.Literal('+=') \
|
|
|
|
| pp.Literal('*=')
|
|
|
|
|
|
|
|
Operation = Identifier('key') + Op('operation') + Values('value')
|
|
|
|
Load = pp.Keyword('load') + pp.Suppress('(') \
|
|
|
|
+ Identifier('loaded') + pp.Suppress(')')
|
|
|
|
Include = pp.Keyword('include') + pp.Suppress('(') \
|
|
|
|
+ pp.CharsNotIn(':{=}#)\n')('included') + pp.Suppress(')')
|
|
|
|
Option = pp.Keyword('option') + pp.Suppress('(') \
|
|
|
|
+ Identifier('option') + pp.Suppress(')')
|
|
|
|
DefineTest = pp.Suppress(pp.Keyword('defineTest')
|
|
|
|
+ pp.Suppress('(') + Identifier
|
|
|
|
+ pp.Suppress(')')
|
|
|
|
+ pp.nestedExpr(opener='{', closer='}')
|
|
|
|
+ pp.LineEnd()) # ignore the whole thing...
|
2018-11-01 15:13:11 +00:00
|
|
|
ForLoop = pp.Suppress(pp.Keyword('for') + pp.nestedExpr()
|
2018-12-21 11:13:38 +00:00
|
|
|
+ pp.nestedExpr(opener='{', closer='}',
|
|
|
|
ignoreExpr=None)
|
|
|
|
+ pp.LineEnd()) # ignore the whole thing...
|
2018-10-24 13:20:27 +00:00
|
|
|
FunctionCall = pp.Suppress(Identifier + pp.nestedExpr())
|
|
|
|
|
|
|
|
Scope = pp.Forward()
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
Statement = pp.Group(Load | Include | Option | DefineTest
|
|
|
|
| ForLoop | FunctionCall | Operation)
|
2018-10-24 13:20:27 +00:00
|
|
|
StatementLine = Statement + EOL
|
2018-11-01 15:12:21 +00:00
|
|
|
StatementGroup = pp.ZeroOrMore(StatementLine | Scope | EOL)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
Block = pp.Suppress('{') + pp.Optional(EOL) \
|
|
|
|
+ pp.ZeroOrMore(EOL | Statement + EOL | Scope) \
|
|
|
|
+ pp.Optional(Statement) + pp.Optional(EOL) \
|
|
|
|
+ pp.Suppress('}') + pp.Optional(EOL)
|
|
|
|
|
|
|
|
Condition = pp.Optional(pp.White()) + pp.CharsNotIn(':{=}#\\\n')
|
|
|
|
Condition.setParseAction(lambda x: ' '.join(x).strip())
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
SingleLineScope = pp.Suppress(pp.Literal(':')) \
|
|
|
|
+ pp.Group(Scope | Block | StatementLine)('statements')
|
2018-10-24 13:20:27 +00:00
|
|
|
MultiLineScope = Block('statements')
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
SingleLineElse = pp.Suppress(pp.Literal(':')) \
|
|
|
|
+ pp.Group(Scope | StatementLine)('else_statements')
|
|
|
|
MultiLineElse = pp.Group(Block)('else_statements')
|
|
|
|
Else = pp.Suppress(pp.Keyword('else')) \
|
|
|
|
+ (SingleLineElse | MultiLineElse)
|
|
|
|
Scope <<= pp.Group(Condition('condition')
|
|
|
|
+ (SingleLineScope | MultiLineScope)
|
|
|
|
+ pp.Optional(Else))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if debug:
|
2018-12-21 11:13:38 +00:00
|
|
|
for ename in 'EOL Identifier Substitution SubstitutionValue ' \
|
|
|
|
'LiteralValuePart Value Values SingleLineScope ' \
|
|
|
|
'MultiLineScope Scope SingleLineElse ' \
|
|
|
|
'MultiLineElse Else Condition Block ' \
|
|
|
|
'StatementGroup Statement Load Include Option ' \
|
|
|
|
'DefineTest ForLoop FunctionCall Operation'.split():
|
2018-10-24 13:20:27 +00:00
|
|
|
expr = locals()[ename]
|
|
|
|
expr.setName(ename)
|
|
|
|
expr.setDebug()
|
|
|
|
|
|
|
|
Grammar = StatementGroup('statements')
|
|
|
|
Grammar.ignore(LC)
|
|
|
|
|
|
|
|
return Grammar
|
|
|
|
|
|
|
|
def parseFile(self, file: str):
|
|
|
|
print('Parsing \"{}\"...'.format(file))
|
|
|
|
try:
|
|
|
|
result = self._Grammar.parseFile(file, parseAll=True)
|
|
|
|
except pp.ParseException as pe:
|
|
|
|
print(pe.line)
|
|
|
|
print(' '*(pe.col-1) + '^')
|
|
|
|
print(pe)
|
|
|
|
raise pe
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def parseProFile(file: str, *, debug=False):
|
|
|
|
parser = QmakeParser(debug=debug)
|
|
|
|
return parser.parseFile(file)
|
|
|
|
|
|
|
|
|
|
|
|
def map_condition(condition: str) -> str:
|
2019-01-23 15:40:23 +00:00
|
|
|
re.sub(r'if\s*\((.*?)\)', r'\1', condition)
|
|
|
|
re.sub(r'(^|[^a-zA-Z0-9_])isEmpty\s*\((.*?)\)', r'\2_ISEMPTY', condition)
|
|
|
|
re.sub(r'(^|[^a-zA-Z0-9_])contains\s*\((.*?), (.*)?\)',
|
|
|
|
r'\2___contains___\3', condition)
|
|
|
|
re.sub(r'\s*==\s*', '___STREQUAL___', condition)
|
2019-01-23 11:57:06 +00:00
|
|
|
|
|
|
|
condition = condition.replace('*', '_x_')
|
|
|
|
condition = condition.replace('.$$', '__ss_')
|
|
|
|
condition = condition.replace('$$', '_ss_')
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
condition = condition.replace('!', 'NOT ')
|
|
|
|
condition = condition.replace('&&', ' AND ')
|
|
|
|
condition = condition.replace('|', ' OR ')
|
2019-01-17 16:11:52 +00:00
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
cmake_condition = ''
|
|
|
|
for part in condition.split():
|
2018-12-21 11:13:38 +00:00
|
|
|
# some features contain e.g. linux, that should not be
|
|
|
|
# turned upper case
|
|
|
|
feature = re.match(r"(qtConfig|qtHaveModule)\(([a-zA-Z0-9_-]+)\)",
|
|
|
|
part)
|
2018-10-24 13:20:27 +00:00
|
|
|
if feature:
|
2018-11-01 13:56:13 +00:00
|
|
|
if (feature.group(1) == "qtHaveModule"):
|
2018-12-21 11:13:38 +00:00
|
|
|
part = 'TARGET {}'.format(map_qt_base_library(
|
|
|
|
feature.group(2)))
|
2018-11-01 13:56:13 +00:00
|
|
|
else:
|
2019-01-28 14:06:44 +00:00
|
|
|
feature = featureName(feature.group(2))
|
|
|
|
if feature.startswith('system_') and substitute_libs(feature[7:]) != feature[7:]:
|
|
|
|
# Qt6 always uses system libraries!
|
|
|
|
part = 'ON'
|
|
|
|
else:
|
|
|
|
part = 'QT_FEATURE_' + feature
|
2018-10-24 13:20:27 +00:00
|
|
|
else:
|
|
|
|
part = substitute_platform(part)
|
|
|
|
|
|
|
|
part = part.replace('true', 'ON')
|
|
|
|
part = part.replace('false', 'OFF')
|
|
|
|
cmake_condition += ' ' + part
|
|
|
|
return cmake_condition.strip()
|
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def handle_subdir(scope: Scope, cm_fh: typing.IO[str], *,
|
|
|
|
indent: int = 0) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
assert scope.TEMPLATE == 'subdirs'
|
2018-10-24 13:20:27 +00:00
|
|
|
ind = ' ' * indent
|
|
|
|
for sd in scope.get('SUBDIRS', []):
|
2019-01-29 09:18:21 +00:00
|
|
|
full_sd = os.path.join(scope.basedir, sd)
|
2018-10-24 13:20:27 +00:00
|
|
|
if os.path.isdir(full_sd):
|
|
|
|
cm_fh.write('{}add_subdirectory({})\n'.format(ind, sd))
|
|
|
|
elif os.path.isfile(full_sd):
|
|
|
|
subdir_result = parseProFile(full_sd, debug=False)
|
2018-12-21 11:13:38 +00:00
|
|
|
subdir_scope \
|
|
|
|
= Scope.FromDict(scope, full_sd,
|
|
|
|
subdir_result.asDict().get('statements'),
|
2019-01-29 09:18:21 +00:00
|
|
|
'', scope.basedir)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
cmakeify_scope(subdir_scope, cm_fh, indent=indent + 1)
|
|
|
|
elif sd.startswith('-'):
|
2018-12-21 11:13:38 +00:00
|
|
|
cm_fh.write('{}### remove_subdirectory'
|
|
|
|
'("{}")\n'.format(ind, sd[1:]))
|
2018-10-24 13:20:27 +00:00
|
|
|
else:
|
2019-01-24 14:43:13 +00:00
|
|
|
print(' XXXX: SUBDIR {} in {}: Not found.'.format(sd, scope))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
for c in scope.children():
|
2019-01-29 09:18:21 +00:00
|
|
|
cond = c.condition
|
2018-10-24 13:20:27 +00:00
|
|
|
if cond == 'else':
|
|
|
|
cm_fh.write('\n{}else()\n'.format(ind))
|
|
|
|
elif cond:
|
|
|
|
cm_fh.write('\n{}if({})\n'.format(ind, cond))
|
|
|
|
|
|
|
|
handle_subdir(c, cm_fh, indent=indent + 1)
|
|
|
|
|
|
|
|
if cond:
|
|
|
|
cm_fh.write('{}endif()\n'.format(ind))
|
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def sort_sources(sources) -> typing.List[str]:
|
|
|
|
to_sort = {} # type: typing.Dict[str, typing.List[str]]
|
2018-10-24 13:20:27 +00:00
|
|
|
for s in sources:
|
|
|
|
if s is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
dir = os.path.dirname(s)
|
|
|
|
base = os.path.splitext(os.path.basename(s))[0]
|
|
|
|
if base.endswith('_p'):
|
|
|
|
base = base[:-2]
|
|
|
|
sort_name = os.path.join(dir, base)
|
|
|
|
|
|
|
|
array = to_sort.get(sort_name, [])
|
|
|
|
array.append(s)
|
|
|
|
|
|
|
|
to_sort[sort_name] = array
|
|
|
|
|
|
|
|
lines = []
|
|
|
|
for k in sorted(to_sort.keys()):
|
|
|
|
lines.append(' '.join(sorted(to_sort[k])))
|
|
|
|
|
|
|
|
return lines
|
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_header(cm_fh: typing.IO[str], name: str,
|
|
|
|
typename: str, *, indent: int = 0):
|
|
|
|
cm_fh.write('{}###########################################'
|
|
|
|
'##########################\n'.format(spaces(indent)))
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write('{}## {} {}:\n'.format(spaces(indent), name, typename))
|
2018-12-21 11:13:38 +00:00
|
|
|
cm_fh.write('{}###########################################'
|
|
|
|
'##########################\n\n'.format(spaces(indent)))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_scope_header(cm_fh: typing.IO[str], *, indent: int = 0):
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write('\n{}## Scopes:\n'.format(spaces(indent)))
|
2018-12-21 11:13:38 +00:00
|
|
|
cm_fh.write('{}###########################################'
|
|
|
|
'##########################\n'.format(spaces(indent)))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_sources_section(cm_fh: typing.IO[str], scope: Scope, *,
|
2019-01-25 14:41:02 +00:00
|
|
|
indent: int = 0, known_libraries=set()) \
|
|
|
|
-> typing.Set[str]:
|
2018-10-24 13:20:27 +00:00
|
|
|
ind = spaces(indent)
|
2019-01-25 14:41:02 +00:00
|
|
|
scope.reset_visited_keys()
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
plugin_type = scope.get('PLUGIN_TYPE')
|
2019-01-18 11:43:11 +00:00
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
if plugin_type:
|
|
|
|
cm_fh.write('{} TYPE {}\n'.format(ind, plugin_type[0]))
|
|
|
|
|
2019-01-18 11:46:08 +00:00
|
|
|
sources = scope.get('SOURCES') + scope.get('HEADERS') \
|
|
|
|
+ scope.get('OBJECTIVE_SOURCES') + scope.get('NO_PCH_SOURCES') \
|
|
|
|
+ scope.get('FORMS')
|
|
|
|
resources = scope.get('RESOURCES')
|
2018-10-24 13:20:27 +00:00
|
|
|
if resources:
|
|
|
|
qrc_only = True
|
|
|
|
for r in resources:
|
|
|
|
if not r.endswith('.qrc'):
|
|
|
|
qrc_only = False
|
|
|
|
break
|
|
|
|
|
|
|
|
if not qrc_only:
|
|
|
|
print(' XXXX Ignoring non-QRC file resources.')
|
|
|
|
else:
|
|
|
|
sources += resources
|
|
|
|
|
2018-12-20 09:41:56 +00:00
|
|
|
vpath = scope.get('VPATH')
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
sources = [map_source_to_cmake(s, scope.basedir, vpath) for s in sources]
|
2018-10-24 13:20:27 +00:00
|
|
|
if sources:
|
|
|
|
cm_fh.write('{} SOURCES\n'.format(ind))
|
|
|
|
for l in sort_sources(sources):
|
|
|
|
cm_fh.write('{} {}\n'.format(ind, l))
|
|
|
|
|
2019-01-18 11:46:08 +00:00
|
|
|
defines = scope.get('DEFINES')
|
2018-12-20 15:15:10 +00:00
|
|
|
if defines:
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write('{} DEFINES\n'.format(ind))
|
2018-12-20 15:15:10 +00:00
|
|
|
for d in defines:
|
2018-12-21 11:13:38 +00:00
|
|
|
d = d.replace('=\\\\\\"$$PWD/\\\\\\"',
|
|
|
|
'="${CMAKE_CURRENT_SOURCE_DIR}/"')
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write('{} {}\n'.format(ind, d))
|
2019-01-18 11:46:08 +00:00
|
|
|
includes = scope.get('INCLUDEPATH')
|
2018-12-20 15:15:10 +00:00
|
|
|
if includes:
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write('{} INCLUDE_DIRECTORIES\n'.format(ind))
|
2018-12-20 15:15:10 +00:00
|
|
|
for i in includes:
|
2019-01-18 11:02:04 +00:00
|
|
|
i = i.rstrip('/') or ('/')
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write('{} {}\n'.format(ind, i))
|
|
|
|
|
2019-01-18 11:46:08 +00:00
|
|
|
dependencies = [map_qt_library(q) for q in scope.get('QT')
|
2018-12-21 11:13:38 +00:00
|
|
|
if map_qt_library(q) not in known_libraries]
|
2019-01-18 11:46:08 +00:00
|
|
|
dependencies += [map_qt_library(q) for q in scope.get('QT_FOR_PRIVATE')
|
2018-12-21 11:13:38 +00:00
|
|
|
if map_qt_library(q) not in known_libraries]
|
2019-01-29 11:07:24 +00:00
|
|
|
dependencies += scope.get('QMAKE_USE_PRIVATE') + scope.get('QMAKE_USE') \
|
2019-01-18 11:46:08 +00:00
|
|
|
+ scope.get('LIBS_PRIVATE') + scope.get('LIBS')
|
2018-10-24 13:20:27 +00:00
|
|
|
if dependencies:
|
|
|
|
cm_fh.write('{} LIBRARIES\n'.format(ind))
|
|
|
|
is_framework = False
|
|
|
|
for d in dependencies:
|
|
|
|
if d == '-framework':
|
|
|
|
is_framework = True
|
|
|
|
continue
|
|
|
|
if is_framework:
|
|
|
|
d = '${FW%s}' % d
|
|
|
|
if d.startswith('-l'):
|
|
|
|
d = d[2:]
|
2018-11-02 11:32:57 +00:00
|
|
|
|
|
|
|
if d.startswith('-'):
|
|
|
|
d = '# Remove: {}'.format(d[1:])
|
|
|
|
else:
|
|
|
|
d = substitute_libs(d)
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write('{} {}\n'.format(ind, d))
|
|
|
|
is_framework = False
|
|
|
|
|
2019-01-29 11:07:24 +00:00
|
|
|
compile_options = scope.get('QMAKE_CXXFLAGS')
|
|
|
|
if compile_options:
|
|
|
|
cm_fh.write('{} COMPILE_OPTIONS\n'.format(ind))
|
|
|
|
for co in compile_options:
|
|
|
|
cm_fh.write('{} "{}"\n'.format(ind, co))
|
|
|
|
|
|
|
|
link_options = scope.get('QMAKE_LFLAGS')
|
|
|
|
if link_options:
|
|
|
|
cm_fh.write('{} LINK_OPTIONS\n'.format(ind))
|
|
|
|
for lo in link_options:
|
|
|
|
cm_fh.write('{} "{}"\n'.format(ind, lo))
|
|
|
|
|
2019-01-30 15:43:11 +00:00
|
|
|
moc_options = scope.get('QMAKE_MOC_OPTIONS')
|
|
|
|
if moc_options:
|
|
|
|
cm_fh.write('{} MOC_OPTIONS\n'.format(ind))
|
|
|
|
for mo in moc_options:
|
|
|
|
cm_fh.write('{} "{}"\n'.format(ind, mo))
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
return set(scope.keys) - scope.visited_keys
|
2019-01-17 16:11:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_simple_condition(condition: str) -> bool:
|
2019-01-25 14:41:02 +00:00
|
|
|
return ' ' not in condition \
|
|
|
|
or (condition.startswith('NOT ') and ' ' not in condition[4:])
|
2019-01-17 16:11:52 +00:00
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-18 11:43:11 +00:00
|
|
|
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':
|
2019-01-25 14:41:02 +00:00
|
|
|
# All these keys are actually reported already
|
2019-01-18 11:43:11 +00:00
|
|
|
continue
|
|
|
|
values = scope.get(k)
|
2019-01-25 14:41:02 +00:00
|
|
|
value_string = '<EMPTY>' if not values \
|
|
|
|
else '"' + '" "'.join(scope.get(k)) + '"'
|
2019-01-18 11:43:11 +00:00
|
|
|
result += '{}# {} = {}\n'.format(indent, k, value_string)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2019-01-23 15:40:23 +00:00
|
|
|
def _iterate_expr_tree(expr, op, matches):
|
|
|
|
assert expr.func == op
|
|
|
|
keepers = ()
|
|
|
|
for arg in expr.args:
|
|
|
|
if arg in matches:
|
|
|
|
matches = tuple(x for x in matches if x != arg)
|
|
|
|
elif arg == op:
|
|
|
|
(matches, extra_keepers) = _iterate_expr_tree(arg, op, matches)
|
|
|
|
keepers = (*keepers, *extra_keepers)
|
|
|
|
else:
|
|
|
|
keepers = (*keepers, arg)
|
|
|
|
return (matches, keepers)
|
|
|
|
|
|
|
|
|
|
|
|
def _simplify_expressions(expr, op, matches, replacement):
|
|
|
|
args = expr.args
|
|
|
|
for arg in args:
|
|
|
|
expr = expr.subs(arg, _simplify_expressions(arg, op, matches,
|
|
|
|
replacement))
|
|
|
|
|
|
|
|
if expr.func == op:
|
|
|
|
(to_match, keepers) = tuple(_iterate_expr_tree(expr, op, matches))
|
|
|
|
if len(to_match) == 0:
|
|
|
|
# build expression with keepers and replacement:
|
|
|
|
if keepers:
|
|
|
|
start = replacement
|
|
|
|
current_expr = None
|
|
|
|
last_expr = keepers[-1]
|
|
|
|
for repl_arg in keepers[:-1]:
|
|
|
|
current_expr = op(start, repl_arg)
|
|
|
|
start = current_expr
|
|
|
|
top_expr = op(start, last_expr)
|
|
|
|
else:
|
|
|
|
top_expr = replacement
|
|
|
|
|
|
|
|
expr = expr.subs(expr, top_expr)
|
|
|
|
|
|
|
|
return expr
|
|
|
|
|
|
|
|
|
|
|
|
def _simplify_flavors_in_condition(base: str, flavors, expr):
|
|
|
|
''' Simplify conditions based on the knownledge of which flavors
|
|
|
|
belong to which OS. '''
|
|
|
|
base_expr = simplify_logic(base)
|
|
|
|
false_expr = simplify_logic('false')
|
|
|
|
for flavor in flavors:
|
|
|
|
flavor_expr = simplify_logic(flavor)
|
|
|
|
expr = _simplify_expressions(expr, And, (base_expr, flavor_expr,),
|
|
|
|
flavor_expr)
|
|
|
|
expr = _simplify_expressions(expr, Or, (base_expr, flavor_expr),
|
|
|
|
base_expr)
|
|
|
|
expr = _simplify_expressions(expr, And, (Not(base_expr), flavor_expr,),
|
|
|
|
false_expr)
|
|
|
|
return expr
|
|
|
|
|
|
|
|
|
|
|
|
def _recursive_simplify(expr):
|
|
|
|
''' Simplify the expression as much as possible based on
|
|
|
|
domain knowledge. '''
|
|
|
|
input_expr = expr
|
|
|
|
|
|
|
|
# Simplify even further, based on domain knowledge:
|
|
|
|
apples = ('APPLE_OSX', 'APPLE_UIKIT', 'APPLE_IOS',
|
|
|
|
'APPLE_TVOS', 'APPLE_WATCHOS',)
|
|
|
|
bsds = ('APPLE', 'FREEBSD', 'OPENBSD', 'NETBSD',)
|
|
|
|
unixes = ('APPLE', *apples, 'BSD', *bsds, 'LINUX',
|
|
|
|
'ANDROID', 'ANDROID_EMBEDDED',
|
|
|
|
'INTEGRITY', 'VXWORKS', 'QNX', 'WASM')
|
|
|
|
|
|
|
|
unix_expr = simplify_logic('UNIX')
|
|
|
|
win_expr = simplify_logic('WIN32')
|
|
|
|
false_expr = simplify_logic('false')
|
|
|
|
true_expr = simplify_logic('true')
|
|
|
|
|
|
|
|
expr = expr.subs(Not(unix_expr), win_expr) # NOT UNIX -> WIN32
|
|
|
|
expr = expr.subs(Not(win_expr), unix_expr) # NOT WIN32 -> UNIX
|
|
|
|
|
|
|
|
# UNIX [OR foo ]OR WIN32 -> ON [OR foo]
|
|
|
|
expr = _simplify_expressions(expr, Or, (unix_expr, win_expr,), true_expr)
|
|
|
|
# UNIX [AND foo ]AND WIN32 -> OFF [AND foo]
|
|
|
|
expr = _simplify_expressions(expr, And, (unix_expr, win_expr,), false_expr)
|
|
|
|
for unix_flavor in unixes:
|
|
|
|
# unix_flavor [AND foo ] AND WIN32 -> FALSE [AND foo]
|
|
|
|
flavor_expr = simplify_logic(unix_flavor)
|
|
|
|
expr = _simplify_expressions(expr, And, (win_expr, flavor_expr,),
|
|
|
|
false_expr)
|
|
|
|
|
|
|
|
expr = _simplify_flavors_in_condition('WIN32', ('WINRT',), expr)
|
|
|
|
expr = _simplify_flavors_in_condition('APPLE', apples, expr)
|
|
|
|
expr = _simplify_flavors_in_condition('BSD', bsds, expr)
|
|
|
|
expr = _simplify_flavors_in_condition('UNIX', unixes, expr)
|
|
|
|
|
|
|
|
# Now simplify further:
|
|
|
|
expr = simplify_logic(expr)
|
|
|
|
|
|
|
|
while expr != input_expr:
|
|
|
|
input_expr = expr
|
|
|
|
expr = _recursive_simplify(expr)
|
|
|
|
|
|
|
|
return expr
|
|
|
|
|
|
|
|
|
|
|
|
def simplify_condition(condition: str) -> str:
|
|
|
|
input_condition = condition.strip()
|
|
|
|
|
|
|
|
# Map to sympy syntax:
|
|
|
|
condition = ' ' + input_condition + ' '
|
|
|
|
condition = condition.replace('(', ' ( ')
|
|
|
|
condition = condition.replace(')', ' ) ')
|
|
|
|
|
|
|
|
tmp = ''
|
|
|
|
while tmp != condition:
|
|
|
|
tmp = condition
|
|
|
|
|
|
|
|
condition = condition.replace(' NOT ', ' ~ ')
|
|
|
|
condition = condition.replace(' AND ', ' & ')
|
|
|
|
condition = condition.replace(' OR ', ' | ')
|
|
|
|
condition = condition.replace(' ON ', 'true')
|
|
|
|
condition = condition.replace(' OFF ', 'false')
|
|
|
|
|
|
|
|
try:
|
|
|
|
# Generate and simplify condition using sympy:
|
|
|
|
condition_expr = simplify_logic(condition)
|
|
|
|
condition = str(_recursive_simplify(condition_expr))
|
|
|
|
|
|
|
|
# Map back to CMake syntax:
|
|
|
|
condition = condition.replace('~', 'NOT ')
|
|
|
|
condition = condition.replace('&', 'AND')
|
|
|
|
condition = condition.replace('|', 'OR')
|
|
|
|
condition = condition.replace('True', 'ON')
|
|
|
|
condition = condition.replace('False', 'OFF')
|
|
|
|
except:
|
|
|
|
# sympy did not like our input, so leave this condition alone:
|
|
|
|
condition = input_condition
|
|
|
|
|
2019-01-24 15:01:17 +00:00
|
|
|
if condition == '':
|
|
|
|
condition = 'ON'
|
2019-01-23 15:40:23 +00:00
|
|
|
return condition
|
|
|
|
|
|
|
|
|
2019-01-22 13:20:47 +00:00
|
|
|
def recursive_evaluate_scope(scope: Scope, parent_condition: str = '',
|
|
|
|
previous_condition: str = '') -> str:
|
2019-01-29 09:18:21 +00:00
|
|
|
current_condition = scope.condition
|
2019-01-22 13:23:59 +00:00
|
|
|
total_condition = current_condition
|
2018-10-24 13:20:27 +00:00
|
|
|
if total_condition == 'else':
|
2019-01-17 16:11:52 +00:00
|
|
|
assert previous_condition, \
|
2019-01-29 09:18:21 +00:00
|
|
|
"Else branch without previous condition in: %s" % scope.file
|
2019-01-17 16:11:52 +00:00
|
|
|
if previous_condition.startswith('NOT '):
|
|
|
|
total_condition = previous_condition[4:]
|
|
|
|
elif is_simple_condition(previous_condition):
|
|
|
|
total_condition = 'NOT {}'.format(previous_condition)
|
|
|
|
else:
|
|
|
|
total_condition = 'NOT ({})'.format(previous_condition)
|
2018-10-24 13:20:27 +00:00
|
|
|
if parent_condition:
|
2019-01-17 16:11:52 +00:00
|
|
|
if not total_condition:
|
|
|
|
total_condition = parent_condition
|
|
|
|
else:
|
2019-01-25 14:41:02 +00:00
|
|
|
if is_simple_condition(parent_condition) \
|
|
|
|
and is_simple_condition(total_condition):
|
2019-01-17 16:11:52 +00:00
|
|
|
total_condition = '{} AND {}'.format(parent_condition,
|
|
|
|
total_condition)
|
|
|
|
elif is_simple_condition(total_condition):
|
2019-01-25 14:41:02 +00:00
|
|
|
total_condition = '({}) AND {}'.format(parent_condition,
|
|
|
|
total_condition)
|
2019-01-17 16:11:52 +00:00
|
|
|
elif is_simple_condition(parent_condition):
|
2019-01-25 14:41:02 +00:00
|
|
|
total_condition = '{} AND ({})'.format(parent_condition,
|
|
|
|
total_condition)
|
2019-01-17 16:11:52 +00:00
|
|
|
else:
|
2019-01-25 14:41:02 +00:00
|
|
|
total_condition = '({}) AND ({})'.format(parent_condition,
|
|
|
|
total_condition)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
scope.total_condition = simplify_condition(total_condition)
|
2019-01-22 13:20:47 +00:00
|
|
|
|
|
|
|
prev_condition = ''
|
2019-01-29 09:18:21 +00:00
|
|
|
for c in scope.children:
|
2019-01-22 13:20:47 +00:00
|
|
|
prev_condition = recursive_evaluate_scope(c, total_condition,
|
|
|
|
prev_condition)
|
|
|
|
|
2019-01-22 13:23:59 +00:00
|
|
|
return current_condition
|
2019-01-22 13:20:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def write_extend_target(cm_fh: typing.IO[str], target: str,
|
|
|
|
scope: Scope, indent: int = 0):
|
2018-10-24 13:20:27 +00:00
|
|
|
extend_qt_io_string = io.StringIO()
|
2019-01-18 11:43:11 +00:00
|
|
|
ignored_keys = write_sources_section(extend_qt_io_string, scope)
|
2018-10-24 13:20:27 +00:00
|
|
|
extend_qt_string = extend_qt_io_string.getvalue()
|
|
|
|
|
2019-01-25 14:41:02 +00:00
|
|
|
ignored_keys_report = write_ignored_keys(scope, ignored_keys,
|
|
|
|
spaces(indent + 1))
|
2019-01-18 11:43:11 +00:00
|
|
|
if extend_qt_string and ignored_keys_report:
|
|
|
|
ignored_keys_report = '\n' + ignored_keys_report
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
extend_scope = '\n{}extend_target({} CONDITION {}\n' \
|
2019-01-22 13:20:47 +00:00
|
|
|
'{}{})\n'.format(spaces(indent), target,
|
2019-01-29 09:18:21 +00:00
|
|
|
scope.total_condition,
|
2019-01-25 14:41:02 +00:00
|
|
|
extend_qt_string, ignored_keys_report)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if not extend_qt_string:
|
2019-01-18 11:43:11 +00:00
|
|
|
if ignored_keys_report:
|
|
|
|
# Comment out the generated extend_target call because there
|
|
|
|
# no sources were found, but keep it commented for
|
|
|
|
# informational purposes.
|
|
|
|
extend_scope = ''.join(['#' + line for line in
|
|
|
|
extend_scope.splitlines(keepends=True)])
|
|
|
|
else:
|
|
|
|
extend_scope = '' # Nothing to report, so don't!
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write(extend_scope)
|
|
|
|
|
|
|
|
|
2019-01-22 13:20:47 +00:00
|
|
|
def flatten_scopes(scope: Scope) -> typing.List[Scope]:
|
2019-01-24 15:01:17 +00:00
|
|
|
result = [scope] # type: typing.List[Scope]
|
2019-01-29 09:18:21 +00:00
|
|
|
for c in scope.children:
|
2019-01-22 13:20:47 +00:00
|
|
|
result += flatten_scopes(c)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def merge_scopes(scopes: typing.List[Scope]) -> typing.List[Scope]:
|
|
|
|
result = [] # type: typing.List[Scope]
|
|
|
|
|
2019-01-24 15:01:17 +00:00
|
|
|
# Merge scopes with their parents:
|
|
|
|
known_scopes = {} # type: typing.Mapping[str, Scope]
|
2019-01-22 13:20:47 +00:00
|
|
|
for scope in scopes:
|
2019-01-29 09:18:21 +00:00
|
|
|
total_condition = scope.total_condition
|
2019-01-24 15:01:17 +00:00
|
|
|
if total_condition == 'OFF':
|
|
|
|
# ignore this scope entirely!
|
|
|
|
pass
|
|
|
|
elif total_condition in known_scopes:
|
|
|
|
known_scopes[total_condition].merge(scope)
|
|
|
|
else:
|
|
|
|
# Keep everything else:
|
|
|
|
result.append(scope)
|
|
|
|
known_scopes[total_condition] = scope
|
2019-01-22 13:20:47 +00:00
|
|
|
|
|
|
|
return result
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_main_part(cm_fh: typing.IO[str], name: str, typename: str,
|
2018-10-24 13:20:27 +00:00
|
|
|
cmake_function: str, scope: Scope, *,
|
|
|
|
extra_lines: typing.List[str] = [],
|
2018-12-21 11:13:38 +00:00
|
|
|
indent: int = 0,
|
2018-10-24 13:20:27 +00:00
|
|
|
**kwargs: typing.Any):
|
2019-01-24 15:01:17 +00:00
|
|
|
# Evaluate total condition of all scopes:
|
|
|
|
recursive_evaluate_scope(scope)
|
|
|
|
|
|
|
|
# Get a flat list of all scopes but the main one:
|
|
|
|
scopes = flatten_scopes(scope)
|
|
|
|
total_scopes = len(scopes)
|
|
|
|
# Merge scopes based on their conditions:
|
|
|
|
scopes = merge_scopes(scopes)
|
|
|
|
print("xxxxxx {} scopes, {} after merging!".format(total_scopes, len(scopes)))
|
|
|
|
|
|
|
|
assert len(scopes)
|
2019-01-29 09:18:21 +00:00
|
|
|
assert scopes[0].total_condition == 'ON'
|
2019-01-24 15:01:17 +00:00
|
|
|
|
|
|
|
# Now write out the scopes:
|
2018-10-24 13:20:27 +00:00
|
|
|
write_header(cm_fh, name, typename, indent=indent)
|
|
|
|
|
|
|
|
cm_fh.write('{}{}({}\n'.format(spaces(indent), cmake_function, name))
|
|
|
|
for extra_line in extra_lines:
|
|
|
|
cm_fh.write('{} {}\n'.format(spaces(indent), extra_line))
|
|
|
|
|
2019-01-24 15:01:17 +00:00
|
|
|
ignored_keys = write_sources_section(cm_fh, scopes[0], indent=indent, **kwargs)
|
|
|
|
ignored_keys_report = write_ignored_keys(scopes[0], ignored_keys,
|
2019-01-25 14:41:02 +00:00
|
|
|
spaces(indent + 1))
|
2019-01-18 11:43:11 +00:00
|
|
|
if ignored_keys_report:
|
|
|
|
cm_fh.write(ignored_keys_report)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
# Footer:
|
|
|
|
cm_fh.write('{})\n'.format(spaces(indent)))
|
|
|
|
|
|
|
|
# Scopes:
|
2019-01-24 15:01:17 +00:00
|
|
|
if len(scopes) == 1:
|
2018-10-24 13:20:27 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
write_scope_header(cm_fh, indent=indent)
|
|
|
|
|
2019-01-24 15:01:17 +00:00
|
|
|
for c in scopes[1:]:
|
2019-01-22 13:20:47 +00:00
|
|
|
write_extend_target(cm_fh, name, c, indent=indent)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_module(cm_fh: typing.IO[str], scope: Scope, *,
|
|
|
|
indent: int = 0) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
module_name = scope.TARGET
|
2018-10-24 13:20:27 +00:00
|
|
|
assert module_name.startswith('Qt')
|
|
|
|
|
|
|
|
extra = []
|
|
|
|
if 'static' in scope.get('CONFIG'):
|
|
|
|
extra.append('STATIC')
|
|
|
|
if 'no_module_headers' in scope.get('CONFIG'):
|
|
|
|
extra.append('NO_MODULE_HEADERS')
|
|
|
|
|
|
|
|
write_main_part(cm_fh, module_name[2:], 'Module', 'add_qt_module', scope,
|
2018-12-21 11:13:38 +00:00
|
|
|
extra_lines=extra, indent=indent,
|
|
|
|
known_libraries={'Qt::Core', })
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if 'qt_tracepoints' in scope.get('CONFIG'):
|
2018-12-21 11:13:38 +00:00
|
|
|
tracepoints = map_to_file(scope.getString('TRACEPOINT_PROVIDER'),
|
2019-01-29 09:18:21 +00:00
|
|
|
scope.basedir, scope.currentdir)
|
2018-12-21 11:13:38 +00:00
|
|
|
cm_fh.write('\n\n{}qt_create_tracepoints({} {})\n'
|
|
|
|
.format(spaces(indent), module_name[2:], tracepoints))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_tool(cm_fh: typing.IO[str], scope: Scope, *,
|
|
|
|
indent: int = 0) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
tool_name = scope.TARGET
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
write_main_part(cm_fh, tool_name, 'Tool', 'add_qt_tool', scope,
|
|
|
|
indent=indent, known_libraries={'Qt::Core', })
|
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_test(cm_fh: typing.IO[str], scope: Scope, *,
|
|
|
|
indent: int = 0) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
test_name = scope.TARGET
|
2018-10-24 13:20:27 +00:00
|
|
|
assert test_name
|
|
|
|
|
|
|
|
write_main_part(cm_fh, test_name, 'Test', 'add_qt_test', scope,
|
|
|
|
indent=indent, known_libraries={'Qt::Core', 'Qt::Test', })
|
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_binary(cm_fh: typing.IO[str], scope: Scope,
|
|
|
|
gui: bool = False, *, indent: int = 0) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
binary_name = scope.TARGET
|
2018-10-24 13:20:27 +00:00
|
|
|
assert binary_name
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
extra = ['GUI', ] if gui else []
|
2018-10-24 13:20:27 +00:00
|
|
|
write_main_part(cm_fh, binary_name, 'Binary', 'add_qt_executable', scope,
|
2018-12-21 11:13:38 +00:00
|
|
|
extra_lines=extra, indent=indent,
|
|
|
|
known_libraries={'Qt::Core', })
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_plugin(cm_fh, scope, *, indent: int = 0):
|
2019-01-29 09:18:21 +00:00
|
|
|
plugin_name = scope.TARGET
|
2018-10-24 13:20:27 +00:00
|
|
|
assert plugin_name
|
|
|
|
|
|
|
|
write_main_part(cm_fh, plugin_name, 'Plugin', 'add_qt_plugin', scope,
|
|
|
|
indent=indent, known_libraries={'QtCore', })
|
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def handle_app_or_lib(scope: Scope, cm_fh: typing.IO[str], *,
|
|
|
|
indent: int = 0) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
assert scope.TEMPLATE in ('app', 'lib')
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
is_lib = scope.TEMPLATE == 'lib'
|
2018-10-24 13:20:27 +00:00
|
|
|
is_plugin = any('qt_plugin' == s for s in scope.get('_LOADED', []))
|
|
|
|
|
|
|
|
if is_lib or 'qt_module' in scope.get('_LOADED', []):
|
|
|
|
write_module(cm_fh, scope, indent=indent)
|
|
|
|
elif is_plugin:
|
|
|
|
write_plugin(cm_fh, scope, indent=indent)
|
|
|
|
elif 'qt_tool' in scope.get('_LOADED', []):
|
|
|
|
write_tool(cm_fh, scope, indent=indent)
|
|
|
|
else:
|
2018-12-21 11:13:38 +00:00
|
|
|
if 'testcase' in scope.get('CONFIG') \
|
|
|
|
or 'testlib' in scope.get('CONFIG'):
|
2018-10-24 13:20:27 +00:00
|
|
|
write_test(cm_fh, scope, indent=indent)
|
|
|
|
else:
|
|
|
|
gui = 'console' not in scope.get('CONFIG')
|
|
|
|
write_binary(cm_fh, scope, gui, indent=indent)
|
|
|
|
|
|
|
|
docs = scope.getString("QMAKE_DOCS")
|
|
|
|
if docs:
|
2018-12-21 11:13:38 +00:00
|
|
|
cm_fh.write("\n{}add_qt_docs({})\n"
|
|
|
|
.format(spaces(indent),
|
2019-01-29 09:18:21 +00:00
|
|
|
map_to_file(docs, scope.basedir,
|
|
|
|
scope.currentdir)))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def cmakeify_scope(scope: Scope, cm_fh: typing.IO[str], *,
|
|
|
|
indent: int = 0) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
template = scope.TEMPLATE
|
2018-10-24 13:20:27 +00:00
|
|
|
if template == 'subdirs':
|
|
|
|
handle_subdir(scope, cm_fh, indent=indent)
|
2018-11-01 14:52:21 +00:00
|
|
|
elif template in ('app', 'lib'):
|
2018-10-24 13:20:27 +00:00
|
|
|
handle_app_or_lib(scope, cm_fh, indent=indent)
|
|
|
|
else:
|
|
|
|
print(' XXXX: {}: Template type {} not yet supported.'
|
2019-01-29 09:18:21 +00:00
|
|
|
.format(scope.file, template))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def generate_cmakelists(scope: Scope) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
with open(scope.cMakeListsFile, 'w') as cm_fh:
|
|
|
|
assert scope.file
|
2018-12-21 11:13:38 +00:00
|
|
|
cm_fh.write('# Generated from {}.\n\n'
|
2019-01-29 09:18:21 +00:00
|
|
|
.format(os.path.basename(scope.file)))
|
2018-10-24 13:20:27 +00:00
|
|
|
cmakeify_scope(scope, cm_fh)
|
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def do_include(scope: Scope, *, debug: bool = False) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
for c in scope.children:
|
2019-01-17 16:14:19 +00:00
|
|
|
do_include(c)
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
for i in scope._INCLUDED:
|
|
|
|
dir = scope.basedir
|
2019-01-17 14:23:30 +00:00
|
|
|
include_file = i
|
2018-12-21 11:13:38 +00:00
|
|
|
if not include_file:
|
|
|
|
continue
|
2018-10-24 13:20:27 +00:00
|
|
|
if not os.path.isfile(include_file):
|
|
|
|
print(' XXXX: Failed to include {}.'.format(include_file))
|
|
|
|
continue
|
|
|
|
|
|
|
|
include_result = parseProFile(include_file, debug=debug)
|
2018-12-21 11:13:38 +00:00
|
|
|
include_scope \
|
2019-01-18 11:44:15 +00:00
|
|
|
= Scope.FromDict(None, include_file,
|
2018-12-21 11:13:38 +00:00
|
|
|
include_result.asDict().get('statements'),
|
2019-01-25 14:41:02 +00:00
|
|
|
'', dir) # This scope will be merged into scope!
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
do_include(include_scope)
|
|
|
|
|
|
|
|
scope.merge(include_scope)
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
args = _parse_commandline()
|
|
|
|
|
2018-11-01 14:55:19 +00:00
|
|
|
debug_parsing = args.debug_parser or args.debug
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
for file in args.files:
|
2018-11-01 14:55:19 +00:00
|
|
|
parseresult = parseProFile(file, debug=debug_parsing)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if args.debug_parse_result or args.debug:
|
|
|
|
print('\n\n#### Parser result:')
|
|
|
|
print(parseresult)
|
|
|
|
print('\n#### End of parser result.\n')
|
|
|
|
if args.debug_parse_dictionary or args.debug:
|
|
|
|
print('\n\n####Parser result dictionary:')
|
|
|
|
print(parseresult.asDict())
|
|
|
|
print('\n#### End of parser result dictionary.\n')
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
file_scope = Scope.FromDict(None, file,
|
|
|
|
parseresult.asDict().get('statements'))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if args.debug_pro_structure or args.debug:
|
|
|
|
print('\n\n#### .pro/.pri file structure:')
|
|
|
|
print(file_scope.dump())
|
|
|
|
print('\n#### End of .pro/.pri file structure.\n')
|
|
|
|
|
2018-11-01 14:55:19 +00:00
|
|
|
do_include(file_scope, debug=debug_parsing)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if args.debug_full_pro_structure or args.debug:
|
|
|
|
print('\n\n#### Full .pro/.pri file structure:')
|
|
|
|
print(file_scope.dump())
|
|
|
|
print('\n#### End of full .pro/.pri file structure.\n')
|
|
|
|
|
|
|
|
generate_cmakelists(file_scope)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|