Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Semantics / common.py
blob14323f4a70d87dcc35bc5884a907bf7b0e0d7691
1 """Provides common functionality to the test scripts."""
3 import os
4 import sys
5 from pathlib import Path
7 def set_source(source):
8 """Checks whether the source file exists and returns its path."""
9 if not Path(source).is_file():
10 die(source)
11 return Path(source)
13 def set_executable(executable):
14 """Checks whether a Flang executable has been set and returns its path."""
15 flang_fc1 = Path(executable)
16 if not flang_fc1.is_file():
17 die(flang_fc1)
18 return str(flang_fc1)
20 def set_temp(tmp):
21 """Sets a temporary directory or creates one if it doesn't exist."""
22 os.makedirs(Path(tmp), exist_ok=True)
23 return Path(tmp)
25 def die(file=None):
26 """Used in other functions."""
27 if file is None:
28 print(f"{sys.argv[0]}: FAIL")
29 else:
30 print(f"{sys.argv[0]}: File not found: {file}")
31 sys.exit(1)
33 def check_args(args):
34 """Verifies that 2 arguments have been passed."""
35 if len(args) < 3:
36 print(f"Usage: {args[0]} <fortran-source> <flang-command>")
37 sys.exit(1)
39 def check_args_long(args):
40 """Verifies that 3 arguments have been passed."""
41 if len(args) < 4:
42 print(f"Usage: {args[0]} <fortran-source> <temp-test-dir> <flang-command>")
43 sys.exit(1)