From a2045472498e3851e0e6d97170952769f14ad9a3 Mon Sep 17 00:00:00 2001 From: "Scheufler, Henning" Date: Mon, 27 Sep 2021 10:30:21 +0200 Subject: [PATCH 1/2] ENH: include additional binaries in the fmu increasing portability --- pythonfmu/builder.py | 26 ++++++++++++++++++- pythonfmu/pythonfmu-export/src/CMakeLists.txt | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pythonfmu/builder.py b/pythonfmu/builder.py index a96d51b3..aa5ddea6 100644 --- a/pythonfmu/builder.py +++ b/pythonfmu/builder.py @@ -66,6 +66,7 @@ def build_FMU( dest: FilePath = ".", project_files: Iterable[FilePath] = set(), documentation_folder: Optional[FilePath] = None, + binary_files : Optional[FilePath] = None, **options, ) -> Path: script_file = Path(script_file) @@ -164,7 +165,7 @@ def build_FMU( src_binaries.rglob("*.so"), src_binaries.rglob("*.dylib"), ): - relative_f = f.relative_to(src_binaries) + relative_f = f.relative_to(src_binaries) arcname = ( binaries / relative_f.parent @@ -172,6 +173,22 @@ def build_FMU( ) zip_fmu.write(f, arcname=arcname) + if binary_files is not None: + binary_file = Path(binary_files) + if binary_file.is_file(): + with open(binary_file,'r') as bf: + bfs = bf.readlines() + bfs = [line.rstrip() for line in bfs] + + for f in bfs: + f = Path(f) + arcname = ( + binaries + / get_platform() + / f.name + ) + zip_fmu.write(f, arcname=arcname) + # Add the documentation folder if documentation_folder is not None: documentation = Path("documentation") @@ -217,6 +234,13 @@ def create_command_parser(parser: argparse.ArgumentParser): default=None ) + parser.add_argument( + "--binary_file", + dest="binary_files", + help="will copy the files list in the binary file in binary folder enabling better portability", + default=None + ) + for option in FMI2_MODEL_OPTIONS: action = "store_false" if option.value else "store_true" parser.add_argument( diff --git a/pythonfmu/pythonfmu-export/src/CMakeLists.txt b/pythonfmu/pythonfmu-export/src/CMakeLists.txt index b2314d5f..52759262 100644 --- a/pythonfmu/pythonfmu-export/src/CMakeLists.txt +++ b/pythonfmu/pythonfmu-export/src/CMakeLists.txt @@ -17,6 +17,9 @@ set(sources pythonfmu/PySlaveInstance.cpp ) +SET (CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN'") + add_library(pythonfmu-export ${sources} ${headers}) target_compile_features(pythonfmu-export PUBLIC "cxx_std_17") From a9cb8e6b6b8998b2f910dac66d3f582bfdc910a4 Mon Sep 17 00:00:00 2001 From: "Scheufler, Henning" Date: Sun, 10 Oct 2021 22:12:00 +0200 Subject: [PATCH 2/2] BUG: builder was adding possiblity non-existing binaries --- pythonfmu/builder.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pythonfmu/builder.py b/pythonfmu/builder.py index aa5ddea6..de0186b3 100644 --- a/pythonfmu/builder.py +++ b/pythonfmu/builder.py @@ -180,14 +180,14 @@ def build_FMU( bfs = bf.readlines() bfs = [line.rstrip() for line in bfs] - for f in bfs: - f = Path(f) - arcname = ( - binaries - / get_platform() - / f.name - ) - zip_fmu.write(f, arcname=arcname) + for f in bfs: + f = Path(f) + arcname = ( + binaries + / get_platform() + / f.name + ) + zip_fmu.write(f, arcname=arcname) # Add the documentation folder if documentation_folder is not None: