Return the flag if a flag name is supported on the specified compiler, otherwise None (can be used as a boolean). If multiple flags are passed, return the first that matches.
(compiler: Any, flag: str)
| 227 | |
| 228 | # cf http://bugs.python.org/issue26689 |
| 229 | def has_flag(compiler: Any, flag: str) -> bool: |
| 230 | """ |
| 231 | Return the flag if a flag name is supported on the |
| 232 | specified compiler, otherwise None (can be used as a boolean). |
| 233 | If multiple flags are passed, return the first that matches. |
| 234 | """ |
| 235 | |
| 236 | with tmp_chdir(): |
| 237 | fname = Path("flagcheck.cpp") |
| 238 | # Don't trigger -Wunused-parameter. |
| 239 | fname.write_text("int main (int, char **) { return 0; }", encoding="utf-8") |
| 240 | |
| 241 | try: |
| 242 | compiler.compile([str(fname)], extra_postargs=[flag]) |
| 243 | except distutils.errors.CompileError: |
| 244 | return False |
| 245 | return True |
| 246 | |
| 247 | |
| 248 | # Every call will cache the result |
no test coverage detected