diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-07-30 15:50:22 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-07-31 12:55:33 +0200 |
commit | ca103f357c5dde9d39dc1d42ef53f02b5e632d43 (patch) | |
tree | ca58d48648a43a3da07f211872e18964898fa133 /util/cmake/pro2cmake.py | |
parent | e755ce99d97be26f11c4b49d2a354c464d15dcab (diff) |
CMake: pro2cmake: Reformat files using black
Change-Id: Ic06840f9877d6b863f48a5eb97fcd6735ab9bde8
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Diffstat (limited to 'util/cmake/pro2cmake.py')
-rwxr-xr-x | util/cmake/pro2cmake.py | 139 |
1 files changed, 78 insertions, 61 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 37f0b845f5..fd5410adf6 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -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 |