From e9eead6ad85b333d93fdac028dfa3896e5007155 Mon Sep 17 00:00:00 2001 From: "Gregory S. Tucker" Date: Mon, 30 Sep 2024 16:27:06 +0200 Subject: [PATCH] [Add] support for @LIBRARYFLAGS@ replacements (#78) * [Add] support for @LIBRARYFLAGS@ replacements --- src/mccode_antlr/config/platforms.yaml | 6 ++++++ src/mccode_antlr/instr/instr.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/mccode_antlr/config/platforms.yaml b/src/mccode_antlr/config/platforms.yaml index 1bc9348..e858efe 100644 --- a/src/mccode_antlr/config/platforms.yaml +++ b/src/mccode_antlr/config/platforms.yaml @@ -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 @@ -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 @@ -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 diff --git a/src/mccode_antlr/instr/instr.py b/src/mccode_antlr/instr/instr.py index c37dde0..cfe89e2 100644 --- a/src/mccode_antlr/instr/instr.py +++ b/src/mccode_antlr/instr/instr.py @@ -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 @@ -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])