CMake: pro2cmake: Reformat files using black

Change-Id: Ic06840f9877d6b863f48a5eb97fcd6735ab9bde8
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Alexandru Croitor 2020-07-30 15:50:22 +02:00
parent e755ce99d9
commit ca103f357c
3 changed files with 98 additions and 85 deletions

View File

@ -240,9 +240,11 @@ def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set):
if "condition" in use:
has_condition = True
indentation = " "
condition = map_condition(use['condition'])
condition = map_condition(use["condition"])
cm_fh.write(f"if({condition})\n")
cm_fh.write(f"{indentation}qt_add_qmake_lib_dependency({newlib.soName} {use['lib']})\n")
cm_fh.write(
f"{indentation}qt_add_qmake_lib_dependency({newlib.soName} {use['lib']})\n"
)
if has_condition:
cm_fh.write("endif()\n")
@ -846,10 +848,7 @@ def get_feature_mapping():
"alloc_malloc_h": None,
"alloc_stdlib_h": None,
"build_all": None,
"ccache": {
"autoDetect": "1",
"condition": "QT_USE_CCACHE"
},
"ccache": {"autoDetect": "1", "condition": "QT_USE_CCACHE"},
"compiler-flags": None,
"cross_compile": {"condition": "CMAKE_CROSSCOMPILING"},
"debug_and_release": {
@ -868,9 +867,7 @@ def get_feature_mapping():
"framework": {
"condition": "APPLE AND BUILD_SHARED_LIBS AND NOT CMAKE_BUILD_TYPE STREQUAL Debug"
},
"gc_binaries": {
"condition" : "NOT QT_FEATURE_shared"
},
"gc_binaries": {"condition": "NOT QT_FEATURE_shared"},
"gcc-sysroot": None,
"gcov": None,
"GNUmake": None,
@ -879,10 +876,7 @@ def get_feature_mapping():
"condition": "NOT QT_FEATURE_icu AND QT_FEATURE_textcodec AND NOT WIN32 AND NOT QNX AND NOT ANDROID AND NOT APPLE AND WrapIconv_FOUND",
},
"incredibuild_xge": None,
"ltcg": {
"autoDetect": "1",
"condition": "CMAKE_INTERPROCEDURAL_OPTIMIZATION"
},
"ltcg": {"autoDetect": "1", "condition": "CMAKE_INTERPROCEDURAL_OPTIMIZATION"},
"msvc_mp": None,
"optimize_debug": None,
"optimize_size": None,
@ -898,7 +892,6 @@ def get_feature_mapping():
"autoDetect": "1",
"condition": "BUILD_SHARED_LIBS AND UNIX AND NOT WIN32 AND NOT ANDROID",
},
"shared": {
"condition": "BUILD_SHARED_LIBS",
"output": [
@ -1230,7 +1223,7 @@ def processSummaryHelper(ctx, entries, cm_fh):
report_condition_mapping = {
"(features.rpath || features.rpath_dir) && !features.shared": "(features.rpath || QT_EXTRA_RPATHS) && !features.shared",
"(features.rpath || features.rpath_dir) && var.QMAKE_LFLAGS_RPATH == ''": None
"(features.rpath || features.rpath_dir) && var.QMAKE_LFLAGS_RPATH == ''": None,
}
@ -1354,6 +1347,7 @@ def processSubconfigs(path, ctx, data):
subconfCtx = ctx
processJson(subconfDir, subconfCtx, subconfData)
class special_cased_file:
def __init__(self, base_dir: str, file_name: str):
self.base_dir = base_dir
@ -1375,6 +1369,7 @@ class special_cased_file:
if self.sc_handler.handle_special_cases():
os.replace(self.gen_file_path, self.file_path)
def processJson(path, ctx, data):
ctx["project_dir"] = path
ctx["module"] = data.get("module", "global")
@ -1412,6 +1407,7 @@ def processJson(path, ctx, data):
# do this late:
processSubconfigs(path, ctx, data)
def main():
if len(sys.argv) != 2:
print("This scripts needs one directory to process!")

View File

@ -168,7 +168,9 @@ _qt_library_map = [
"gsttools", "Qt6", "Qt::MultimediaGstTools", extra=["COMPONENTS", "MultimediaGstTools"]
),
LibraryMapping("gui", "Qt6", "Qt::Gui", extra=["COMPONENTS", "Gui"]),
LibraryMapping("platformheaders", "Qt6", "Qt::PlatformHeaders", extra=["COMPONENTS", "PlatformHeaders"]),
LibraryMapping(
"platformheaders", "Qt6", "Qt::PlatformHeaders", extra=["COMPONENTS", "PlatformHeaders"]
),
LibraryMapping("help", "Qt6", "Qt::Help", extra=["COMPONENTS", "Help"]),
LibraryMapping(
"hunspellinputmethod",
@ -219,7 +221,9 @@ _qt_library_map = [
LibraryMapping("nfc", "Qt6", "Qt::Nfc", extra=["COMPONENTS", "Nfc"]),
LibraryMapping("oauth", "Qt6", "Qt::NetworkAuth", extra=["COMPONENTS", "NetworkAuth"]),
LibraryMapping("opcua", "Qt6", "Qt::OpcUa", extra=["COMPONENTS", "OpcUa"]),
LibraryMapping("opcua_private", "Qt6", "Qt::OpcUaPrivate", extra=["COMPONENTS", "OpcUaPrivate"]),
LibraryMapping(
"opcua_private", "Qt6", "Qt::OpcUaPrivate", extra=["COMPONENTS", "OpcUaPrivate"]
),
LibraryMapping("opengl", "Qt6", "Qt::OpenGL", extra=["COMPONENTS", "OpenGL"]),
LibraryMapping(
"openglwidgets", "Qt6", "Qt::OpenGLWidgets", extra=["COMPONENTS", "OpenGLWidgets"]
@ -362,12 +366,8 @@ _qt_library_map = [
"webkitwidgets", "Qt6", "Qt::WebKitWidgets", extra=["COMPONENTS", "WebKitWidgets"]
),
LibraryMapping("zlib", "Qt6", "Qt::Zlib", extra=["COMPONENTS", "Zlib"]),
LibraryMapping(
"httpserver", "Qt6", "Qt::HttpServer", extra=["COMPONENTS", "HttpServer"]
),
LibraryMapping(
"sslserver", "Qt6", "Qt::SslServer", extra=["COMPONENTS", "HttpServer"]
)
LibraryMapping("httpserver", "Qt6", "Qt::HttpServer", extra=["COMPONENTS", "HttpServer"]),
LibraryMapping("sslserver", "Qt6", "Qt::SslServer", extra=["COMPONENTS", "HttpServer"]),
]
# Note that the library map is adjusted dynamically further down.

View File

@ -509,13 +509,13 @@ def write_add_qt_resource_call(
# If a base dir is given, we have to write the source file property
# assignments that disable the quick compiler per file.
if base_dir and skip_qtquick_compiler:
source_file_properties[full_source].append('QT_SKIP_QUICKCOMPILER 1')
source_file_properties[full_source].append("QT_SKIP_QUICKCOMPILER 1")
for full_source in source_file_properties:
per_file_props = source_file_properties[full_source]
if per_file_props:
prop_spaces = " "
per_file_props_joined = f'\n{prop_spaces}'.join(per_file_props)
per_file_props_joined = f"\n{prop_spaces}".join(per_file_props)
output += dedent(
f"""\
set_source_files_properties("{full_source}"
@ -1331,8 +1331,10 @@ class Scope(object):
# Looking at you qmltyperegistrar.pro.
eval_ops_transformer = None
if key.endswith("SOURCES") or key.endswith("HEADERS"):
def file_transformer(scope, files):
return scope._map_files(files)
eval_ops_transformer = file_transformer
return self._evalOps(key, eval_ops_transformer, [], inherit=inherit)
@ -1341,7 +1343,7 @@ class Scope(object):
if len(v) == 0:
return default
if len(v) > 1:
return ' '.join(v)
return " ".join(v)
return v[0]
def _map_files(
@ -2154,8 +2156,12 @@ def write_library_section(
if dep not in public_module_public_deps:
public_module_public_deps.append(dep)
private_module_interface_deps.extend([map_qt_library(q) for q in scope.expand("QT_FOR_PRIVATE")])
private_module_interface_deps.extend(_map_libraries_to_cmake(scope.expand("QMAKE_USE_FOR_PRIVATE"), known_libraries))
private_module_interface_deps.extend(
[map_qt_library(q) for q in scope.expand("QT_FOR_PRIVATE")]
)
private_module_interface_deps.extend(
_map_libraries_to_cmake(scope.expand("QMAKE_USE_FOR_PRIVATE"), known_libraries)
)
write_list(cm_fh, public_module_private_deps, "LIBRARIES", indent + 1)
write_list(cm_fh, public_module_public_deps, "PUBLIC_LIBRARIES", indent + 1)
@ -2336,8 +2342,14 @@ def expand_resource_glob(cm_fh: IO[str], expression: str) -> str:
return expanded_var
def write_resources(cm_fh: IO[str], target: str, scope: Scope, indent: int = 0, is_example=False,
target_ref: str = None):
def write_resources(
cm_fh: IO[str],
target: str,
scope: Scope,
indent: int = 0,
is_example=False,
target_ref: str = None,
):
if target_ref is None:
target_ref = target
# vpath = scope.expand('VPATH')
@ -2478,59 +2490,58 @@ def write_repc_files(cm_fh: IO[str], target: str, scope: Scope, indent: int = 0)
cm_fh.write(")\n")
def write_generic_cmake_command(cm_fh: IO[str], command_name: str, arguments: List[str],
indent: int = 0):
def write_generic_cmake_command(
cm_fh: IO[str], command_name: str, arguments: List[str], indent: int = 0
):
ind = spaces(indent)
arguments_str = " ".join(arguments)
cm_fh.write(f"{ind}{command_name}({arguments_str})\n")
def write_set_target_properties(cm_fh: IO[str],
targets: List[str],
properties: List[str],
indent: int = 0):
def write_set_target_properties(
cm_fh: IO[str], targets: List[str], properties: List[str], indent: int = 0
):
ind = spaces(indent)
command_name = 'set_target_properties'
command_name = "set_target_properties"
arguments_ind = spaces(indent + 1)
prop_pairs = [(properties[i] + ' ' + properties[i + 1]) for i in range(0, len(properties), 2)]
prop_pairs = [(properties[i] + " " + properties[i + 1]) for i in range(0, len(properties), 2)]
properties_str = f"\n{arguments_ind}" + f"\n{arguments_ind}".join(prop_pairs)
if len(targets) == 1:
targets_str = targets[0] + ' '
targets_str = targets[0] + " "
else:
targets_str = f"\n{arguments_ind}" + f"\n{arguments_ind}".join(targets) + f"\n{arguments_ind}"
targets_str = (
f"\n{arguments_ind}" + f"\n{arguments_ind}".join(targets) + f"\n{arguments_ind}"
)
cm_fh.write(f"{ind}{command_name}({targets_str}PROPERTIES{properties_str}\n{ind})\n")
def write_set_source_files_properties(cm_fh: IO[str],
files: List[str],
properties: List[str],
indent: int = 0):
def write_set_source_files_properties(
cm_fh: IO[str], files: List[str], properties: List[str], indent: int = 0
):
ind = spaces(indent)
command_name = 'set_source_files_properties'
command_name = "set_source_files_properties"
arguments_ind = spaces(indent + 1)
prop_pairs = [(properties[i] + ' ' + properties[i + 1]) for i in range(0, len(properties), 2)]
prop_pairs = [(properties[i] + " " + properties[i + 1]) for i in range(0, len(properties), 2)]
properties_str = f"\n{arguments_ind}" + f"\n{arguments_ind}".join(prop_pairs)
if len(files) == 1:
targets_str = files[0] + ' '
targets_str = files[0] + " "
else:
targets_str = f"\n{arguments_ind}" + f"\n{arguments_ind}".join(files) + f"\n{arguments_ind}"
cm_fh.write(f"{ind}{command_name}({targets_str}PROPERTIES{properties_str}\n{ind})\n")
def write_target_sources(cm_fh: IO[str],
target: str,
sources: List[str],
visibility: str = 'PRIVATE',
indent: int = 0):
command_name = 'target_sources'
header = f'{command_name}({target} {visibility}\n'
write_list(cm_fh, sources, '', indent, footer=f')', header=header)
def write_target_sources(
cm_fh: IO[str], target: str, sources: List[str], visibility: str = "PRIVATE", indent: int = 0
):
command_name = "target_sources"
header = f"{command_name}({target} {visibility}\n"
write_list(cm_fh, sources, "", indent, footer=f")", header=header)
def expand_project_requirements(scope: Scope, skip_message: bool = False) -> str:
@ -2553,7 +2564,9 @@ def expand_project_requirements(scope: Scope, skip_message: bool = False) -> str
return requirements
def write_extend_target(cm_fh: IO[str], target: str, scope: Scope, indent: int = 0, target_ref: str = None):
def write_extend_target(
cm_fh: IO[str], target: str, scope: Scope, indent: int = 0, target_ref: str = None
):
if target_ref is None:
target_ref = target
ind = spaces(indent)
@ -2772,7 +2785,7 @@ def is_path_relative_ish(path: str) -> bool:
return False
def absolutify_path(path: str, base_dir: str = '${CMAKE_CURRENT_SOURCE_DIR}') -> str:
def absolutify_path(path: str, base_dir: str = "${CMAKE_CURRENT_SOURCE_DIR}") -> str:
if not path:
return path
if is_path_relative_ish(path):
@ -2792,9 +2805,9 @@ def write_version_part(cm_fh: IO[str], target: str, scope: Scope, indent: int =
properties = []
if version_value:
properties.extend(['QT_TARGET_VERSION', f'"{version_value}"'])
properties.extend(["QT_TARGET_VERSION", f'"{version_value}"'])
if target_description:
properties.extend(['QT_TARGET_DESCRIPTION', f'"{target_description}"'])
properties.extend(["QT_TARGET_DESCRIPTION", f'"{target_description}"'])
if properties:
write_set_target_properties(cm_fh, [target], properties, indent=indent)
@ -2802,15 +2815,16 @@ def write_version_part(cm_fh: IO[str], target: str, scope: Scope, indent: int =
write_scope_condition_end(cm_fh, condition, indent=indent)
def write_darwin_part(cm_fh: IO[str], target: str, scope: Scope, main_scope_target_name: str = '',
indent: int = 0):
def write_darwin_part(
cm_fh: IO[str], target: str, scope: Scope, main_scope_target_name: str = "", indent: int = 0
):
if scope.is_internal_qt_app:
# Embed custom provided Info.plist file.
info_plist = scope.expandString("QMAKE_INFO_PLIST")
info_plist = absolutify_path(info_plist)
icon_path = scope.expandString("ICON")
icon_basename = ''
icon_basename = ""
new_output_name = None
current_scope_output_name = scope.TARGET
@ -2825,20 +2839,21 @@ def write_darwin_part(cm_fh: IO[str], target: str, scope: Scope, main_scope_targ
properties = []
if info_plist:
properties.extend(['MACOSX_BUNDLE_INFO_PLIST', f'"{info_plist}"'])
properties.extend(['MACOSX_BUNDLE', 'TRUE'])
properties.extend(["MACOSX_BUNDLE_INFO_PLIST", f'"{info_plist}"'])
properties.extend(["MACOSX_BUNDLE", "TRUE"])
if icon_path:
properties.extend(['MACOSX_BUNDLE_ICON_FILE', f'"{icon_basename}"'])
properties.extend(["MACOSX_BUNDLE_ICON_FILE", f'"{icon_basename}"'])
if new_output_name:
properties.extend(['OUTPUT_NAME', f'"{new_output_name}"'])
properties.extend(["OUTPUT_NAME", f'"{new_output_name}"'])
if properties:
write_set_target_properties(cm_fh, [target], properties, indent=indent)
if icon_path:
source_properties = ['MACOSX_PACKAGE_LOCATION', 'Resources']
write_set_source_files_properties(cm_fh, [icon_path], source_properties,
indent=indent)
source_properties = ["MACOSX_PACKAGE_LOCATION", "Resources"]
write_set_source_files_properties(
cm_fh, [icon_path], source_properties, indent=indent
)
write_target_sources(cm_fh, target, [icon_path], indent=indent)
write_scope_condition_end(cm_fh, condition, indent=indent)
@ -2858,17 +2873,16 @@ def write_windows_part(cm_fh: IO[str], target: str, scope: Scope, indent: int =
properties = []
if is_console:
properties.extend(['WIN32_EXECUTABLE', 'FALSE'])
properties.extend(["WIN32_EXECUTABLE", "FALSE"])
if rc_file:
properties.extend(['QT_TARGET_WINDOWS_RC_FILE', f'"{rc_file}"'])
properties.extend(["QT_TARGET_WINDOWS_RC_FILE", f'"{rc_file}"'])
if rc_icons:
properties.extend(['QT_TARGET_RC_ICONS', f'"{rc_icons}"'])
properties.extend(["QT_TARGET_RC_ICONS", f'"{rc_icons}"'])
if properties:
write_set_target_properties(cm_fh, [target],
properties, indent=indent)
write_set_target_properties(cm_fh, [target], properties, indent=indent)
write_scope_condition_end(cm_fh, condition, indent=indent)
@ -3259,16 +3273,16 @@ def write_generic_library(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> s
def forward_target_info(scope: Scope, extra: [str], skip: Optional[Dict[str]] = None):
s = scope.get_string("QMAKE_TARGET_PRODUCT")
if s:
extra.append(f"TARGET_PRODUCT \"{s}\"")
extra.append(f'TARGET_PRODUCT "{s}"')
s = scope.get_string("QMAKE_TARGET_DESCRIPTION")
if s and (not skip or 'QMAKE_TARGET_DESCRIPTION' not in skip):
extra.append(f"TARGET_DESCRIPTION \"{s}\"")
if s and (not skip or "QMAKE_TARGET_DESCRIPTION" not in skip):
extra.append(f'TARGET_DESCRIPTION "{s}"')
s = scope.get_string("QMAKE_TARGET_COMPANY")
if s:
extra.append(f"TARGET_COMPANY \"{s}\"")
extra.append(f'TARGET_COMPANY "{s}"')
s = scope.get_string("QMAKE_TARGET_COPYRIGHT")
if s:
extra.append(f"TARGET_COPYRIGHT \"{s}\"")
extra.append(f'TARGET_COPYRIGHT "{s}"')
def write_module(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str:
@ -3369,7 +3383,7 @@ def write_qt_app(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str:
extra = []
target_info_skip = {}
target_info_skip['QMAKE_TARGET_DESCRIPTION'] = True
target_info_skip["QMAKE_TARGET_DESCRIPTION"] = True
forward_target_info(scope, extra, target_info_skip)
write_main_part(
@ -3426,6 +3440,7 @@ def write_test(cm_fh: IO[str], scope: Scope, gui: bool = False, *, indent: int =
return test_name
def write_binary(cm_fh: IO[str], scope: Scope, gui: bool = False, *, indent: int = 0) -> str:
binary_name = scope.TARGET
assert binary_name
@ -3536,7 +3551,9 @@ def write_example(
example_install_dir = scope.expandString("target.path")
if not example_install_dir:
example_install_dir = "${INSTALL_EXAMPLESDIR}"
example_install_dir = example_install_dir.replace("$$[QT_INSTALL_EXAMPLES]", "${INSTALL_EXAMPLESDIR}")
example_install_dir = example_install_dir.replace(
"$$[QT_INSTALL_EXAMPLES]", "${INSTALL_EXAMPLESDIR}"
)
cm_fh.write(
"cmake_minimum_required(VERSION 3.14)\n"
@ -3546,7 +3563,7 @@ def write_example(
"set(CMAKE_AUTORCC ON)\n"
"set(CMAKE_AUTOUIC ON)\n\n"
"if(NOT DEFINED INSTALL_EXAMPLESDIR)\n"
" set(INSTALL_EXAMPLESDIR \"examples\")\n"
' set(INSTALL_EXAMPLESDIR "examples")\n'
"endif()\n\n"
f'set(INSTALL_EXAMPLEDIR "{example_install_dir}")\n\n'
)
@ -4135,8 +4152,8 @@ def handle_top_level_repo_project(scope: Scope, cm_fh: IO[str]):
def create_top_level_cmake_conf():
conf_file_name = ".cmake.conf"
try:
with open(conf_file_name, 'x') as file:
file.write("set(QT_REPO_MODULE_VERSION \"6.0.0\")\n")
with open(conf_file_name, "x") as file:
file.write('set(QT_REPO_MODULE_VERSION "6.0.0")\n')
except FileExistsError as _:
pass