(cmake_files, executable_pattern)
| 36 | |
| 37 | |
| 38 | def build_cmake_tests(cmake_files, executable_pattern): |
| 39 | global build_sub_dir |
| 40 | run_files = [] |
| 41 | |
| 42 | if len(cmake_files) == 0: |
| 43 | return [1, []] |
| 44 | |
| 45 | has_error = False |
| 46 | base_dir = os.getcwd() |
| 47 | build_dir = os.path.join(base_dir, build_sub_dir) |
| 48 | |
| 49 | os.makedirs(name=build_dir, exist_ok=True) |
| 50 | |
| 51 | cmake_args = os.getenv("EXTRA_CMAKE_ARGS") |
| 52 | |
| 53 | parallel_build = os.getenv("PARALLEL_BUILD") |
| 54 | |
| 55 | for cmake_file in cmake_files: |
| 56 | source_dir = os.path.dirname(cmake_file) |
| 57 | module_build_dir = os.path.join(build_dir, source_dir) |
| 58 | os.makedirs(name=module_build_dir, exist_ok=True) |
| 59 | os.chdir(module_build_dir) |
| 60 | |
| 61 | cmake_command = ["cmake"] |
| 62 | if cmake_args is not None: |
| 63 | cmake_command.append(cmake_args) |
| 64 | cmake_command.append(os.path.join(base_dir, source_dir)) |
| 65 | |
| 66 | if sys.platform == "win32": |
| 67 | cmake_command.append("-DBIN_SUB_DIR=/Debug") |
| 68 | |
| 69 | result_code = subprocess.call(cmake_command, shell=False) |
| 70 | if result_code != 0: |
| 71 | print(f"Error with cmake for {source_dir}") |
| 72 | has_error = True |
| 73 | continue |
| 74 | |
| 75 | if parallel_build is not None: |
| 76 | print("building parallel") |
| 77 | result_code = subprocess.call( |
| 78 | ["cmake", "--build", ".", "--parallel", f"{parallel_build}"], |
| 79 | shell=False, |
| 80 | ) |
| 81 | else: |
| 82 | result_code = subprocess.call(["cmake", "--build", "."], shell=False) |
| 83 | |
| 84 | if result_code != 0: |
| 85 | has_error = True |
| 86 | continue |
| 87 | for executable in executable_pattern: |
| 88 | run_files.extend(glob.glob(f"{module_build_dir}{executable}")) |
| 89 | |
| 90 | if has_error: |
| 91 | return [1, []] |
| 92 | else: |
| 93 | return [0, run_files] |
| 94 | |
| 95 |
no test coverage detected