(compiler, is_cpp, flags, code)
| 204 | compiler.verbose = bk_ver |
| 205 | |
| 206 | def flags_is_required(compiler, is_cpp, flags, code): |
| 207 | if is_cpp: |
| 208 | compiler = compiler.cxx_compiler() |
| 209 | suf = '.cpp' |
| 210 | else: |
| 211 | suf = '.c' |
| 212 | with tempfile.TemporaryDirectory() as temp_dir: |
| 213 | tmp_file = os.path.join(temp_dir, "test" + suf) |
| 214 | with open(tmp_file, "w+") as f: |
| 215 | f.write(code) |
| 216 | # without specify any flags in case of the required |
| 217 | # standard already supported by default, then there's |
| 218 | # no need for passing the flags |
| 219 | comp = try_compile(compiler, tmp_file) |
| 220 | if not comp[0]: |
| 221 | comp = try_compile(compiler, tmp_file, flags) |
| 222 | if not comp[0]: |
| 223 | # rerun to verbose the error |
| 224 | try_compile(compiler, tmp_file, flags, True) |
| 225 | if is_cpp: |
| 226 | raise RuntimeError( |
| 227 | "Broken toolchain during testing C++ compiler. \n" |
| 228 | "A compiler with support for C++17 language " |
| 229 | "features is required.\n" |
| 230 | f"Triggered the following error: {comp[1]}." |
| 231 | ) |
| 232 | else: |
| 233 | raise RuntimeError( |
| 234 | "Broken toolchain during testing C compiler. \n" |
| 235 | "A compiler with support for C99 language " |
| 236 | "features is required.\n" |
| 237 | f"Triggered the following error: {comp[1]}." |
| 238 | ) |
| 239 | return True |
| 240 | return False |
| 241 | |
| 242 | def std_cxx_flags(cmd): |
| 243 | compiler = cmd.compiler |
no test coverage detected