From: meklund Date: Thu, 29 Mar 2018 10:53:16 +0000 (+0300) Subject: Changed FMIL core and fragments logic to properly find files X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F1664%2F5;p=simantics%2Ffmil.git Changed FMIL core and fragments logic to properly find files Required .dll and .so files on window and linux are found in fragments .win32, .win64 and .linux64. Added a "Requires-Capability" and "Provides-Capability" tag to the project's MANIFEST.MF files, which now correctly resolves the fragments on Linux and Windows. Also added first build of linux FMI shared object files (still missing FMUSimulator.so!) Amend 1: Updated to tycho 1.1.0 build Amend 2: Added README.md to linux64 FMI Library with build from source instructions Change-Id: I5cfd24d1890c73eb4f39effbb7e26a67ef920df9 --- diff --git a/org.simantics.fmil.core/META-INF/MANIFEST.MF b/org.simantics.fmil.core/META-INF/MANIFEST.MF index ba74f08..7d11554 100644 --- a/org.simantics.fmil.core/META-INF/MANIFEST.MF +++ b/org.simantics.fmil.core/META-INF/MANIFEST.MF @@ -10,3 +10,4 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0", org.slf4j.api, gnu.trove3;bundle-version="3.0.3" Export-Package: org.simantics.fmil.core +Require-Capability: org.simantics.fmil.simulator.implementation.capability;filter:="(type=fmi)";effective:="active" diff --git a/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java b/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java index 41ebf95..3a7c031 100644 --- a/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java +++ b/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java @@ -3,6 +3,7 @@ package org.simantics.fmil.core; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import java.net.URL; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.nio.file.Paths; @@ -13,9 +14,9 @@ import java.util.Set; import java.util.UUID; import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.osgi.framework.Bundle; -import org.simantics.fmil.core.ExecEnvironment.ARCHType; import org.simantics.fmil.core.ExecEnvironment.OSType; import org.simantics.utils.FileUtils; import org.slf4j.Logger; @@ -34,9 +35,9 @@ public class FMIL { */ private static int OK = 0; private static int ERROR = 1; - private static String UNSATISFIED_LINK = "Method not found. DLL might not be loaded properly."; - public static final String TEMP_FMU_DIRECTORY_NAME = "fmil"; - public static String TEMP_FMU_COMMON_DIRECTORY; + private static String UNSATISFIED_LINK = "Method not found. DLL might not be loaded properly."; + public static final String TEMP_FMU_DIRECTORY_NAME = "fmil"; + public static String TEMP_FMU_COMMON_DIRECTORY; public static String LOCK_FILE_NAME = "fmil.lock"; public static Object syncObject = new Object(); @@ -45,35 +46,28 @@ public class FMIL { * Static: load native libraries required for the FMU simulation to work. */ static { - + File[] libraries = new File[2]; - Bundle bundle = null; - ExecEnvironment env = ExecEnvironment.calculate(); - if (env.os == OSType.WINDOWS) { - if (env.arch == ARCHType.X86) { - bundle = Platform.getBundle("org.simantics.fmil.win32"); - } else if (env.arch == ARCHType.X86_64) { - bundle = Platform.getBundle("org.simantics.fmil.win64"); - } - } - - if (bundle != null) { - try{ - String root = FileLocator.getBundleFile(bundle).getAbsolutePath(); -// if (env.arch == ARCHType.X86_64) { -// File newFIle = new File(root, "libraries/libexpat.dll"); -// System.load(newFIle.getAbsolutePath()); -// } -// libraries[0] = new File(root, "libraries/zlibwapi.dll"); -// libraries[1] = new File(root, "libraries/miniunz.dll"); - libraries[0] = new File(root, "libraries/fmilib_shared.dll"); - libraries[1] = new File(root, "libraries/FMUSimulator.dll"); - } - catch (Exception e) { - e.printStackTrace(); + + try { + URL sharedFMILIBUrl = null; + URL simulatorFMIUrl = null; + Bundle b = Platform.getBundle("org.simantics.fmil.core"); + + if (env.os == OSType.WINDOWS) { + sharedFMILIBUrl = FileLocator.find(b, new Path("libraries/fmilib_shared.dll"), null); + simulatorFMIUrl = FileLocator.find(b, new Path("libraries/FMUSimulator.dll"), null); + } else if(env.os == OSType.LINUX) { + sharedFMILIBUrl = FileLocator.find(b, new Path("libraries/libfmilib_shared.so"), null); + simulatorFMIUrl = FileLocator.find(b, new Path("libraries/FMUSimulator.so"), null); } + + libraries[0] = new File(FileLocator.toFileURL(sharedFMILIBUrl).getPath()); + libraries[1] = new File(FileLocator.toFileURL(simulatorFMIUrl).getPath()); + } catch (Exception e) { + LOGGER.error("Failed to resolve native FMU simulation library for execution environment {}.{}", env.os, env.arch, e); } for(File library : libraries) { @@ -873,7 +867,7 @@ public class FMIL { synchronized(syncObject) { try { - // TODO: printtaa id ja name, jotta saadaan virheessä kiinni + // TODO: printtaa id ja name, jotta saadaan virheessä kiinni double result = getRealValue_(getModelIDNew(), variableMap.get(name)); System.err.println("getRealValue " + name + " = " + result); return result; diff --git a/org.simantics.fmil.linux64/META-INF/MANIFEST.MF b/org.simantics.fmil.linux64/META-INF/MANIFEST.MF index 1c60e2b..72adc74 100644 --- a/org.simantics.fmil.linux64/META-INF/MANIFEST.MF +++ b/org.simantics.fmil.linux64/META-INF/MANIFEST.MF @@ -4,7 +4,8 @@ Bundle-Name: FMI Library 64-bit Linux Fragment Bundle-SymbolicName: org.simantics.fmil.linux64 Bundle-Version: 1.0.0.qualifier Bundle-Vendor: Semantum Oy -Fragment-Host: org.simantics.fmil.core;bundle-version="1.0.0" +Fragment-Host: org.simantics.fmil.core Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Eclipse-PlatformFilter: (& (osgi.os=linux) (osgi.arch=x86_64)) Eclipse-BundleShape: dir +Provide-Capability: org.simantics.fmil.simulator.implementation.capability;type:"fmi";effective:="active" diff --git a/org.simantics.fmil.linux64/README.md b/org.simantics.fmil.linux64/README.md new file mode 100644 index 0000000..5511597 --- /dev/null +++ b/org.simantics.fmil.linux64/README.md @@ -0,0 +1,23 @@ +Build FMI Library for Linux: +Download 2.0.3-src.zip from here http://www.jmodelica.org/FMILibrary +Derived guide: http://www.jmodelica.org/page/27916 + +1) Download cmake (apt-get install -y cmake) +2) Unzip the source file to a source directory (/path/to/source) +3) Make an empty build directory (mkdir /path/to/build) +4) Change directory to the build directory +5) cmake /path/to/source +6) make +7) make install test + 7.1) If tests fail, look at the error and fix it + 7.2) Otherwise move on to step 8. +8) Under your build directory should be five files: + - libfmu1_dll_me.so + - libfmu2_dll_me.so + - libfmu1_dll_cs.so + - libfmu2_dll_cs.so + - libfmilib_shared.so +9) Copy the above files to where you want them (i.e. under org.simantics.fmil.linux64 libraries directory) +10) Repeat steps 3 to 9 for "debug" shared objects, but replace the following steps: + "5") cmake -DFMILIB_ENABLE_LOG_LEVEL_DEBUG=ON /path/to/source (note the added param) + "9") Copy the files to libraries/debug directory (instead of libraries) \ No newline at end of file diff --git a/org.simantics.fmil.linux64/libraries/debug/libfmilib_shared.so b/org.simantics.fmil.linux64/libraries/debug/libfmilib_shared.so new file mode 100644 index 0000000..572b3fb Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/debug/libfmilib_shared.so differ diff --git a/org.simantics.fmil.linux64/libraries/debug/libfmu1_dll_cs.so b/org.simantics.fmil.linux64/libraries/debug/libfmu1_dll_cs.so new file mode 100644 index 0000000..b0a3485 Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/debug/libfmu1_dll_cs.so differ diff --git a/org.simantics.fmil.linux64/libraries/debug/libfmu1_dll_me.so b/org.simantics.fmil.linux64/libraries/debug/libfmu1_dll_me.so new file mode 100644 index 0000000..9dd42bb Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/debug/libfmu1_dll_me.so differ diff --git a/org.simantics.fmil.linux64/libraries/debug/libfmu2_dll_cs.so b/org.simantics.fmil.linux64/libraries/debug/libfmu2_dll_cs.so new file mode 100644 index 0000000..4e402f7 Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/debug/libfmu2_dll_cs.so differ diff --git a/org.simantics.fmil.linux64/libraries/debug/libfmu2_dll_me.so b/org.simantics.fmil.linux64/libraries/debug/libfmu2_dll_me.so new file mode 100644 index 0000000..686dea2 Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/debug/libfmu2_dll_me.so differ diff --git a/org.simantics.fmil.linux64/libraries/libfmilib_shared.so b/org.simantics.fmil.linux64/libraries/libfmilib_shared.so new file mode 100644 index 0000000..6e5d495 Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/libfmilib_shared.so differ diff --git a/org.simantics.fmil.linux64/libraries/libfmu1_dll_cs.so b/org.simantics.fmil.linux64/libraries/libfmu1_dll_cs.so new file mode 100644 index 0000000..b0a3485 Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/libfmu1_dll_cs.so differ diff --git a/org.simantics.fmil.linux64/libraries/libfmu1_dll_me.so b/org.simantics.fmil.linux64/libraries/libfmu1_dll_me.so new file mode 100644 index 0000000..9dd42bb Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/libfmu1_dll_me.so differ diff --git a/org.simantics.fmil.linux64/libraries/libfmu2_dll_cs.so b/org.simantics.fmil.linux64/libraries/libfmu2_dll_cs.so new file mode 100644 index 0000000..4e402f7 Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/libfmu2_dll_cs.so differ diff --git a/org.simantics.fmil.linux64/libraries/libfmu2_dll_me.so b/org.simantics.fmil.linux64/libraries/libfmu2_dll_me.so new file mode 100644 index 0000000..686dea2 Binary files /dev/null and b/org.simantics.fmil.linux64/libraries/libfmu2_dll_me.so differ diff --git a/org.simantics.fmil.parent/pom.xml b/org.simantics.fmil.parent/pom.xml index d2cc399..7790ee1 100644 --- a/org.simantics.fmil.parent/pom.xml +++ b/org.simantics.fmil.parent/pom.xml @@ -1,79 +1,84 @@ - - 4.0.0 - org.simantics.fmi - org.simantics.fmil.parent - 0.0.1-SNAPSHOT - pom - - - - master - http://www.simantics.org/download - UTF-8 - 1.0.0 - - - - - - simantics-sdk - p2 - ${simantics-download-site}/${branch-spec}/sdk - - - - - - - org.eclipse.tycho - tycho-compiler-plugin - ${tycho-version} - - -err:-forbidden - - - - org.eclipse.tycho - tycho-maven-plugin - ${tycho-version} - true - - - org.eclipse.tycho - tycho-versions-plugin - ${tycho-version} - - - org.eclipse.tycho - target-platform-configuration - ${tycho-version} - - true - p2 - - - win32 - win32 - x86 - - - win32 - win32 - x86_64 - - - - - - - - - ../org.simantics.fmil.core - ../org.simantics.fmil.feature - ../org.simantics.fmil.linux64 - ../org.simantics.fmil.win32 - ../org.simantics.fmil.win64 - ../org.simantics.fmil.repository - - + + 4.0.0 + org.simantics.fmi + org.simantics.fmil.parent + 0.0.1-SNAPSHOT + pom + + + + master + http://www.simantics.org/download + UTF-8 + 1.1.0 + + + + + + simantics-sdk + p2 + ${simantics-download-site}/${branch-spec}/sdk + + + + + + + org.eclipse.tycho + tycho-compiler-plugin + ${tycho-version} + + -err:-forbidden + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + org.eclipse.tycho + tycho-versions-plugin + ${tycho-version} + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + true + p2 + + + linux + gtk + x86_64 + + + win32 + win32 + x86 + + + win32 + win32 + x86_64 + + + + + + + + + ../org.simantics.fmil.core + ../org.simantics.fmil.feature + ../org.simantics.fmil.linux64 + ../org.simantics.fmil.win32 + ../org.simantics.fmil.win64 + ../org.simantics.fmil.repository + + diff --git a/org.simantics.fmil.win32/META-INF/MANIFEST.MF b/org.simantics.fmil.win32/META-INF/MANIFEST.MF index 4d71f7e..ef755c2 100644 --- a/org.simantics.fmil.win32/META-INF/MANIFEST.MF +++ b/org.simantics.fmil.win32/META-INF/MANIFEST.MF @@ -8,3 +8,4 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Eclipse-PlatformFilter: (& (osgi.os=win32) (osgi.arch=x86)) Bundle-Vendor: Semantum Oy Eclipse-BundleShape: dir +Provide-Capability: org.simantics.fmil.simulator.implementation.capability;type:"fmi";effective:="active" diff --git a/org.simantics.fmil.win64/META-INF/MANIFEST.MF b/org.simantics.fmil.win64/META-INF/MANIFEST.MF index 884cbce..3a45e01 100644 --- a/org.simantics.fmil.win64/META-INF/MANIFEST.MF +++ b/org.simantics.fmil.win64/META-INF/MANIFEST.MF @@ -8,3 +8,4 @@ Fragment-Host: org.simantics.fmil.core;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Eclipse-PlatformFilter: (& (osgi.os=win32) (osgi.arch=x86_64)) Eclipse-BundleShape: dir +Provide-Capability: org.simantics.fmil.simulator.implementation.capability;type:"fmi";effective:="active"