|
1 | 1 | # Override the compile command to include the custom library
|
2 | 2 | import os.path
|
| 3 | +import subprocess |
3 | 4 |
|
4 | 5 | # Access the same parameters that the main configuration uses
|
5 | 6 | stdlibLocation = lit_config.params["LIB"]
|
6 | 7 | compilerLocation = lit_config.params["COMPILER"]
|
7 |
| -rustyRootDirectory = "/home/michael/dev/rusty" |
8 | 8 |
|
| 9 | +# Derive rusty root directory using relative paths |
9 | 10 | test_dir = os.path.dirname(__file__)
|
10 |
| -lib_path = os.path.abspath(test_dir) |
| 11 | +source_path = os.path.abspath(test_dir) |
| 12 | +rustyRootDirectory = os.path.abspath(os.path.join(test_dir, "..", "..", "..", "..")) |
| 13 | + |
| 14 | +# Use tmp directory for compiled library |
| 15 | +tmp_lib_path = "/tmp" |
| 16 | +tmp_lib_file = f"{tmp_lib_path}/libfoo.so" |
| 17 | + |
| 18 | +# Compile foo.c to libfoo.so in the tmp directory |
| 19 | +try: |
| 20 | + lit_config.note(f"Compiling foo.c into {tmp_lib_file}...") |
| 21 | + gcc_cmd = f"gcc -shared -fPIC -o {tmp_lib_file} {source_path}/foo.c" |
| 22 | + lit_config.note(f"Running: {gcc_cmd}") |
| 23 | + result = subprocess.run(gcc_cmd, shell=True, check=True, |
| 24 | + stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 25 | + lit_config.note(f"Successfully compiled {tmp_lib_file}") |
| 26 | +except subprocess.CalledProcessError as e: |
| 27 | + lit_config.error(f"Failed to compile foo.c: {e.stderr.decode()}") |
| 28 | + raise |
11 | 29 |
|
12 | 30 | # Build on the existing compile command but add our custom library
|
13 | 31 | compile = f'{compilerLocation}'
|
14 | 32 | compile = f'{compile} -o /tmp/%basename_t.out'
|
15 | 33 | compile = f'{compile} -liec61131std -L{stdlibLocation}/lib -i "{stdlibLocation}/include/*.st"'
|
| 34 | +# Fix the path to utility files - remove the duplicate "tests/" in the path |
16 | 35 | compile = f'{compile} -i "{rustyRootDirectory}/tests/lit/util/*.pli"'
|
17 |
| -compile = f'{compile} -L{lib_path} -lfoo -i {lib_path}/header.pli' |
| 36 | +compile = f'{compile} -L{tmp_lib_path} -lfoo -i {source_path}/header.pli' |
18 | 37 | compile = f'{compile} --linker=cc'
|
19 | 38 |
|
20 | 39 | # Log the compile command
|
21 | 40 | lit_config.note(f"Compile command: {compile}")
|
22 | 41 |
|
23 | 42 | # Update the run command to include the custom library path
|
24 |
| -run_cmd = f'LD_LIBRARY_PATH="{stdlibLocation}/lib:{lib_path}" /tmp/%basename_t.out' |
| 43 | +run_cmd = f'LD_LIBRARY_PATH="{stdlibLocation}/lib:{tmp_lib_path}" /tmp/%basename_t.out' |
25 | 44 |
|
26 | 45 | # Override the substitutions
|
27 | 46 | config.substitutions = [s for s in config.substitutions if s[0] not in ['%COMPILE', '%RUN']]
|
|
0 commit comments