From a54649248107825da45f32edfdc3e9e48418e7ac Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 8 Oct 2019 11:57:27 +0200 Subject: [PATCH] pro2cmake: Allow skipping regeneration of a project via inline marker If a CMakeLists.txt file has the special marker # special case skip regeneration then pro2cmake will skip the convertion of the .pro file that is present in the same folder as the CMakeLists.txt file. The --ignore-skip-marker can be used to force conversion of such a project file. Change-Id: I73aae742d1843148b5c22217cb3fc6b0f8e87b82 Reviewed-by: Simon Hausmann --- util/cmake/pro2cmake.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 64ca5d78d4..dee9da5b56 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -164,6 +164,14 @@ def _parse_commandline(): help="Don't use condition simplifier cache (conversion speed may decrease).", ) + parser.add_argument( + "-i", + "--ignore-skip-marker", + dest="ignore_skip_marker", + action="store_true", + help="If set, pro file will be converted even if skip marker is found in CMakeLists.txt.", + ) + parser.add_argument( "files", metavar="<.pro/.pri file>", @@ -3446,7 +3454,22 @@ def copy_generated_file_to_final_location(scope: Scope, keep_temporary_files=Fal os.remove(scope.generated_cmake_lists_path) -def should_convert_project(project_file_path: str = "") -> bool: +def cmake_project_has_skip_marker(project_file_path: str = "") -> bool: + dir_path = os.path.dirname(project_file_path) + cmake_project_path = os.path.join(dir_path, "CMakeLists.txt") + if not os.path.exists(cmake_project_path): + return False + + with open(cmake_project_path, "r") as file_fd: + contents = file_fd.read() + + if "# special case skip regeneration" in contents: + return True + + return False + + +def should_convert_project(project_file_path: str = "", ignore_skip_marker: bool = False) -> bool: qmake_conf_path = find_qmake_conf(project_file_path) qmake_conf_dir_path = os.path.dirname(qmake_conf_path) @@ -3477,6 +3500,11 @@ def should_convert_project(project_file_path: str = "") -> bool: if skip_certain_tests: return False + # Skip if CMakeLists.txt in the same path as project_file_path has a + # special skip marker. + if not ignore_skip_marker and cmake_project_has_skip_marker(project_file_path): + return False + return True @@ -3499,7 +3527,7 @@ def main() -> None: os.chdir(new_current_dir) project_file_absolute_path = os.path.abspath(file_relative_path) - if not should_convert_project(project_file_absolute_path): + if not should_convert_project(project_file_absolute_path, args.ignore_skip_marker): print(f'Skipping conversion of project: "{project_file_absolute_path}"') continue