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
|
2019-03-07 10:06:23 +00:00
|
|
|
import xml.etree.ElementTree as ET
|
2019-02-11 17:02:22 +00:00
|
|
|
from itertools import chain
|
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
|
2019-05-24 15:29:21 +00:00
|
|
|
from helper import _set_up_py_parsing_nicer_debug_output
|
|
|
|
_set_up_py_parsing_nicer_debug_output(pp)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-05-06 10:26:31 +00:00
|
|
|
from helper import map_qt_library, map_3rd_party_library, is_known_3rd_party_library, \
|
2019-05-17 13:05:49 +00:00
|
|
|
featureName, map_platform, find_library_info_for_target, generate_find_package_info, \
|
|
|
|
LibraryMapping
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-05-04 11:08:19 +00:00
|
|
|
from shutil import copyfile
|
|
|
|
from special_case_helper import SpecialCaseHandler
|
|
|
|
|
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).')
|
2019-05-04 11:08:19 +00:00
|
|
|
parser.add_argument('--debug-special-case-preservation',
|
|
|
|
dest='debug_special_case_preservation', action='store_true',
|
|
|
|
help='Show all git commands and file copies.')
|
2019-05-07 09:27:33 +00:00
|
|
|
|
2019-05-09 08:59:13 +00:00
|
|
|
parser.add_argument('--is-example', action='store_true',
|
2019-05-07 09:27:33 +00:00
|
|
|
dest="is_example",
|
|
|
|
help='Treat the input .pro file as an example.')
|
2019-05-04 11:08:19 +00:00
|
|
|
parser.add_argument('-s', '--skip-special-case-preservation',
|
|
|
|
dest='skip_special_case_preservation', action='store_true',
|
|
|
|
help='Skips behavior to reapply '
|
|
|
|
'special case modifications (requires git in PATH)')
|
|
|
|
parser.add_argument('-k', '--keep-temporary-files',
|
|
|
|
dest='keep_temporary_files', action='store_true',
|
|
|
|
help='Don\'t automatically remove CMakeLists.gen.txt and other '
|
|
|
|
'intermediate files.')
|
2019-05-07 09:27:33 +00:00
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2019-03-07 10:06:23 +00:00
|
|
|
def process_qrc_file(target: str, filepath: str, base_dir: str = '') -> str:
|
|
|
|
assert(target)
|
|
|
|
resource_name = os.path.splitext(os.path.basename(filepath))[0]
|
|
|
|
base_dir = os.path.join('' if base_dir == '.' else base_dir, os.path.dirname(filepath))
|
|
|
|
|
|
|
|
tree = ET.parse(filepath)
|
|
|
|
root = tree.getroot()
|
|
|
|
assert(root.tag == 'RCC')
|
|
|
|
|
|
|
|
output = ''
|
|
|
|
|
|
|
|
resource_count = 0
|
|
|
|
for resource in root:
|
|
|
|
assert(resource.tag == 'qresource')
|
|
|
|
lang = resource.get('lang', '')
|
|
|
|
prefix = resource.get('prefix', '')
|
|
|
|
|
|
|
|
full_resource_name = resource_name + (str(resource_count) if resource_count > 0 else '')
|
|
|
|
|
2019-04-04 08:38:13 +00:00
|
|
|
files: typing.Dict[str, str] = {}
|
2019-03-07 10:06:23 +00:00
|
|
|
for file in resource:
|
|
|
|
path = file.text
|
|
|
|
assert path
|
|
|
|
|
|
|
|
# Get alias:
|
|
|
|
alias = file.get('alias', '')
|
|
|
|
files[path] = alias
|
|
|
|
|
|
|
|
sorted_files = sorted(files.keys())
|
|
|
|
|
|
|
|
assert(sorted_files)
|
|
|
|
|
|
|
|
for source in sorted_files:
|
|
|
|
alias = files[source]
|
|
|
|
if alias:
|
|
|
|
full_source = os.path.join(base_dir, source)
|
|
|
|
output += 'set_source_files_properties("{}"\n' \
|
|
|
|
' PROPERTIES alias "{}")\n'.format(full_source, alias)
|
|
|
|
|
|
|
|
params = ''
|
|
|
|
if lang:
|
|
|
|
params += ' LANG "{}"'.format(lang)
|
|
|
|
if prefix:
|
|
|
|
params += ' PREFIX "{}"'.format(prefix)
|
|
|
|
if base_dir:
|
|
|
|
params += ' BASE "{}"'.format(base_dir)
|
|
|
|
output += 'add_qt_resource({} "{}"{} FILES\n {})\n'.format(target, full_resource_name,
|
|
|
|
params,
|
|
|
|
'\n '.join(sorted_files))
|
|
|
|
|
|
|
|
resource_count += 1
|
|
|
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
2019-02-13 11:24:14 +00:00
|
|
|
def fixup_linecontinuation(contents: str) -> str:
|
2019-05-23 13:57:59 +00:00
|
|
|
# Remove all line continuations, aka a backslash followed by
|
|
|
|
# a newline character with an arbitrary amount of whitespace
|
|
|
|
# between the backslash and the newline.
|
|
|
|
# This greatly simplifies the qmake parsing grammar.
|
|
|
|
contents = re.sub(r'([^\t ])\\[ \t]*\n', '\\1 ', contents)
|
|
|
|
contents = re.sub(r'\\[ \t]*\n', '', contents)
|
2019-02-13 11:24:14 +00:00
|
|
|
return contents
|
|
|
|
|
|
|
|
|
2019-05-17 16:31:19 +00:00
|
|
|
def fixup_comments(contents: str) -> str:
|
|
|
|
# Get rid of completely commented out lines.
|
|
|
|
# So any line which starts with a '#' char and ends with a new line
|
|
|
|
# will be replaced by a single new line.
|
|
|
|
#
|
|
|
|
# This is needed because qmake syntax is weird. In a multi line
|
|
|
|
# assignment (separated by backslashes and newlines aka
|
|
|
|
# # \\\n ), if any of the lines are completely commented out, in
|
|
|
|
# principle the assignment should fail.
|
|
|
|
#
|
|
|
|
# It should fail because you would have a new line separating
|
|
|
|
# the previous value from the next value, and the next value would
|
|
|
|
# not be interpreted as a value, but as a new token / operation.
|
|
|
|
# qmake is lenient though, and accepts that, so we need to take
|
|
|
|
# care of it as well, as if the commented line didn't exist in the
|
|
|
|
# first place.
|
|
|
|
|
|
|
|
contents = re.sub(r'\n#[^\n]*?\n', '\n', contents, re.DOTALL)
|
|
|
|
return contents
|
|
|
|
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
def spaces(indent: int) -> str:
|
|
|
|
return ' ' * indent
|
|
|
|
|
|
|
|
|
2019-04-16 14:32:08 +00:00
|
|
|
def trim_leading_dot(file: str) -> str:
|
|
|
|
while file.startswith('./'):
|
|
|
|
file = file[2:]
|
|
|
|
return file
|
|
|
|
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
def map_to_file(f: str, scope: Scope, *, is_include: bool = False) -> str:
|
|
|
|
assert('$$' not in f)
|
|
|
|
|
|
|
|
if f.startswith('${'): # Some cmake variable is prepended
|
|
|
|
return f
|
|
|
|
|
|
|
|
base_dir = scope.currentdir if is_include else scope.basedir
|
|
|
|
f = os.path.join(base_dir, f)
|
|
|
|
|
2019-04-16 14:32:08 +00:00
|
|
|
return trim_leading_dot(f)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
def handle_vpath(source: str, base_dir: str, vpath: typing.List[str]) -> str:
|
|
|
|
assert('$$' not in source)
|
|
|
|
|
|
|
|
if not source:
|
2018-12-21 11:13:38 +00:00
|
|
|
return ''
|
2019-03-28 12:54:56 +00:00
|
|
|
|
|
|
|
if not vpath:
|
|
|
|
return source
|
2018-12-20 09:41:56 +00:00
|
|
|
|
|
|
|
if os.path.exists(os.path.join(base_dir, source)):
|
|
|
|
return source
|
|
|
|
|
2019-03-28 07:29:53 +00:00
|
|
|
variable_pattern = re.compile(r'\$\{[A-Za-z0-9_]+\}')
|
|
|
|
match = re.match(variable_pattern, source)
|
|
|
|
if match:
|
|
|
|
# a complex, variable based path, skipping validation
|
|
|
|
# or resolving
|
|
|
|
return source
|
|
|
|
|
2018-12-20 09:41:56 +00:00
|
|
|
for v in vpath:
|
|
|
|
fullpath = os.path.join(v, source)
|
|
|
|
if os.path.exists(fullpath):
|
2019-04-16 14:32:08 +00:00
|
|
|
return trim_leading_dot(os.path.relpath(fullpath, base_dir))
|
2018-12-20 09:41:56 +00:00
|
|
|
|
|
|
|
print(' XXXX: Source {}: Not found.'.format(source))
|
|
|
|
return '{}-NOTFOUND'.format(source)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
class Operation:
|
2019-05-17 16:09:21 +00:00
|
|
|
def __init__(self, value: typing.Union[typing.List[str], str]):
|
|
|
|
if isinstance(value, list):
|
|
|
|
self._value = value
|
|
|
|
else:
|
|
|
|
self._value = [str(value), ]
|
2018-12-20 15:15:10 +00:00
|
|
|
|
2019-05-17 13:05:49 +00:00
|
|
|
def process(self, key: str, input: typing.List[str],
|
|
|
|
transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]:
|
2018-12-20 15:15:10 +00:00
|
|
|
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):
|
2019-05-17 13:05:49 +00:00
|
|
|
def process(self, key: str, input: typing.List[str],
|
|
|
|
transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]:
|
2019-03-28 12:54:56 +00:00
|
|
|
return input + transformer(self._value)
|
2018-12-20 15:15:10 +00:00
|
|
|
|
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):
|
2019-05-17 13:05:49 +00:00
|
|
|
def process(self, key: str, input: typing.List[str],
|
|
|
|
transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]:
|
2018-12-20 15:15:10 +00:00
|
|
|
result = input
|
2019-03-28 12:54:56 +00:00
|
|
|
for v in transformer(self._value):
|
2018-12-21 11:13:38 +00:00
|
|
|
if v not in result:
|
2019-03-28 12:54:56 +00:00
|
|
|
result.append(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):
|
2019-05-17 13:05:49 +00:00
|
|
|
def process(self, key: str, input: typing.List[str],
|
|
|
|
transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]:
|
2019-04-11 15:06:01 +00:00
|
|
|
values = [] # typing.List[str]
|
|
|
|
for v in self._value:
|
2019-05-17 13:05:49 +00:00
|
|
|
if v != '$${}'.format(key):
|
2019-04-11 15:06:01 +00:00
|
|
|
values.append(v)
|
|
|
|
else:
|
|
|
|
values += input
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
if transformer:
|
2019-04-11 15:06:01 +00:00
|
|
|
return list(transformer(values))
|
2019-03-28 12:54:56 +00:00
|
|
|
else:
|
2019-04-11 15:06:01 +00:00
|
|
|
return values
|
2018-12-20 15:15:10 +00:00
|
|
|
|
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)
|
|
|
|
|
2019-05-17 13:05:49 +00:00
|
|
|
def process(self, key: str, input: typing.List[str],
|
|
|
|
transformer: typing.Callable[[typing.List[str]], typing.List[str]]) -> typing.List[str]:
|
2018-12-20 15:15:10 +00:00
|
|
|
input_set = set(input)
|
2019-03-26 13:12:09 +00:00
|
|
|
value_set = set(self._value)
|
2018-12-20 15:15:10 +00:00
|
|
|
result = []
|
2019-03-26 13:12:09 +00:00
|
|
|
|
|
|
|
# Add everything that is not going to get removed:
|
|
|
|
for v in input:
|
|
|
|
if v not in value_set:
|
2019-03-26 09:17:58 +00:00
|
|
|
result += [v,]
|
2019-03-26 13:12:09 +00:00
|
|
|
|
|
|
|
# Add everything else with removal marker:
|
2019-03-28 12:54:56 +00:00
|
|
|
for v in transformer(self._value):
|
2019-03-26 13:12:09 +00:00
|
|
|
if v not in input_set:
|
2018-12-21 11:13:38 +00:00
|
|
|
result += ['-{}'.format(v), ]
|
2019-03-26 13:12:09 +00:00
|
|
|
|
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-31 11:17:27 +00:00
|
|
|
|
|
|
|
SCOPE_ID: int = 1
|
|
|
|
|
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 = '',
|
2019-02-07 14:30:44 +00:00
|
|
|
operations: typing.Mapping[str, typing.List[Operation]] = {
|
2019-05-17 13:05:49 +00:00
|
|
|
'QT_SOURCE_TREE': [SetOperation(['${PROJECT_SOURCE_DIR}'])],
|
|
|
|
'QT_BUILD_TREE': [SetOperation(['${PROJECT_BUILD_DIR}'])],
|
2019-02-07 14:30:44 +00:00
|
|
|
}) -> 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
|
|
|
|
|
2019-01-31 11:17:27 +00:00
|
|
|
self._scope_id = Scope.SCOPE_ID
|
|
|
|
Scope.SCOPE_ID += 1
|
2018-10-24 13:20:27 +00:00
|
|
|
self._file = file
|
|
|
|
self._condition = map_condition(condition)
|
2018-12-21 11:13:38 +00:00
|
|
|
self._children = [] # type: typing.List[Scope]
|
2019-03-28 12:54:56 +00:00
|
|
|
self._included_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-04-08 09:28:49 +00:00
|
|
|
return '{}:{}:{}:{}:{}'.format(self._scope_id,
|
|
|
|
self._basedir, self._currentdir,
|
2019-03-28 12:54:56 +00:00
|
|
|
self._file, self._condition or '<TRUE>')
|
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
|
2019-03-28 12:54:56 +00:00
|
|
|
self._included_children.append(other)
|
2019-01-31 09:18:14 +00:00
|
|
|
|
2019-01-31 13:23:57 +00:00
|
|
|
@property
|
|
|
|
def scope_debug(self) -> bool:
|
2019-03-28 12:54:56 +00:00
|
|
|
merge = self.get_string('PRO2CMAKE_SCOPE_DEBUG').lower()
|
2019-05-08 14:45:25 +00:00
|
|
|
return merge == '1' or merge == 'on' or merge == 'yes' or merge == 'true'
|
2019-01-31 13:23:57 +00:00
|
|
|
|
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
|
|
|
|
|
2019-01-31 13:26:06 +00:00
|
|
|
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):
|
2019-03-18 18:12:52 +00:00
|
|
|
new_children: typing.List[Scope] = []
|
2019-01-31 13:26:06 +00:00
|
|
|
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
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
@staticmethod
|
2018-12-20 15:15:10 +00:00
|
|
|
def FromDict(parent_scope: typing.Optional['Scope'],
|
2019-01-31 13:25:32 +00:00
|
|
|
file: str, statements, cond: str = '', base_dir: str = '') -> Scope:
|
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 != ''
|
|
|
|
|
|
|
|
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-31 13:26:06 +00:00
|
|
|
'else', 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',
|
2019-03-28 12:54:56 +00:00
|
|
|
UniqueAddOperation(included))
|
2018-10-24 13:20:27 +00:00
|
|
|
continue
|
|
|
|
|
2019-01-31 13:26:06 +00:00
|
|
|
scope.settle_condition()
|
|
|
|
|
2019-01-31 13:23:57 +00:00
|
|
|
if scope.scope_debug:
|
|
|
|
print('..... [SCOPE_DEBUG]: Created scope {}:'.format(scope))
|
|
|
|
scope.dump(indent=1)
|
|
|
|
print('..... [SCOPE_DEBUG]: <<END OF SCOPE>>')
|
2018-10-24 13:20:27 +00:00
|
|
|
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
|
2019-05-04 11:08:19 +00:00
|
|
|
def generated_cmake_lists_path(self) -> str:
|
|
|
|
assert self.basedir
|
|
|
|
return os.path.join(self.basedir, 'CMakeLists.gen.txt')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def original_cmake_lists_path(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']:
|
2019-03-28 12:54:56 +00:00
|
|
|
result = list(self._children)
|
|
|
|
for include_scope in self._included_children:
|
2019-05-29 15:39:56 +00:00
|
|
|
result += include_scope.children
|
2019-03-28 12:54:56 +00:00
|
|
|
return result
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
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)
|
2019-03-28 12:54:56 +00:00
|
|
|
print('{} Includes:'.format(ind))
|
|
|
|
if not self._included_children:
|
|
|
|
print('{} -- NONE --'.format(ind))
|
|
|
|
else:
|
|
|
|
for c in self._included_children:
|
|
|
|
c.dump(indent=indent + 1)
|
|
|
|
|
|
|
|
def dump_structure(self, *, type: str = 'ROOT', indent: int = 0) -> None:
|
|
|
|
print('{}{}: {}'.format(spaces(indent), type, self))
|
|
|
|
for i in self._included_children:
|
|
|
|
i.dump_structure(type='INCL', indent=indent + 1)
|
|
|
|
for i in self._children:
|
|
|
|
i.dump_structure(type='CHLD', 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
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
def _evalOps(self, key: str,
|
|
|
|
transformer: typing.Optional[typing.Callable[[Scope, typing.List[str]], typing.List[str]]],
|
2019-04-12 09:45:43 +00:00
|
|
|
result: typing.List[str], *, inherrit: bool = False) \
|
2019-03-28 12:54:56 +00:00
|
|
|
-> typing.List[str]:
|
2019-01-18 11:43:11 +00:00
|
|
|
self._visited_keys.add(key)
|
2019-03-28 12:54:56 +00:00
|
|
|
|
2019-04-12 09:45:43 +00:00
|
|
|
# Inherrit values from above:
|
|
|
|
if self._parent and inherrit:
|
|
|
|
result = self._parent._evalOps(key, transformer, result)
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
if transformer:
|
|
|
|
op_transformer = lambda files: transformer(self, files)
|
|
|
|
else:
|
|
|
|
op_transformer = lambda files: files
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
for op in self._operations.get(key, []):
|
2019-04-11 15:06:01 +00:00
|
|
|
result = op.process(key, result, op_transformer)
|
2019-03-28 12:54:56 +00:00
|
|
|
|
|
|
|
for ic in self._included_children:
|
|
|
|
result = list(ic._evalOps(key, transformer, result))
|
|
|
|
|
2018-12-20 15:15:10 +00:00
|
|
|
return result
|
|
|
|
|
2019-04-12 09:45:43 +00:00
|
|
|
def get(self, key: str, *, ignore_includes: bool = False, inherrit: bool = False) -> typing.List[str]:
|
2019-05-29 07:57:34 +00:00
|
|
|
|
|
|
|
is_same_path = self.currentdir == self.basedir
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
if key == 'PWD':
|
2019-05-29 07:57:34 +00:00
|
|
|
if is_same_path:
|
|
|
|
return ['${CMAKE_CURRENT_SOURCE_DIR}']
|
|
|
|
else:
|
|
|
|
return ['${CMAKE_CURRENT_SOURCE_DIR}/' + os.path.relpath(self.currentdir, self.basedir),]
|
2019-03-28 12:54:56 +00:00
|
|
|
if key == 'OUT_PWD':
|
2019-05-29 07:57:34 +00:00
|
|
|
if is_same_path:
|
|
|
|
return ['${CMAKE_CURRENT_BUILD_DIR}']
|
|
|
|
else:
|
|
|
|
return ['${CMAKE_CURRENT_BUILD_DIR}/' + os.path.relpath(self.currentdir, self.basedir),]
|
2019-03-28 12:54:56 +00:00
|
|
|
|
2019-04-12 09:45:43 +00:00
|
|
|
return self._evalOps(key, None, [], inherrit=inherrit)
|
2019-03-28 12:54:56 +00:00
|
|
|
|
|
|
|
def get_string(self, key: str, default: str = '') -> str:
|
|
|
|
v = self.get(key)
|
2018-12-20 15:15:10 +00:00
|
|
|
if len(v) == 0:
|
|
|
|
return default
|
|
|
|
assert len(v) == 1
|
|
|
|
return v[0]
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
def _map_files(self, files: typing.List[str], *,
|
|
|
|
use_vpath: bool = True, is_include: bool = False) -> typing.List[str]:
|
|
|
|
|
2019-05-08 14:45:25 +00:00
|
|
|
expanded_files = [] # type: typing.List[str]
|
2019-03-28 12:54:56 +00:00
|
|
|
for f in files:
|
2019-04-11 15:06:01 +00:00
|
|
|
r = self._expand_value(f)
|
|
|
|
expanded_files += r
|
2019-03-28 12:54:56 +00:00
|
|
|
|
|
|
|
mapped_files = list(map(lambda f: map_to_file(f, self, is_include=is_include), expanded_files))
|
|
|
|
|
|
|
|
if use_vpath:
|
2019-04-12 09:45:43 +00:00
|
|
|
result = list(map(lambda f: handle_vpath(f, self.basedir, self.get('VPATH', inherrit=True)), mapped_files))
|
2019-03-28 12:54:56 +00:00
|
|
|
else:
|
|
|
|
result = mapped_files
|
|
|
|
|
|
|
|
# strip ${CMAKE_CURRENT_SOURCE_DIR}:
|
|
|
|
result = list(map(lambda f: f[28:] if f.startswith('${CMAKE_CURRENT_SOURCE_DIR}/') else f, result))
|
|
|
|
|
2019-04-16 14:32:08 +00:00
|
|
|
# strip leading ./:
|
|
|
|
result = list(map(lambda f: trim_leading_dot(f), result))
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
def get_files(self, key: str, *, use_vpath: bool = False,
|
|
|
|
is_include: bool = False) -> typing.List[str]:
|
|
|
|
transformer = lambda scope, files: scope._map_files(files, use_vpath=use_vpath, is_include=is_include)
|
|
|
|
return list(self._evalOps(key, transformer, []))
|
|
|
|
|
2019-02-07 14:30:44 +00:00
|
|
|
def _expand_value(self, value: str) -> typing.List[str]:
|
|
|
|
result = value
|
|
|
|
pattern = re.compile(r'\$\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?')
|
|
|
|
match = re.search(pattern, result)
|
|
|
|
while match:
|
2019-02-11 16:46:31 +00:00
|
|
|
old_result = result
|
2019-02-07 14:30:44 +00:00
|
|
|
if match.group(0) == value:
|
2019-03-28 12:54:56 +00:00
|
|
|
return self.get(match.group(1))
|
2019-02-11 16:46:31 +00:00
|
|
|
|
2019-04-11 15:06:01 +00:00
|
|
|
replacement = self.get(match.group(1))
|
2019-02-11 16:46:31 +00:00
|
|
|
replacement_str = replacement[0] if replacement else ''
|
|
|
|
result = result[:match.start()] \
|
|
|
|
+ replacement_str \
|
|
|
|
+ result[match.end():]
|
|
|
|
|
|
|
|
if result == old_result:
|
2019-03-28 12:54:56 +00:00
|
|
|
return [result,] # Do not go into infinite loop
|
2019-02-11 16:46:31 +00:00
|
|
|
|
2019-02-07 14:30:44 +00:00
|
|
|
match = re.search(pattern, result)
|
2019-03-28 12:54:56 +00:00
|
|
|
return [result,]
|
2019-02-07 14:30:44 +00:00
|
|
|
|
2019-02-11 16:46:31 +00:00
|
|
|
def expand(self, key: str) -> typing.List[str]:
|
2019-03-28 12:54:56 +00:00
|
|
|
value = self.get(key)
|
2019-02-07 14:30:44 +00:00
|
|
|
result: typing.List[str] = []
|
|
|
|
assert isinstance(value, list)
|
|
|
|
for v in value:
|
|
|
|
result += self._expand_value(v)
|
|
|
|
return result
|
|
|
|
|
|
|
|
def expandString(self, key: str) -> str:
|
2019-03-28 12:54:56 +00:00
|
|
|
result = self._expand_value(self.get_string(key))
|
2019-02-07 14:30:44 +00:00
|
|
|
assert len(result) == 1
|
|
|
|
return result[0]
|
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
|
|
|
def TEMPLATE(self) -> str:
|
2019-03-28 12:54:56 +00:00
|
|
|
return self.get_string('TEMPLATE', 'app')
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
def _rawTemplate(self) -> str:
|
2019-03-28 12:54:56 +00:00
|
|
|
return self.get_string('TEMPLATE')
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-01-29 09:18:21 +00:00
|
|
|
@property
|
|
|
|
def TARGET(self) -> str:
|
2019-03-28 12:54:56 +00:00
|
|
|
return self.get_string('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-03-28 12:54:56 +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:
|
2019-05-23 13:20:41 +00:00
|
|
|
self.debug = debug
|
|
|
|
self._Grammar = self._generate_grammar()
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-05-23 13:20:41 +00:00
|
|
|
def _generate_grammar(self):
|
2018-10-24 13:20:27 +00:00
|
|
|
# Define grammar:
|
|
|
|
pp.ParserElement.setDefaultWhitespaceChars(' \t')
|
|
|
|
|
2019-05-23 13:20:41 +00:00
|
|
|
def add_element(name: str, value: pp.ParserElement):
|
|
|
|
nonlocal self
|
|
|
|
if self.debug:
|
|
|
|
value.setName(name)
|
|
|
|
value.setDebug()
|
|
|
|
return value
|
|
|
|
|
|
|
|
EOL = add_element('EOL', pp.Suppress(pp.LineEnd()))
|
|
|
|
Else = add_element('Else', pp.Keyword('else'))
|
|
|
|
Identifier = add_element('Identifier', pp.Word(pp.alphas + '_',
|
|
|
|
bodyChars=pp.alphanums+'_-./'))
|
|
|
|
BracedValue = add_element('BracedValue',
|
|
|
|
pp.nestedExpr(
|
|
|
|
ignoreExpr=pp.quotedString |
|
|
|
|
pp.QuotedString(quoteChar='$(',
|
|
|
|
endQuoteChar=')',
|
|
|
|
escQuote='\\',
|
|
|
|
unquoteResults=False)
|
|
|
|
).setParseAction(lambda s, l, t: ['(', *t[0], ')']))
|
2019-02-11 17:02:22 +00:00
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
Substitution \
|
2019-05-23 13:20:41 +00:00
|
|
|
= add_element('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('{')
|
|
|
|
+ Identifier + pp.Optional(pp.nestedExpr())
|
|
|
|
+ pp.Literal('}'))
|
|
|
|
| (pp.Literal('$') + pp.Literal('[') + Identifier
|
|
|
|
+ pp.Literal(']'))
|
|
|
|
))))
|
|
|
|
LiteralValuePart = add_element('LiteralValuePart',
|
|
|
|
pp.Word(pp.printables, excludeChars='$#{}()'))
|
2018-12-21 11:13:38 +00:00
|
|
|
SubstitutionValue \
|
2019-05-23 13:20:41 +00:00
|
|
|
= add_element('SubstitutionValue',
|
|
|
|
pp.Combine(pp.OneOrMore(Substitution
|
|
|
|
| LiteralValuePart
|
|
|
|
| pp.Literal('$'))))
|
|
|
|
Value \
|
|
|
|
= add_element('Value',
|
|
|
|
pp.NotAny(Else | pp.Literal('}') | EOL) \
|
|
|
|
+ (pp.QuotedString(quoteChar='"', escChar='\\')
|
|
|
|
| SubstitutionValue
|
|
|
|
| BracedValue))
|
|
|
|
|
2019-05-23 13:57:59 +00:00
|
|
|
Values = add_element('Values', pp.ZeroOrMore(Value)('value'))
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
Op = add_element('OP',
|
|
|
|
pp.Literal('=') | pp.Literal('-=') | pp.Literal('+=') \
|
|
|
|
| pp.Literal('*='))
|
|
|
|
|
|
|
|
Key = add_element('Key', Identifier)
|
|
|
|
|
2019-05-23 13:57:59 +00:00
|
|
|
Operation = add_element('Operation', Key('key') + Op('operation') + Values('value'))
|
|
|
|
CallArgs = add_element('CallArgs', pp.nestedExpr())
|
2019-03-28 12:25:04 +00:00
|
|
|
|
|
|
|
def parse_call_args(results):
|
|
|
|
out = ''
|
|
|
|
for item in chain(*results):
|
|
|
|
if isinstance(item, str):
|
|
|
|
out += item
|
|
|
|
else:
|
|
|
|
out += "(" + parse_call_args(item) + ")"
|
|
|
|
return out
|
|
|
|
|
|
|
|
CallArgs.setParseAction(parse_call_args)
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
Load = add_element('Load', pp.Keyword('load') + CallArgs('loaded'))
|
|
|
|
Include = add_element('Include', pp.Keyword('include') + CallArgs('included'))
|
|
|
|
Option = add_element('Option', pp.Keyword('option') + CallArgs('option'))
|
|
|
|
|
|
|
|
# ignore the whole thing...
|
|
|
|
DefineTestDefinition = add_element(
|
|
|
|
'DefineTestDefinition',
|
|
|
|
pp.Suppress(pp.Keyword('defineTest') + CallArgs
|
|
|
|
+ pp.nestedExpr(opener='{', closer='}', ignoreExpr=pp.LineEnd())))
|
|
|
|
|
|
|
|
# ignore the whole thing...
|
|
|
|
ForLoop = add_element(
|
|
|
|
'ForLoop',
|
|
|
|
pp.Suppress(pp.Keyword('for') + CallArgs
|
|
|
|
+ pp.nestedExpr(opener='{', closer='}', ignoreExpr=pp.LineEnd())))
|
|
|
|
|
|
|
|
# ignore the whole thing...
|
|
|
|
ForLoopSingleLine = add_element(
|
|
|
|
'ForLoopSingleLine',
|
2019-05-23 13:57:59 +00:00
|
|
|
pp.Suppress(pp.Keyword('for') + CallArgs + pp.Literal(':') + pp.SkipTo(EOL)))
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
# ignore the whole thing...
|
|
|
|
FunctionCall = add_element('FunctionCall', pp.Suppress(Identifier + pp.nestedExpr()))
|
|
|
|
|
|
|
|
Scope = add_element('Scope', pp.Forward())
|
|
|
|
|
|
|
|
Statement = add_element('Statement',
|
|
|
|
pp.Group(Load | Include | Option | ForLoop | ForLoopSingleLine
|
|
|
|
| DefineTestDefinition | FunctionCall | Operation))
|
|
|
|
StatementLine = add_element('StatementLine', Statement + (EOL | pp.FollowedBy('}')))
|
|
|
|
StatementGroup = add_element('StatementGroup',
|
|
|
|
pp.ZeroOrMore(StatementLine | Scope | pp.Suppress(EOL)))
|
|
|
|
|
|
|
|
Block = add_element('Block',
|
2019-05-23 13:57:59 +00:00
|
|
|
pp.Suppress('{') + pp.Optional(EOL)
|
|
|
|
+ StatementGroup + pp.Optional(EOL)
|
|
|
|
+ pp.Suppress('}') + pp.Optional(EOL))
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
ConditionEnd = add_element('ConditionEnd',
|
|
|
|
pp.FollowedBy((pp.Optional(pp.White())
|
2019-05-23 13:57:59 +00:00
|
|
|
+ (pp.Literal(':')
|
|
|
|
| pp.Literal('{')
|
|
|
|
| pp.Literal('|')))))
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
ConditionPart1 = add_element('ConditionPart1',
|
|
|
|
(pp.Optional('!') + Identifier + pp.Optional(BracedValue)))
|
|
|
|
ConditionPart2 = add_element('ConditionPart2', pp.CharsNotIn('#{}|:=\\\n'))
|
|
|
|
ConditionPart = add_element(
|
|
|
|
'ConditionPart',
|
2019-05-23 13:57:59 +00:00
|
|
|
(ConditionPart1 ^ ConditionPart2) + ConditionEnd)
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
ConditionOp = add_element('ConditionOp', pp.Literal('|') ^ pp.Literal(':'))
|
2019-05-23 13:57:59 +00:00
|
|
|
ConditionWhiteSpace = add_element('ConditionWhiteSpace',
|
|
|
|
pp.Suppress(pp.Optional(pp.White(' '))))
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
ConditionRepeated = add_element('ConditionRepeated',
|
2019-05-23 13:57:59 +00:00
|
|
|
pp.ZeroOrMore(ConditionOp
|
|
|
|
+ ConditionWhiteSpace + ConditionPart))
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
Condition = add_element('Condition', pp.Combine(ConditionPart + ConditionRepeated))
|
2019-02-11 17:02:22 +00:00
|
|
|
Condition.setParseAction(lambda x: ' '.join(x).strip().replace(':', ' && ').strip(' && '))
|
|
|
|
|
2019-05-23 09:53:41 +00:00
|
|
|
# Weird thing like write_file(a)|error() where error() is the alternative condition
|
|
|
|
# which happens to be a function call. In this case there is no scope, but our code expects
|
|
|
|
# a scope with a list of statements, so create a fake empty statement.
|
2019-05-23 13:20:41 +00:00
|
|
|
ConditionEndingInFunctionCall = add_element(
|
|
|
|
'ConditionEndingInFunctionCall', pp.Suppress(ConditionOp) + FunctionCall
|
|
|
|
+ pp.Empty().setParseAction(lambda x: [[]])
|
|
|
|
.setResultsName('statements'))
|
|
|
|
|
|
|
|
SingleLineScope = add_element('SingleLineScope',
|
2019-05-23 13:57:59 +00:00
|
|
|
pp.Suppress(pp.Literal(':'))
|
2019-05-23 13:20:41 +00:00
|
|
|
+ pp.Group(Block | (Statement + EOL))('statements'))
|
2019-05-23 13:57:59 +00:00
|
|
|
MultiLineScope = add_element('MultiLineScope', Block('statements'))
|
2019-05-23 13:20:41 +00:00
|
|
|
|
|
|
|
SingleLineElse = add_element('SingleLineElse',
|
2019-05-23 13:57:59 +00:00
|
|
|
pp.Suppress(pp.Literal(':'))
|
2019-05-23 13:20:41 +00:00
|
|
|
+ (Scope | Block | (Statement + pp.Optional(EOL))))
|
|
|
|
MultiLineElse = add_element('MultiLineElse', Block)
|
|
|
|
ElseBranch = add_element('ElseBranch', pp.Suppress(Else) + (SingleLineElse | MultiLineElse))
|
|
|
|
|
|
|
|
# Scope is already add_element'ed in the forward declaration above.
|
2019-05-23 13:57:59 +00:00
|
|
|
Scope <<= \
|
|
|
|
pp.Group(Condition('condition')
|
|
|
|
+ (SingleLineScope | MultiLineScope | ConditionEndingInFunctionCall)
|
|
|
|
+ pp.Optional(ElseBranch)('else_statements'))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
Grammar = StatementGroup('statements')
|
2019-05-17 16:31:19 +00:00
|
|
|
Grammar.ignore(pp.pythonStyleComment())
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
return Grammar
|
|
|
|
|
|
|
|
def parseFile(self, file: str):
|
|
|
|
print('Parsing \"{}\"...'.format(file))
|
|
|
|
try:
|
2019-02-13 11:24:14 +00:00
|
|
|
with open(file, 'r') as file_fd:
|
|
|
|
contents = file_fd.read()
|
|
|
|
|
|
|
|
old_contents = contents
|
|
|
|
contents = fixup_linecontinuation(contents)
|
2019-05-17 16:31:19 +00:00
|
|
|
contents = fixup_comments(contents)
|
2019-02-13 11:24:14 +00:00
|
|
|
|
|
|
|
if old_contents != contents:
|
|
|
|
print('Warning: Fixed line continuation in .pro-file!\n'
|
|
|
|
' Position information in Parsing output might be wrong!')
|
|
|
|
result = self._Grammar.parseString(contents, parseAll=True)
|
2018-10-24 13:20:27 +00:00
|
|
|
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-05-29 15:39:56 +00:00
|
|
|
# Some hardcoded cases that are too bothersome to generalize.
|
|
|
|
condition = re.sub(r'^qtConfig\(opengl\(es1\|es2\)\?\)$',
|
|
|
|
r'QT_FEATURE_opengl OR QT_FEATURE_opengles2 OR QT_FEATURE_opengles3',
|
|
|
|
condition)
|
|
|
|
condition = re.sub(r'^qtConfig\(opengl\.\*\)$', r'QT_FEATURE_opengl', condition)
|
|
|
|
condition = re.sub(r'^win\*$', r'win', condition)
|
|
|
|
|
2019-06-03 15:42:43 +00:00
|
|
|
def gcc_version_handler(match_obj: re.Match):
|
|
|
|
operator = match_obj.group(1)
|
|
|
|
version_type = match_obj.group(2)
|
|
|
|
if operator == 'equals':
|
|
|
|
operator = 'STREQUAL'
|
|
|
|
elif operator == 'greaterThan':
|
|
|
|
operator = 'STRGREATER'
|
|
|
|
elif operator == 'lessThan':
|
|
|
|
operator = 'STRLESS'
|
|
|
|
|
|
|
|
version = match_obj.group(3)
|
|
|
|
return '(QT_COMPILER_VERSION_{} {} {})'.format(version_type, operator, version)
|
|
|
|
|
|
|
|
# TODO: Possibly fix for other compilers.
|
|
|
|
pattern = r'(equals|greaterThan|lessThan)\(QT_GCC_([A-Z]+)_VERSION,[ ]*([0-9]+)\)'
|
|
|
|
condition = re.sub(pattern, gcc_version_handler, condition)
|
|
|
|
|
|
|
|
# TODO: the current if(...) replacement makes the parentheses
|
|
|
|
# unbalanced when there are nested expressions.
|
|
|
|
# Need to fix this either with pypi regex recursive regexps,
|
|
|
|
# using pyparsing, or some other proper means of handling
|
|
|
|
# balanced parentheses.
|
2019-02-07 14:28:49 +00:00
|
|
|
condition = re.sub(r'\bif\s*\((.*?)\)', r'\1', condition)
|
2019-06-03 15:42:43 +00:00
|
|
|
|
2019-02-07 14:28:49 +00:00
|
|
|
condition = re.sub(r'\bisEmpty\s*\((.*?)\)', r'\1_ISEMPTY', condition)
|
2019-03-01 14:00:19 +00:00
|
|
|
condition = re.sub(r'\bcontains\s*\((.*?),\s*"?(.*?)"?\)',
|
2019-02-07 14:28:49 +00:00
|
|
|
r'\1___contains___\2', condition)
|
2019-03-01 14:00:19 +00:00
|
|
|
condition = re.sub(r'\bequals\s*\((.*?),\s*"?(.*?)"?\)',
|
2019-02-11 10:36:00 +00:00
|
|
|
r'\1___equals___\2', condition)
|
2019-06-03 15:42:43 +00:00
|
|
|
condition = re.sub(r'\bisEqual\s*\((.*?),\s*"?(.*?)"?\)',
|
|
|
|
r'\1___equals___\2', condition)
|
2019-02-07 14:28:49 +00:00
|
|
|
condition = re.sub(r'\s*==\s*', '___STREQUAL___', condition)
|
2019-05-28 12:16:01 +00:00
|
|
|
condition = re.sub(r'\bexists\s*\((.*?)\)', r'EXISTS \1', condition)
|
|
|
|
|
|
|
|
pattern = r'CONFIG\((debug|release),debug\|release\)'
|
|
|
|
match_result = re.match(pattern, condition)
|
|
|
|
if match_result:
|
|
|
|
build_type = match_result.group(1)
|
|
|
|
if build_type == 'debug':
|
|
|
|
build_type = 'Debug'
|
|
|
|
elif build_type == 'release':
|
|
|
|
build_type = 'Release'
|
|
|
|
condition = re.sub(pattern, '(CMAKE_BUILD_TYPE STREQUAL {})'.format(build_type), 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"):
|
2019-03-28 12:54:56 +00:00
|
|
|
part = 'TARGET {}'.format(map_qt_library(feature.group(2)))
|
2018-11-01 13:56:13 +00:00
|
|
|
else:
|
2019-05-08 14:45:25 +00:00
|
|
|
feature_name = featureName(feature.group(2))
|
|
|
|
if feature_name.startswith('system_') and is_known_3rd_party_library(feature_name[7:]):
|
2019-01-28 14:06:44 +00:00
|
|
|
part = 'ON'
|
2019-01-31 15:20:32 +00:00
|
|
|
elif feature == 'dlopen':
|
|
|
|
part = 'ON'
|
2019-01-28 14:06:44 +00:00
|
|
|
else:
|
2019-05-08 14:45:25 +00:00
|
|
|
part = 'QT_FEATURE_' + feature_name
|
2018-10-24 13:20:27 +00:00
|
|
|
else:
|
2019-05-06 10:26:31 +00:00
|
|
|
part = map_platform(part)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
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], *,
|
2019-05-07 09:27:33 +00:00
|
|
|
indent: int = 0, is_example: bool=False) -> None:
|
2018-10-24 13:20:27 +00:00
|
|
|
ind = ' ' * indent
|
2019-03-28 12:54:56 +00:00
|
|
|
for sd in scope.get_files('SUBDIRS'):
|
|
|
|
if os.path.isdir(sd):
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write('{}add_subdirectory({})\n'.format(ind, sd))
|
2019-03-28 12:54:56 +00:00
|
|
|
elif os.path.isfile(sd):
|
|
|
|
subdir_result = parseProFile(sd, debug=False)
|
2018-12-21 11:13:38 +00:00
|
|
|
subdir_scope \
|
2019-03-28 12:54:56 +00:00
|
|
|
= Scope.FromDict(scope, sd,
|
2018-12-21 11:13:38 +00:00
|
|
|
subdir_result.asDict().get('statements'),
|
2019-01-29 09:18:21 +00:00
|
|
|
'', scope.basedir)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-02-15 14:50:24 +00:00
|
|
|
do_include(subdir_scope)
|
2019-05-07 09:27:33 +00:00
|
|
|
cmakeify_scope(subdir_scope, cm_fh, indent=indent, is_example=is_example)
|
2018-10-24 13:20:27 +00:00
|
|
|
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
|
|
|
|
2019-02-13 08:13:37 +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))
|
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
handle_subdir(c, cm_fh, indent=indent + 1, is_example=is_example)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if cond:
|
|
|
|
cm_fh.write('{}endif()\n'.format(ind))
|
|
|
|
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
def sort_sources(sources: typing.List[str]) -> typing.List[str]:
|
2018-12-21 11:13:38 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-05-09 08:02:37 +00:00
|
|
|
def _map_libraries_to_cmake(libraries: typing.List[str],
|
|
|
|
known_libraries: typing.Set[str]) -> typing.List[str]:
|
|
|
|
result = [] # type: typing.List[str]
|
|
|
|
is_framework = False
|
|
|
|
|
|
|
|
for l in libraries:
|
|
|
|
if l == '-framework':
|
|
|
|
is_framework = True
|
|
|
|
continue
|
|
|
|
if is_framework:
|
|
|
|
l = '${FW%s}' % l
|
|
|
|
if l.startswith('-l'):
|
|
|
|
l = l[2:]
|
|
|
|
|
|
|
|
if l.startswith('-'):
|
|
|
|
l = '# Remove: {}'.format(l[1:])
|
|
|
|
else:
|
|
|
|
l = map_3rd_party_library(l)
|
|
|
|
|
|
|
|
if not l or l in result or l in known_libraries:
|
|
|
|
continue
|
|
|
|
|
|
|
|
result.append(l)
|
|
|
|
is_framework = False
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def extract_cmake_libraries(scope: Scope, *, known_libraries: typing.Set[str]=set()) \
|
|
|
|
-> typing.Tuple[typing.List[str], typing.List[str]]:
|
|
|
|
public_dependencies = [] # type: typing.List[str]
|
|
|
|
private_dependencies = [] # type: typing.List[str]
|
|
|
|
|
|
|
|
for key in ['QMAKE_USE', 'LIBS',]:
|
|
|
|
public_dependencies += scope.expand(key)
|
|
|
|
for key in ['QMAKE_USE_PRIVATE', 'QMAKE_USE_FOR_PRIVATE', 'LIBS_PRIVATE',]:
|
|
|
|
private_dependencies += scope.expand(key)
|
|
|
|
|
|
|
|
for key in ['QT_FOR_PRIVATE',]:
|
|
|
|
private_dependencies += [map_qt_library(q) for q in scope.expand(key)]
|
|
|
|
|
|
|
|
for key in ['QT',]:
|
|
|
|
# Qt public libs: These may include FooPrivate in which case we get
|
|
|
|
# a private dependency on FooPrivate as well as a public dependency on Foo
|
|
|
|
for lib in scope.expand(key):
|
|
|
|
mapped_lib = map_qt_library(lib)
|
|
|
|
|
|
|
|
if mapped_lib.endswith('Private'):
|
|
|
|
private_dependencies.append(mapped_lib)
|
|
|
|
public_dependencies.append(mapped_lib[:-7])
|
|
|
|
else:
|
|
|
|
public_dependencies.append(mapped_lib)
|
|
|
|
|
|
|
|
return (_map_libraries_to_cmake(public_dependencies, known_libraries),
|
|
|
|
_map_libraries_to_cmake(private_dependencies, known_libraries))
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2019-05-08 15:00:48 +00:00
|
|
|
def write_list(cm_fh: typing.IO[str], entries: typing.List[str],
|
|
|
|
cmake_parameter: str,
|
|
|
|
indent: int = 0, *,
|
|
|
|
header: str = '', footer: str = ''):
|
|
|
|
if not entries:
|
|
|
|
return
|
|
|
|
|
|
|
|
ind = spaces(indent)
|
|
|
|
extra_indent = ''
|
|
|
|
|
|
|
|
if header:
|
|
|
|
cm_fh.write('{}{}'.format(ind, header))
|
|
|
|
extra_indent += ' '
|
|
|
|
if cmake_parameter:
|
|
|
|
cm_fh.write('{}{}{}\n'.format(ind, extra_indent, cmake_parameter))
|
|
|
|
extra_indent += ' '
|
|
|
|
for s in sort_sources(entries):
|
|
|
|
cm_fh.write('{}{}{}\n'.format(ind, extra_indent, s))
|
|
|
|
if footer:
|
2019-06-04 13:27:48 +00:00
|
|
|
cm_fh.write('{}{}\n'.format(ind, footer))
|
2019-05-08 15:00:48 +00:00
|
|
|
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
def write_source_file_list(cm_fh: typing.IO[str], scope, cmake_parameter: str,
|
|
|
|
keys: typing.List[str], indent: int = 0, *,
|
|
|
|
header: str = '', footer: str = ''):
|
|
|
|
# collect sources
|
|
|
|
sources: typing.List[str] = []
|
|
|
|
for key in keys:
|
|
|
|
sources += scope.get_files(key, use_vpath=True)
|
|
|
|
|
2019-05-08 15:00:48 +00:00
|
|
|
write_list(cm_fh, sources, cmake_parameter, indent, header=header, footer=footer)
|
2019-03-28 12:54:56 +00:00
|
|
|
|
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
def write_all_source_file_lists(cm_fh: typing.IO[str], scope: Scope, header: str, *,
|
2019-06-04 14:19:46 +00:00
|
|
|
indent: int = 0, footer: str = '', extraKeys: typing.List[str]):
|
2019-05-07 09:27:33 +00:00
|
|
|
write_source_file_list(cm_fh, scope, header,
|
2019-06-04 14:19:46 +00:00
|
|
|
['SOURCES', 'HEADERS', 'OBJECTIVE_SOURCES', 'NO_PCH_SOURCES', 'FORMS'] + extraKeys,
|
|
|
|
indent, footer=footer)
|
2019-05-07 09:27:33 +00:00
|
|
|
|
|
|
|
|
2019-05-08 15:00:48 +00:00
|
|
|
def write_defines(cm_fh: typing.IO[str], scope: Scope, cmake_parameter: str, *,
|
2019-05-07 09:27:33 +00:00
|
|
|
indent: int = 0, footer: str = ''):
|
|
|
|
defines = scope.expand('DEFINES')
|
|
|
|
defines += [d[2:] for d in scope.expand('QMAKE_CXXFLAGS') if d.startswith('-D')]
|
2019-05-08 15:00:48 +00:00
|
|
|
defines = [d.replace('=\\\\\\"$$PWD/\\\\\\"',
|
|
|
|
'="${CMAKE_CURRENT_SOURCE_DIR}/"') for d in defines]
|
|
|
|
|
2019-06-04 14:19:46 +00:00
|
|
|
write_list(cm_fh, defines, cmake_parameter, indent, footer=footer)
|
2019-05-08 15:00:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def write_include_paths(cm_fh: typing.IO[str], scope: Scope, cmake_parameter: str, *,
|
2019-05-07 09:27:33 +00:00
|
|
|
indent: int = 0, footer: str = ''):
|
2019-05-08 15:00:48 +00:00
|
|
|
includes = [i.rstrip('/') or ('/') for i in scope.get_files('INCLUDEPATH')]
|
2019-05-07 09:27:33 +00:00
|
|
|
|
2019-06-04 14:19:46 +00:00
|
|
|
write_list(cm_fh, includes, cmake_parameter, indent, footer=footer)
|
2019-05-07 09:27:33 +00:00
|
|
|
|
|
|
|
|
2019-05-08 15:00:48 +00:00
|
|
|
def write_compile_options(cm_fh: typing.IO[str], scope: Scope, cmake_parameter: str, *,
|
2019-05-07 09:27:33 +00:00
|
|
|
indent: int = 0, footer: str = ''):
|
|
|
|
compile_options = [d for d in scope.expand('QMAKE_CXXFLAGS') if not d.startswith('-D')]
|
2019-05-08 15:00:48 +00:00
|
|
|
|
2019-06-04 14:19:46 +00:00
|
|
|
write_list(cm_fh, compile_options, cmake_parameter, indent, footer=footer)
|
2019-05-07 09:27:33 +00:00
|
|
|
|
2019-04-08 12:44:34 +00:00
|
|
|
|
2019-05-09 08:02:37 +00:00
|
|
|
def write_library_section(cm_fh: typing.IO[str], scope: Scope, *,
|
|
|
|
indent: int = 0, known_libraries: typing.Set[str]=set()):
|
|
|
|
(public_dependencies, private_dependencies) \
|
|
|
|
= extract_cmake_libraries(scope, known_libraries=known_libraries)
|
2019-04-08 12:44:34 +00:00
|
|
|
|
2019-05-09 08:02:37 +00:00
|
|
|
write_list(cm_fh, private_dependencies, 'LIBRARIES', indent + 1)
|
|
|
|
write_list(cm_fh, public_dependencies, 'PUBLIC_LIBRARIES', indent + 1)
|
2019-04-08 12:44:34 +00:00
|
|
|
|
|
|
|
|
2019-05-22 13:09:39 +00:00
|
|
|
def write_autogen_section(cm_fh: typing.IO[str], scope: Scope, *,
|
|
|
|
indent: int = 0):
|
|
|
|
forms = scope.get_files('FORMS')
|
|
|
|
if forms:
|
|
|
|
write_list(cm_fh, ['uic'], 'ENABLE_AUTOGEN_TOOLS', indent)
|
|
|
|
|
2019-04-08 12:44:34 +00:00
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def write_sources_section(cm_fh: typing.IO[str], scope: Scope, *,
|
2019-03-12 18:55:51 +00:00
|
|
|
indent: int = 0, known_libraries=set()):
|
2018-10-24 13:20:27 +00:00
|
|
|
ind = spaces(indent)
|
|
|
|
|
2019-03-07 10:06:23 +00:00
|
|
|
# mark RESOURCES as visited:
|
2019-03-28 12:54:56 +00:00
|
|
|
scope.get('RESOURCES')
|
2019-03-07 10:06:23 +00:00
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
write_all_source_file_lists(cm_fh, scope, 'SOURCES', indent=indent + 1)
|
2019-03-07 10:06:23 +00:00
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
write_source_file_list(cm_fh, scope, 'DBUS_ADAPTOR_SOURCES', ['DBUS_ADAPTORS',], indent + 1)
|
2019-03-28 14:31:07 +00:00
|
|
|
dbus_adaptor_flags = scope.expand('QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS')
|
|
|
|
if dbus_adaptor_flags:
|
|
|
|
cm_fh.write('{} DBUS_ADAPTOR_FLAGS\n'.format(ind))
|
|
|
|
cm_fh.write('{} "{}"\n'.format(ind, '" "'.join(dbus_adaptor_flags)))
|
2019-03-18 18:13:41 +00:00
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
write_source_file_list(cm_fh, scope, 'DBUS_INTERFACE_SOURCES', ['DBUS_INTERFACES',], indent + 1)
|
2019-03-28 14:31:07 +00:00
|
|
|
dbus_interface_flags = scope.expand('QDBUSXML2CPP_INTERFACE_HEADER_FLAGS')
|
|
|
|
if dbus_interface_flags:
|
|
|
|
cm_fh.write('{} DBUS_INTERFACE_FLAGS\n'.format(ind))
|
|
|
|
cm_fh.write('{} "{}"\n'.format(ind, '" "'.join(dbus_interface_flags)))
|
2019-03-18 18:13:41 +00:00
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
write_defines(cm_fh, scope, 'DEFINES', indent=indent + 1)
|
|
|
|
|
|
|
|
write_include_paths(cm_fh, scope, 'INCLUDE_DIRECTORIES', indent=indent + 1)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-05-09 08:02:37 +00:00
|
|
|
write_library_section(cm_fh, scope, indent=indent, known_libraries=known_libraries)
|
2019-03-28 14:08:00 +00:00
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
write_compile_options(cm_fh, scope, 'COMPILE_OPTIONS', indent=indent + 1)
|
2019-01-29 11:07:24 +00:00
|
|
|
|
2019-05-22 13:09:39 +00:00
|
|
|
write_autogen_section(cm_fh, scope, indent=indent + 1)
|
|
|
|
|
2019-01-29 11:07:24 +00:00
|
|
|
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-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-03-12 18:55:51 +00:00
|
|
|
def write_ignored_keys(scope: Scope, indent: str) -> str:
|
2019-01-18 11:43:11 +00:00
|
|
|
result = ''
|
2019-03-12 18:55:51 +00:00
|
|
|
ignored_keys = scope.keys - scope.visited_keys
|
2019-01-18 11:43:11 +00:00
|
|
|
for k in sorted(ignored_keys):
|
2019-02-07 14:30:44 +00:00
|
|
|
if k == '_INCLUDED' or k == 'TARGET' or k == 'QMAKE_DOCS' or k == 'QT_SOURCE_TREE' \
|
2019-03-12 18:55:51 +00:00
|
|
|
or k == 'QT_BUILD_TREE' or k == 'TRACEPOINT_PROVIDER':
|
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)
|
2019-03-12 18:55:51 +00:00
|
|
|
|
|
|
|
if result:
|
|
|
|
result = '\n#### Keys ignored in scope {}:\n{}'.format(scope, result)
|
|
|
|
|
2019-01-18 11:43:11 +00:00
|
|
|
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)
|
2019-02-12 23:15:15 +00:00
|
|
|
return matches, keepers
|
2019-01-23 15:40:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _simplify_expressions(expr, op, matches, replacement):
|
2019-02-12 23:15:15 +00:00
|
|
|
for arg in expr.args:
|
2019-01-23 15:40:23 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-02-12 23:15:15 +00:00
|
|
|
def _simplify_os_families(expr, family_members, other_family_members):
|
|
|
|
for family in family_members:
|
|
|
|
for other in other_family_members:
|
|
|
|
if other in family_members:
|
|
|
|
continue # skip those in the sub-family
|
|
|
|
|
|
|
|
f_expr = simplify_logic(family)
|
|
|
|
o_expr = simplify_logic(other)
|
|
|
|
|
|
|
|
expr = _simplify_expressions(expr, And, (f_expr, Not(o_expr)), f_expr)
|
|
|
|
expr = _simplify_expressions(expr, And, (Not(f_expr), o_expr), o_expr)
|
|
|
|
expr = _simplify_expressions(expr, And, (f_expr, o_expr), simplify_logic('false'))
|
|
|
|
return expr
|
|
|
|
|
|
|
|
|
2019-01-23 15:40:23 +00:00
|
|
|
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:
|
2019-02-12 23:15:15 +00:00
|
|
|
windowses = ('WIN32', 'WINRT')
|
2019-01-23 15:40:23 +00:00
|
|
|
apples = ('APPLE_OSX', 'APPLE_UIKIT', 'APPLE_IOS',
|
|
|
|
'APPLE_TVOS', 'APPLE_WATCHOS',)
|
2019-04-02 12:13:27 +00:00
|
|
|
bsds = ('FREEBSD', 'OPENBSD', 'NETBSD',)
|
2019-02-12 23:15:15 +00:00
|
|
|
androids = ('ANDROID', 'ANDROID_EMBEDDED')
|
2019-01-23 15:40:23 +00:00
|
|
|
unixes = ('APPLE', *apples, 'BSD', *bsds, 'LINUX',
|
2019-02-12 23:15:15 +00:00
|
|
|
*androids, 'HAIKU',
|
2019-01-23 15:40:23 +00:00
|
|
|
'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)
|
|
|
|
|
|
|
|
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)
|
2019-02-11 16:52:39 +00:00
|
|
|
expr = _simplify_flavors_in_condition('ANDROID', ('ANDROID_EMBEDDED',), expr)
|
2019-01-23 15:40:23 +00:00
|
|
|
|
2019-02-12 23:15:15 +00:00
|
|
|
# Simplify families of OSes against other families:
|
|
|
|
expr = _simplify_os_families(expr, ('WIN32', 'WINRT'), unixes)
|
|
|
|
expr = _simplify_os_families(expr, androids, unixes)
|
|
|
|
expr = _simplify_os_families(expr, ('BSD', *bsds), unixes)
|
|
|
|
|
|
|
|
for family in ('HAIKU', 'QNX', 'INTEGRITY', 'LINUX', 'VXWORKS'):
|
|
|
|
expr = _simplify_os_families(expr, (family,), unixes)
|
|
|
|
|
2019-01-23 15:40:23 +00:00
|
|
|
# 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 ', ' | ')
|
2019-02-11 17:02:22 +00:00
|
|
|
condition = condition.replace(' ON ', ' true ')
|
|
|
|
condition = condition.replace(' OFF ', ' false ')
|
2019-01-23 15:40:23 +00:00
|
|
|
|
|
|
|
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-02-11 17:02:22 +00:00
|
|
|
return condition or 'ON'
|
2019-01-23 15:40:23 +00:00
|
|
|
|
|
|
|
|
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-02-11 16:53:54 +00:00
|
|
|
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-02-11 16:53:54 +00:00
|
|
|
total_condition = '({}) AND ({})'.format(parent_condition,
|
2019-01-17 16:11:52 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2019-05-08 14:45:25 +00:00
|
|
|
def map_to_cmake_condition(condition: typing.Optional[str]) -> str:
|
2019-03-01 14:00:19 +00:00
|
|
|
condition = re.sub(r'\bQT_ARCH___equals___([a-zA-Z_0-9]*)',
|
2019-05-08 14:45:25 +00:00
|
|
|
r'(TEST_architecture_arch STREQUAL "\1")', condition or '')
|
2019-03-01 14:00:19 +00:00
|
|
|
condition = re.sub(r'\bQT_ARCH___contains___([a-zA-Z_0-9]*)',
|
2019-05-08 14:45:25 +00:00
|
|
|
r'(TEST_architecture_arch STREQUAL "\1")', condition or '')
|
2019-03-01 14:00:19 +00:00
|
|
|
return condition
|
|
|
|
|
|
|
|
|
2019-03-07 10:06:23 +00:00
|
|
|
def write_resources(cm_fh: typing.IO[str], target: str, scope: Scope, indent: int = 0):
|
|
|
|
vpath = scope.expand('VPATH')
|
|
|
|
|
|
|
|
# Handle QRC files by turning them into add_qt_resource:
|
2019-03-28 12:54:56 +00:00
|
|
|
resources = scope.get_files('RESOURCES')
|
2019-03-07 10:06:23 +00:00
|
|
|
qrc_output = ''
|
|
|
|
if resources:
|
|
|
|
qrc_only = True
|
|
|
|
for r in resources:
|
|
|
|
if r.endswith('.qrc'):
|
2019-03-28 12:54:56 +00:00
|
|
|
qrc_output += process_qrc_file(target, r, scope.basedir)
|
2019-03-07 10:06:23 +00:00
|
|
|
else:
|
|
|
|
qrc_only = False
|
|
|
|
|
|
|
|
if not qrc_only:
|
|
|
|
print(' XXXX Ignoring non-QRC file resources.')
|
|
|
|
|
|
|
|
if qrc_output:
|
|
|
|
cm_fh.write('\n# Resources:\n')
|
|
|
|
for line in qrc_output.split('\n'):
|
|
|
|
cm_fh.write(' ' * indent + line + '\n')
|
|
|
|
|
|
|
|
|
2019-01-22 13:20:47 +00:00
|
|
|
def write_extend_target(cm_fh: typing.IO[str], target: str,
|
|
|
|
scope: Scope, indent: int = 0):
|
2019-03-12 18:55:51 +00:00
|
|
|
ind = spaces(indent)
|
2018-10-24 13:20:27 +00:00
|
|
|
extend_qt_io_string = io.StringIO()
|
2019-03-12 18:55:51 +00:00
|
|
|
write_sources_section(extend_qt_io_string, scope)
|
2018-10-24 13:20:27 +00:00
|
|
|
extend_qt_string = extend_qt_io_string.getvalue()
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
extend_scope = '\n{}extend_target({} CONDITION {}\n' \
|
2019-03-12 18:55:51 +00:00
|
|
|
'{}{})\n'.format(ind, target,
|
2019-03-01 14:00:19 +00:00
|
|
|
map_to_cmake_condition(scope.total_condition),
|
2019-03-12 18:55:51 +00:00
|
|
|
extend_qt_string, ind)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if not extend_qt_string:
|
2019-03-12 18:55:51 +00:00
|
|
|
extend_scope = '' # Nothing to report, so don't!
|
2019-01-18 11:43:11 +00:00
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
cm_fh.write(extend_scope)
|
|
|
|
|
2019-03-07 10:06:23 +00:00
|
|
|
write_resources(cm_fh, target, scope, indent)
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
|
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-05-08 14:45:25 +00:00
|
|
|
assert 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
|
|
|
|
|
|
|
|
2019-03-11 14:09:33 +00:00
|
|
|
def write_simd_part(cm_fh: typing.IO[str], target: str, scope: Scope, indent: int = 0):
|
|
|
|
simd_options = [ 'sse2', 'sse3', 'ssse3', 'sse4_1', 'sse4_2', 'aesni', 'shani', 'avx', 'avx2',
|
|
|
|
'avx512f', 'avx512cd', 'avx512er', 'avx512pf', 'avx512dq', 'avx512bw',
|
|
|
|
'avx512vl', 'avx512ifma', 'avx512vbmi', 'f16c', 'rdrnd', 'neon', 'mips_dsp',
|
|
|
|
'mips_dspr2',
|
|
|
|
'arch_haswell', 'avx512common', 'avx512core'];
|
|
|
|
for simd in simd_options:
|
|
|
|
SIMD = simd.upper();
|
2019-03-28 12:54:56 +00:00
|
|
|
write_source_file_list(cm_fh, scope, 'SOURCES',
|
2019-05-08 15:00:48 +00:00
|
|
|
['{}_HEADERS'.format(SIMD),
|
|
|
|
'{}_SOURCES'.format(SIMD),
|
|
|
|
'{}_C_SOURCES'.format(SIMD),
|
|
|
|
'{}_ASM'.format(SIMD)],
|
|
|
|
indent,
|
|
|
|
header = 'add_qt_simd_part({} SIMD {}\n'.format(target, simd),
|
|
|
|
footer = ')\n\n')
|
2019-03-11 14:09:33 +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] = [],
|
2019-03-18 18:16:40 +00:00
|
|
|
indent: int = 0, extra_keys: typing.List[str],
|
|
|
|
**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)
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-03-12 18:55:51 +00:00
|
|
|
scopes[0].reset_visited_keys()
|
2019-03-18 18:16:40 +00:00
|
|
|
for k in extra_keys:
|
|
|
|
scopes[0].get(k)
|
2019-03-12 18:55:51 +00:00
|
|
|
|
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-03-12 18:55:51 +00:00
|
|
|
write_sources_section(cm_fh, scopes[0], indent=indent, **kwargs)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
# Footer:
|
|
|
|
cm_fh.write('{})\n'.format(spaces(indent)))
|
|
|
|
|
2019-03-07 10:06:23 +00:00
|
|
|
write_resources(cm_fh, name, scope, indent)
|
|
|
|
|
2019-03-11 14:09:33 +00:00
|
|
|
write_simd_part(cm_fh, name, scope, indent)
|
|
|
|
|
2019-03-12 18:55:51 +00:00
|
|
|
ignored_keys_report = write_ignored_keys(scopes[0], spaces(indent))
|
|
|
|
if ignored_keys_report:
|
|
|
|
cm_fh.write(ignored_keys_report)
|
|
|
|
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
# 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-03-12 18:55:51 +00:00
|
|
|
c.reset_visited_keys()
|
2019-01-22 13:20:47 +00:00
|
|
|
write_extend_target(cm_fh, name, c, indent=indent)
|
2019-03-12 18:55:51 +00:00
|
|
|
ignored_keys_report = write_ignored_keys(c, spaces(indent))
|
|
|
|
if ignored_keys_report:
|
|
|
|
cm_fh.write(ignored_keys_report)
|
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
|
2019-02-13 12:04:45 +00:00
|
|
|
if not module_name.startswith('Qt'):
|
|
|
|
print('XXXXXX Module name {} does not start with Qt!'.format(module_name))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
extra = []
|
|
|
|
if 'static' in scope.get('CONFIG'):
|
|
|
|
extra.append('STATIC')
|
|
|
|
if 'no_module_headers' in scope.get('CONFIG'):
|
|
|
|
extra.append('NO_MODULE_HEADERS')
|
|
|
|
|
2019-05-29 14:56:49 +00:00
|
|
|
module_config = scope.get("MODULE_CONFIG")
|
|
|
|
if len(module_config):
|
|
|
|
extra.append('QMAKE_MODULE_CONFIG {}'.format(" ".join(module_config)))
|
|
|
|
|
2019-05-03 14:03:15 +00:00
|
|
|
module_plugin_types = scope.get_files('MODULE_PLUGIN_TYPES')
|
|
|
|
if module_plugin_types:
|
|
|
|
extra.append('PLUGIN_TYPES {}'.format(" ".join(module_plugin_types)))
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
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,
|
2019-05-17 15:41:59 +00:00
|
|
|
known_libraries={}, extra_keys=[])
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
if 'qt_tracepoints' in scope.get('CONFIG'):
|
2019-03-28 12:54:56 +00:00
|
|
|
tracepoints = scope.get_files('TRACEPOINT_PROVIDER')
|
2018-12-21 11:13:38 +00:00
|
|
|
cm_fh.write('\n\n{}qt_create_tracepoints({} {})\n'
|
2019-03-28 12:54:56 +00:00
|
|
|
.format(spaces(indent), module_name[2:], ' '.join(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
|
|
|
|
2019-04-16 14:32:08 +00:00
|
|
|
extra = ['BOOTSTRAP'] if 'force_bootstrap' in scope.get('CONFIG') else []
|
2019-03-01 12:32:44 +00:00
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
write_main_part(cm_fh, tool_name, 'Tool', 'add_qt_tool', scope,
|
2019-03-01 12:32:44 +00:00
|
|
|
indent=indent, known_libraries={'Qt::Core', },
|
2019-03-18 18:16:40 +00:00
|
|
|
extra_lines=extra, extra_keys=['CONFIG'])
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
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,
|
2019-03-18 18:16:40 +00:00
|
|
|
indent=indent, known_libraries={'Qt::Core', 'Qt::Test',},
|
|
|
|
extra_keys=[])
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-03-18 18:15:22 +00:00
|
|
|
extra = ['GUI',] if gui else[]
|
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
target_path = scope.get_string('target.path')
|
2019-03-18 18:15:22 +00:00
|
|
|
if target_path:
|
|
|
|
target_path = target_path.replace('$$[QT_INSTALL_EXAMPLES]', '${INSTALL_EXAMPLESDIR}')
|
|
|
|
extra.append('OUTPUT_DIRECTORY "{}"'.format(target_path))
|
|
|
|
if 'target' in scope.get('INSTALLS'):
|
|
|
|
extra.append('INSTALL_DIRECTORY "{}"'.format(target_path))
|
|
|
|
|
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,
|
2019-03-18 18:16:40 +00:00
|
|
|
known_libraries={'Qt::Core', }, extra_keys=['target.path', 'INSTALLS'])
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2019-05-09 08:59:13 +00:00
|
|
|
def write_find_package_section(cm_fh: typing.IO[str],
|
|
|
|
public_libs: typing.List[str],
|
|
|
|
private_libs: typing.List[str], *, indent: int=0):
|
|
|
|
packages = [] # type: typing.List[LibraryMapping]
|
|
|
|
all_libs = public_libs + private_libs
|
|
|
|
|
|
|
|
for l in all_libs:
|
|
|
|
info = find_library_info_for_target(l)
|
|
|
|
if info and info not in packages:
|
|
|
|
packages.append(info)
|
|
|
|
|
|
|
|
ind = spaces(indent)
|
|
|
|
|
|
|
|
for p in packages:
|
|
|
|
cm_fh.write(generate_find_package_info(p, use_qt_find_package=False, indent=indent))
|
|
|
|
|
|
|
|
if packages:
|
|
|
|
cm_fh.write('\n')
|
|
|
|
|
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
def write_example(cm_fh: typing.IO[str], scope: Scope,
|
|
|
|
gui: bool = False, *, indent: int = 0) -> None:
|
|
|
|
binary_name = scope.TARGET
|
|
|
|
assert binary_name
|
|
|
|
|
|
|
|
cm_fh.write('cmake_minimum_required(VERSION 3.14)\n' +
|
2019-05-09 08:59:13 +00:00
|
|
|
'project({} LANGUAGES CXX)\n\n'.format(binary_name) +
|
2019-05-07 09:27:33 +00:00
|
|
|
'set(CMAKE_INCLUDE_CURRENT_DIR ON)\n\n' +
|
|
|
|
'set(CMAKE_AUTOMOC ON)\n' +
|
|
|
|
'set(CMAKE_AUTORCC ON)\n' +
|
|
|
|
'set(CMAKE_AUTOUIC ON)\n\n' +
|
|
|
|
'set(INSTALL_EXAMPLEDIR "examples")\n\n')
|
|
|
|
|
2019-05-09 08:59:13 +00:00
|
|
|
(public_libs, private_libs) = extract_cmake_libraries(scope)
|
|
|
|
write_find_package_section(cm_fh, public_libs, private_libs, indent=indent)
|
|
|
|
|
2019-05-07 09:27:33 +00:00
|
|
|
add_executable = 'add_executable({}'.format(binary_name);
|
|
|
|
if gui:
|
2019-05-09 08:59:13 +00:00
|
|
|
add_executable += ' WIN32 MACOSX_BUNDLE'
|
2019-05-07 09:27:33 +00:00
|
|
|
|
2019-06-04 14:19:46 +00:00
|
|
|
write_all_source_file_lists(cm_fh, scope, add_executable, indent=0, extraKeys = ['RESOURCES'])
|
2019-05-07 09:27:33 +00:00
|
|
|
|
|
|
|
cm_fh.write(')\n')
|
|
|
|
|
2019-06-04 13:28:59 +00:00
|
|
|
write_include_paths(cm_fh, scope, 'target_include_directories({} PUBLIC'.format(binary_name),
|
2019-05-07 09:27:33 +00:00
|
|
|
indent=0, footer=')')
|
2019-06-04 14:19:46 +00:00
|
|
|
write_defines(cm_fh, scope, 'target_compile_definitions({} PUBLIC'.format(binary_name),
|
2019-05-07 09:27:33 +00:00
|
|
|
indent=0, footer=')')
|
2019-05-09 09:07:02 +00:00
|
|
|
write_list(cm_fh, private_libs, '', indent=indent,
|
|
|
|
header='target_link_libraries({} PRIVATE\n'.format(binary_name), footer=')')
|
|
|
|
write_list(cm_fh, public_libs, '', indent=indent,
|
|
|
|
header='target_link_libraries({} PUBLIC\n'.format(binary_name), footer=')')
|
2019-05-07 09:27:33 +00:00
|
|
|
write_compile_options(cm_fh, scope, 'target_compile_options({}'.format(binary_name),
|
|
|
|
indent=0, footer=')')
|
|
|
|
|
2019-05-09 08:59:13 +00:00
|
|
|
cm_fh.write('\ninstall(TARGETS {}\n'.format(binary_name) +
|
|
|
|
' RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"\n' +
|
|
|
|
' BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"\n' +
|
2019-05-07 09:27:33 +00:00
|
|
|
')\n')
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-05-03 14:03:15 +00:00
|
|
|
extra = []
|
|
|
|
|
|
|
|
plugin_type = scope.get_string('PLUGIN_TYPE')
|
|
|
|
if plugin_type:
|
|
|
|
extra.append('TYPE {}'.format(plugin_type))
|
|
|
|
|
|
|
|
plugin_class_name = scope.get_string('PLUGIN_CLASS_NAME')
|
|
|
|
if plugin_class_name:
|
|
|
|
extra.append('CLASS_NAME {}'.format(plugin_class_name))
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
write_main_part(cm_fh, plugin_name, 'Plugin', 'add_qt_plugin', scope,
|
2019-05-03 14:03:15 +00:00
|
|
|
indent=indent, extra_lines=extra, known_libraries={}, extra_keys=[])
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
2018-12-21 11:13:38 +00:00
|
|
|
def handle_app_or_lib(scope: Scope, cm_fh: typing.IO[str], *,
|
2019-05-07 09:27:33 +00:00
|
|
|
indent: int = 0, is_example: bool=False) -> 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'
|
2019-03-28 12:54:56 +00:00
|
|
|
is_plugin = any('qt_plugin' == s for s in scope.get('_LOADED'))
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
if is_lib or 'qt_module' in scope.get('_LOADED'):
|
2019-05-07 09:27:33 +00:00
|
|
|
assert not is_example
|
2018-10-24 13:20:27 +00:00
|
|
|
write_module(cm_fh, scope, indent=indent)
|
|
|
|
elif is_plugin:
|
2019-05-07 09:27:33 +00:00
|
|
|
assert not is_example
|
2018-10-24 13:20:27 +00:00
|
|
|
write_plugin(cm_fh, scope, indent=indent)
|
2019-03-28 12:54:56 +00:00
|
|
|
elif 'qt_tool' in scope.get('_LOADED'):
|
2019-05-07 09:27:33 +00:00
|
|
|
assert not is_example
|
2018-10-24 13:20:27 +00:00
|
|
|
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'):
|
2019-05-07 09:27:33 +00:00
|
|
|
assert not is_example
|
2018-10-24 13:20:27 +00:00
|
|
|
write_test(cm_fh, scope, indent=indent)
|
|
|
|
else:
|
2019-05-17 15:24:15 +00:00
|
|
|
config = scope.get('CONFIG')
|
|
|
|
gui = all(val not in config for val in ['console', 'cmdline'])
|
2019-05-07 09:27:33 +00:00
|
|
|
if is_example:
|
|
|
|
write_example(cm_fh, scope, gui, indent=indent)
|
|
|
|
else:
|
|
|
|
write_binary(cm_fh, scope, gui, indent=indent)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
2019-03-28 12:54:56 +00:00
|
|
|
ind = spaces(indent)
|
|
|
|
write_source_file_list(cm_fh, scope, '',
|
|
|
|
['QMAKE_DOCS',],
|
2019-05-08 15:00:48 +00:00
|
|
|
indent,
|
|
|
|
header = 'add_qt_docs(\n',
|
|
|
|
footer = ')\n')
|
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], *,
|
2019-05-07 09:27:33 +00:00
|
|
|
indent: int = 0, is_example: bool=False) -> None:
|
2019-01-29 09:18:21 +00:00
|
|
|
template = scope.TEMPLATE
|
2018-10-24 13:20:27 +00:00
|
|
|
if template == 'subdirs':
|
2019-05-07 09:27:33 +00:00
|
|
|
handle_subdir(scope, cm_fh, indent=indent, is_example=is_example)
|
2018-11-01 14:52:21 +00:00
|
|
|
elif template in ('app', 'lib'):
|
2019-05-07 09:27:33 +00:00
|
|
|
handle_app_or_lib(scope, cm_fh, indent=indent, is_example=is_example)
|
2018-10-24 13:20:27 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2019-05-04 11:08:19 +00:00
|
|
|
def generate_new_cmakelists(scope: Scope, *, is_example: bool=False) -> None:
|
|
|
|
print('Generating CMakeLists.gen.txt')
|
|
|
|
with open(scope.generated_cmake_lists_path, 'w') as cm_fh:
|
2019-01-29 09:18:21 +00:00
|
|
|
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)))
|
2019-05-07 09:27:33 +00:00
|
|
|
cmakeify_scope(scope, cm_fh, is_example=is_example)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
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-03-28 12:54:56 +00:00
|
|
|
for include_file in scope.get_files('_INCLUDED', is_include=True):
|
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-03-28 12:54:56 +00:00
|
|
|
'', scope.basedir) # This scope will be merged into scope!
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
do_include(include_scope)
|
|
|
|
|
|
|
|
scope.merge(include_scope)
|
|
|
|
|
|
|
|
|
2019-05-04 11:08:19 +00:00
|
|
|
def copy_generated_file_to_final_location(scope: Scope, keep_temporary_files=False) -> None:
|
|
|
|
print('Copying {} to {}'.format(scope.generated_cmake_lists_path,
|
|
|
|
scope.original_cmake_lists_path))
|
|
|
|
copyfile(scope.generated_cmake_lists_path, scope.original_cmake_lists_path)
|
|
|
|
if not keep_temporary_files:
|
|
|
|
os.remove(scope.generated_cmake_lists_path)
|
|
|
|
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
def main() -> None:
|
|
|
|
args = _parse_commandline()
|
|
|
|
|
2018-11-01 14:55:19 +00:00
|
|
|
debug_parsing = args.debug_parser or args.debug
|
|
|
|
|
2019-05-07 14:46:28 +00:00
|
|
|
backup_current_dir = os.getcwd()
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
for file in args.files:
|
2019-05-07 14:46:28 +00:00
|
|
|
new_current_dir = os.path.dirname(file)
|
|
|
|
file_relative_path = os.path.basename(file)
|
2019-05-08 11:14:37 +00:00
|
|
|
if new_current_dir:
|
|
|
|
os.chdir(new_current_dir)
|
2019-05-07 14:46:28 +00:00
|
|
|
|
|
|
|
parseresult = parseProFile(file_relative_path, 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')
|
|
|
|
|
2019-05-07 14:46:28 +00:00
|
|
|
file_scope = Scope.FromDict(None, file_relative_path,
|
2018-12-21 11:13:38 +00:00
|
|
|
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:')
|
2019-05-08 14:45:25 +00:00
|
|
|
file_scope.dump()
|
2018-10-24 13:20:27 +00:00
|
|
|
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:')
|
2019-05-08 14:45:25 +00:00
|
|
|
file_scope.dump()
|
2018-10-24 13:20:27 +00:00
|
|
|
print('\n#### End of full .pro/.pri file structure.\n')
|
|
|
|
|
2019-05-04 11:08:19 +00:00
|
|
|
generate_new_cmakelists(file_scope, is_example=args.is_example)
|
|
|
|
|
|
|
|
copy_generated_file = True
|
|
|
|
if not args.skip_special_case_preservation:
|
|
|
|
debug_special_case = args.debug_special_case_preservation or args.debug
|
|
|
|
handler = SpecialCaseHandler(file_scope.original_cmake_lists_path,
|
|
|
|
file_scope.generated_cmake_lists_path,
|
|
|
|
file_scope.basedir,
|
|
|
|
keep_temporary_files=args.keep_temporary_files,
|
|
|
|
debug=debug_special_case)
|
|
|
|
|
|
|
|
copy_generated_file = handler.handle_special_cases()
|
|
|
|
|
|
|
|
if copy_generated_file:
|
|
|
|
copy_generated_file_to_final_location(file_scope,
|
|
|
|
keep_temporary_files=args.keep_temporary_files)
|
2019-05-07 14:46:28 +00:00
|
|
|
os.chdir(backup_current_dir)
|
2018-10-24 13:20:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|