|
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 | 8 | rustyRootDirectory = "/home/michael/dev/rusty"
|
8 | 9 |
|
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 | + |
| 13 | +# Use tmp directory for compiled library |
| 14 | +tmp_lib_path = "/tmp" |
| 15 | +tmp_lib_file = f"{tmp_lib_path}/libfoo.so" |
| 16 | + |
| 17 | +# Compile foo.c to libfoo.so in the tmp directory |
| 18 | +try: |
| 19 | + lit_config.note(f"Compiling foo.c into {tmp_lib_file}...") |
| 20 | + gcc_cmd = f"gcc -shared -fPIC -o {tmp_lib_file} {source_path}/foo.c" |
| 21 | + lit_config.note(f"Running: {gcc_cmd}") |
| 22 | + result = subprocess.run(gcc_cmd, shell=True, check=True, |
| 23 | + stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 24 | + lit_config.note(f"Successfully compiled {tmp_lib_file}") |
| 25 | +except subprocess.CalledProcessError as e: |
| 26 | + lit_config.error(f"Failed to compile foo.c: {e.stderr.decode()}") |
| 27 | + raise |
11 | 28 |
|
12 | 29 | # Build on the existing compile command but add our custom library
|
13 | 30 | compile = f'{compilerLocation}'
|
14 | 31 | compile = f'{compile} -o /tmp/%basename_t.out'
|
15 | 32 | compile = f'{compile} -liec61131std -L{stdlibLocation}/lib -i "{stdlibLocation}/include/*.st"'
|
16 | 33 | compile = f'{compile} -i "{rustyRootDirectory}/tests/lit/util/*.pli"'
|
17 |
| -compile = f'{compile} -L{lib_path} -lfoo -i {lib_path}/header.pli' |
| 34 | +compile = f'{compile} -L{tmp_lib_path} -lfoo -i {source_path}/header.pli' |
18 | 35 | compile = f'{compile} --linker=cc'
|
19 | 36 |
|
20 | 37 | # Log the compile command
|
21 | 38 | lit_config.note(f"Compile command: {compile}")
|
22 | 39 |
|
23 | 40 | # 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' |
| 41 | +run_cmd = f'LD_LIBRARY_PATH="{stdlibLocation}/lib:{tmp_lib_path}" /tmp/%basename_t.out' |
25 | 42 |
|
26 | 43 | # Override the substitutions
|
27 | 44 | config.substitutions = [s for s in config.substitutions if s[0] not in ['%COMPILE', '%RUN']]
|
|
0 commit comments