From ce9a1434670196c151c34ce5e0f7ed0718f4215f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Mon, 25 Mar 2019 17:30:16 +0100 Subject: [PATCH] Do not overwrite CMakeLists.txt when running run_pro2cmake One directory may contain many pro files. The generator was happily generating the same CMakeLists.txt for all of them (overwriting). This patch implements a different logic. It tries to find the main pro file and skips others assuming that somehow implicitly they will be incorporated (for example through SUBDIRS). Change-Id: Ie07d75e900a96dd48bf981a896c9dfb920f39a23 Reviewed-by: Tobias Hunger --- util/cmake/run_pro2cmake.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/util/cmake/run_pro2cmake.py b/util/cmake/run_pro2cmake.py index b3a07c75226..47bc6b661f6 100755 --- a/util/cmake/run_pro2cmake.py +++ b/util/cmake/run_pro2cmake.py @@ -41,9 +41,33 @@ pro2cmake = os.path.join(script_path, 'pro2cmake.py') if len(sys.argv) > 1: base_path = os.path.abspath(sys.argv[1]) -failed_files = [] -all_files = glob.glob(os.path.join(base_path, '**/*.pro'), recursive=True) +def find_all_pro_files(): + + def sorter(pro_file: str) -> str: + """ Sorter that tries to prioritize main pro files in a directory. """ + pro_file_without_suffix = pro_file.rsplit('/', 1)[-1][:-4] + dir_name = os.path.dirname(pro_file) + if dir_name.endswith('/' + pro_file_without_suffix): + return dir_name + return dir_name + "/__" + pro_file + + all_files = [] + previous_dir_name: str = None + for pro_file in sorted(glob.glob(os.path.join(base_path, '**/*.pro'), + recursive=True), + key=sorter): + dir_name = os.path.dirname(pro_file) + if dir_name == previous_dir_name: + print("Skipping:", pro_file) + else: + all_files.append(pro_file) + previous_dir_name = dir_name + return all_files + + +failed_files = [] +all_files = find_all_pro_files() files_count = len(all_files) with concurrent.futures.ThreadPoolExecutor(initializer=os.nice, initargs=(10,)) as pool: