Skip to content

Commit

Permalink
[Add] support for @LIBRARYFLAGS@ replacements (#78)
Browse files Browse the repository at this point in the history
* [Add] support for @LIBRARYFLAGS@ replacements
  • Loading branch information
g5t authored Sep 30, 2024
1 parent 0a4a96f commit e9eead6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/mccode_antlr/config/platforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Linux:
acc: -lm -fast -Minfo=accel -acc=gpu -gpu=managed -DOPENACC -x c -D_POSIX_C_SOURCE
nexus: -DUSE_NEXUS -lNeXus
mpi: -DUSE_MPI -lmpi
gsl: -lgsl -lgslcblas
xrl: -lxrl
mpi:
cc: mpicc
run: mpirun
Expand All @@ -22,6 +24,8 @@ Darwin:
acc: -lm -ta:multicore -DOPENACC -x c -D_DARWIN_C_SOURCE
nexus: -DUSE_NEXUS -lNeXus
mpi: -DUSE_MPI -lmpi
gsl: -lgsl -lgslcblas
xrl: -lxrl
mpi:
cc: mpicc.clang
run: mpirun
Expand All @@ -36,6 +40,8 @@ Windows:
acc: -lm -ta:multicore -DOPENACC -x c -D_POSIX_C_SOURCE
nexus: -Wl,-rpath,"C:/Program Files/NeXus Data Format/bin" -L"C:/Program Files/NeXus Data Format/bin" -DUSE_NEXUS -lNeXus-0 -I"C:/Program Files/Nexus Data Format/include/nexus"
mpi: -DUSE_MPI -lmsmpi
gsl: -lgsl -lgslcblas
xrl: -lxrl
mpi:
cc: mpicc.bat
run: mpiexec.exe
Expand Down
15 changes: 11 additions & 4 deletions src/mccode_antlr/instr/instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,29 @@ def replace(chars, start, replacer):

def _replace_keywords(self, flag):
from mccode_antlr.config import config
from re import sub
from re import sub, findall
if '@NEXUSFLAGS@' in flag:
flag = sub(r'@NEXUSFLAGS@', config['flags']['nexus'].as_str_expanded(), flag)
if '@MCCODE_LIB@' in flag:
print(f'The instrument {self.name} uses @MCCODE_LIB@ dependencies which no longer work.')
print('Expect problems at compilation.')
flag = sub('@MCCODE_LIB@', '.', flag)
general_re = r'@(\w+)@'
for replace in findall(general_re, flag):
# Is this replacement something like XXXFLAGS?
if replace.lower().endswith('flags') and replace.lower()[:-5] in config['flags']:
flag = sub(f'@{replace}@', config['flags'][replace.lower()[:-5]].as_str_expanded(), flag)
elif replace.lower().endswith('flags'):
# Punt, and just replace with the lowercase version of the keyword -- hopefully this was intended
flag = sub(f'@{replace}@', f'-l{replace.lower()[:-5]}', flag)
else:
logger.warning(f'Unknown keyword @{replace}@ in dependency string')
return flag

def decoded_flags(self) -> list[str]:
# Each 'flag' in self.flags is from a single instrument component DEPENDENCY, and might contain duplicates:
# If we accept that white space differences matter, we can deduplicate the strings 'easily'
unique_flags = set(self.flags)
# logger.debug(f'{unique_flags = }')
# The dependency strings are allowed to contain any of
# '@NEXUSFLAGS@', @MCCODE_LIB@, CMD(...), ENV(...), GETPATH(...)
# each of which should be replaced by ... something. Start by replacing the 'static' (old-style) keywords
Expand Down Expand Up @@ -486,7 +495,5 @@ def check_expr(self, expr: int | float | str | Expr | Value):
return expr




def _join_rawc_tuple(rawc_tuple: tuple[RawC]):
return '\n'.join([str(rc) for rc in rawc_tuple])

0 comments on commit e9eead6

Please sign in to comment.