Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Isolate generation of the NATIVE path for the jar file.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 27 Nov 2013 15:37:49 +0000 (16:37 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 21 Feb 2014 16:05:55 +0000 (17:05 +0100)
Now it can be obtained by running:
    java -classpath simgrid.jar org.simgrid.msg.NativeLib

Use it also when finalizing the jar file.

buildtools/Cmake/DefinePackages.cmake
buildtools/Cmake/MakeJava.cmake
buildtools/Cmake/Scripts/java_bundle.sh [new file with mode: 0755]
src/bindings/java/org/simgrid/msg/Msg.java
src/bindings/java/org/simgrid/msg/NativeLib.java [new file with mode: 0644]

index 9e7f0d7..b2d079e 100644 (file)
@@ -470,12 +470,13 @@ set(JMSG_JAVA_SRC
   src/bindings/java/org/simgrid/msg/Msg.java
   src/bindings/java/org/simgrid/msg/MsgException.java
   src/bindings/java/org/simgrid/msg/Mutex.java
-  src/bindings/java/org/simgrid/msg/Semaphore.java
   src/bindings/java/org/simgrid/msg/NativeException.java
+  src/bindings/java/org/simgrid/msg/NativeLib.java
   src/bindings/java/org/simgrid/msg/Process.java
   src/bindings/java/org/simgrid/msg/ProcessKilledError.java
   src/bindings/java/org/simgrid/msg/ProcessNotFoundException.java
   src/bindings/java/org/simgrid/msg/RngStream.java
+  src/bindings/java/org/simgrid/msg/Semaphore.java
   src/bindings/java/org/simgrid/msg/Task.java
   src/bindings/java/org/simgrid/msg/TaskCancelledException.java
   src/bindings/java/org/simgrid/msg/TimeoutException.java
@@ -1021,6 +1022,7 @@ set(CMAKE_SOURCE_FILES
   buildtools/Cmake/Scripts/SimGrid.packproj
   buildtools/Cmake/Scripts/generate_memcheck_tests.pl
   buildtools/Cmake/Scripts/generate_new_tests.pl
+  buildtools/Cmake/Scripts/java_bundle.sh
   buildtools/Cmake/Scripts/my_valgrind.pl
   buildtools/Cmake/Scripts/postinstall.sh
   buildtools/Cmake/Scripts/preinstall.sh
index 7db344a..9f957f2 100644 (file)
@@ -65,20 +65,6 @@ set(LIBSIMGRID_SO
 set(LIBSIMGRID_JAVA_SO
   ${CMAKE_SHARED_LIBRARY_PREFIX}simgrid-java${CMAKE_SHARED_LIBRARY_SUFFIX})
 
-## Name of the "NATIVE" folder in simgrid.jar
-##
-if(CMAKE_SYSTEM_PROCESSOR MATCHES ".86")
-  if(${ARCH_32_BITS})
-    set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/i386/")
-  else()
-    set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/amd64/")
-  endif()
-else()
-  message(WARNING "Unknown system type. Processor: ${CMAKE_SYSTEM_PROCESSOR}; System: ${CMAKE_SYSTEM_NAME}")
-  set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/")
-endif()
-message("-- [Java] Native libraries bundled into: ${JSG_BUNDLE}")
-
 ## Don't strip libraries if not in release mode
 ##
 if(release)
@@ -96,27 +82,24 @@ else()
   add_jar(simgrid-java_pre_jar ${JMSG_JAVA_SRC} OUTPUT_NAME simgrid)
 endif()
 
+set(JAVA_BUNDLE "${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/java_bundle.sh")
+set(JAVA_BUNDLE_SO_FILES
+  ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}
+  ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_JAVA_SO}
+  )
+set(JAVA_BUNDLE_TXT_FILES
+  ${CMAKE_HOME_DIRECTORY}/COPYING
+  ${CMAKE_HOME_DIRECTORY}/ChangeLog
+  ${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java
+  ${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1
+  )
 add_custom_command(
   COMMENT "Finalize simgrid.jar..."
   OUTPUT ${SIMGRID_JAR}_finalized
   DEPENDS simgrid simgrid-java simgrid-java_pre_jar
           ${SIMGRID_JAR} ${MANIFEST_IN_FILE}
-          ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}
-          ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_JAVA_SO}
-          ${CMAKE_HOME_DIRECTORY}/COPYING
-          ${CMAKE_HOME_DIRECTORY}/ChangeLog
-          ${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java
-          ${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1
-  COMMAND ${CMAKE_COMMAND} -E remove_directory "NATIVE"
-  COMMAND ${CMAKE_COMMAND} -E make_directory "${JSG_BUNDLE}"
-  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}" "${JSG_BUNDLE}"
-  COMMAND ${STRIP_COMMAND} -S "${JSG_BUNDLE}/${LIBSIMGRID_SO}"
-  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_JAVA_SO}" "${JSG_BUNDLE}"
-  COMMAND ${STRIP_COMMAND} -S "${JSG_BUNDLE}/${LIBSIMGRID_JAVA_SO}"
-  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/COPYING" "${JSG_BUNDLE}"
-  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/ChangeLog" "${JSG_BUNDLE}"
-  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java" "${JSG_BUNDLE}"
-  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1" "${JSG_BUNDLE}"
+          ${JAVA_BUNDLE_SO_FILES} ${JAVA_BUNDLE_TXT_FILES}
+  COMMAND ${JAVA_BUNDLE} "${SIMGRID_JAR}" "${Java_JAVA_EXECUTABLE}" "${STRIP_COMMAND}" -so ${JAVA_BUNDLE_SO_FILES} -txt ${JAVA_BUNDLE_TXT_FILES}
   COMMAND ${CMAKE_COMMAND} -E copy ${MANIFEST_IN_FILE} ${MANIFEST_FILE}
   COMMAND ${CMAKE_COMMAND} -E echo "Specification-Version: \\\"${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}\\\"" >> ${MANIFEST_FILE}
   COMMAND ${CMAKE_COMMAND} -E echo "Implementation-Version: \\\"${GIT_VERSION}\\\"" >> ${MANIFEST_FILE}
diff --git a/buildtools/Cmake/Scripts/java_bundle.sh b/buildtools/Cmake/Scripts/java_bundle.sh
new file mode 100755 (executable)
index 0000000..1c232b8
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+set -e
+#set -x
+
+if [ $# -lt 3 ]; then
+    cat >&2 <<EOF
+Usage: $0 simgrid.jar java_command strip_command [-so file.so...] [-txt file.txt...]
+    simgrid.jar    SimGrid jar file
+    java_command   path to the Java runtime
+    strip_command  path to the command used to strip libraries
+    file.so        library file to stript and bundle into the archive
+    file.txt       other file  to bundle into the archive
+EOF
+    exit 1
+fi
+
+SIMGRID_JAR=$1
+JAVA=$2
+STRIP=$3
+shift 3
+
+JSG_BUNDLE=$("$JAVA" -classpath "$SIMGRID_JAR" org.simgrid.msg.NativeLib)
+
+# sanity check
+case "$JSG_BUNDLE" in
+    NATIVE/*)
+        cat >&2 <<EOF
+-- [Java] Native libraries bundled into: ${JSG_BUNDLE}
+EOF
+        ;;
+    *)
+        cat >&2 <<EOF
+-- [Java] Native libraries NOT bundled into invalid directory: ${JSG_BUNDLE}
+EOF
+        exit 1
+        ;;
+esac
+
+# prepare directory
+rm -fr NATIVE
+mkdir -p "$JSG_BUNDLE"
+
+if [ "$1" = "-so" ]; then
+    shift
+    for file; do
+        [ "$file" != "-txt" ] || break
+        cp -f "$file" "$JSG_BUNDLE"
+        "$STRIP" -S "$JSG_BUNDLE/${file##*/}"
+        shift
+    done
+fi
+
+if [ "$1" = "-txt" ]; then
+    shift
+    for file; do
+        cp -f "$file" "$JSG_BUNDLE"
+        shift
+    done
+fi
index 93d4ccd..108c7b5 100644 (file)
@@ -34,19 +34,7 @@ public final class Msg {
                nativeInit();
        }
        private static void loadLib (String name) {
-               String Os = System.getProperty("os.name");
-               String Arch = System.getProperty("os.arch");
-               // Some OS/Arch may be different between Java and Cmake,
-               // which generated the path
-               if (Os.toLowerCase().startsWith("win"))
-                       Os = "Windows";
-               else if (Os.contains("OS X"))
-                       Os = "Darwin";
-               if (Arch.equalsIgnoreCase("x86"))
-                       Arch = "i386";
-               else if (Arch.equalsIgnoreCase("x86_64"))
-                       Arch = "amd64";
-               String Path = "NATIVE/" + Os + "/" + Arch + "/";
+               String Path = NativeLib.getPath();
 
                String filename=name;
                InputStream in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
diff --git a/src/bindings/java/org/simgrid/msg/NativeLib.java b/src/bindings/java/org/simgrid/msg/NativeLib.java
new file mode 100644 (file)
index 0000000..151fb95
--- /dev/null
@@ -0,0 +1,28 @@
+package org.simgrid.msg;
+
+public final class NativeLib {
+    public static String getPath() {
+        String prefix = "NATIVE";
+        String os = System.getProperty("os.name");
+        String arch = System.getProperty("os.arch");
+
+        if (os.toLowerCase().startsWith("^win"))
+            os = "Windows";
+        else if (os.contains("OS X"))
+            os = "Darwin";
+
+        if (arch.matches("^i[3-6]86$"))
+            arch = "x86";
+        else if (arch.equalsIgnoreCase("amd64"))
+            arch = "x86_64";
+
+        os = os.replace(' ', '_');
+        arch = arch.replace(' ', '_');
+
+        return prefix + "/" + os + "/" + arch + "/";
+    }
+
+    public static void main(String[] args) {
+        System.out.println(getPath());
+    }
+}