[jvm-packages] Replaced create_jni.{bat,sh} with a Python version (#2383)
* [jvm-packages] Replaced create_jni.{bat,sh} with a Python version
This allows to have a single script for all platforms.
* [jvm-packages] Added all configuration options to create_jni.py
This commit is contained in:
parent
c82276386d
commit
37c27ab8e8
@ -1,19 +0,0 @@
|
||||
echo "copy native library"
|
||||
set libsource=..\lib\libxgboost4j.so
|
||||
|
||||
if not exist %libsource% (
|
||||
goto end
|
||||
)
|
||||
|
||||
set libfolder=src\main\resources\lib
|
||||
set libpath=%libfolder%\xgboost4j.dll
|
||||
if not exist %libfolder% (mkdir %libfolder%)
|
||||
if exist %libpath% (del %libpath%)
|
||||
copy %libsource% %libpath%
|
||||
echo complete
|
||||
exit
|
||||
|
||||
:end
|
||||
echo "source library not found, please build it first by runing mingw32-make jvm"
|
||||
pause
|
||||
exit
|
||||
109
jvm-packages/create_jni.py
Executable file
109
jvm-packages/create_jni.py
Executable file
@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env python
|
||||
import errno
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from subprocess import check_output
|
||||
|
||||
|
||||
CONFIG = {
|
||||
"USE_OPENMP": "ON",
|
||||
"USE_HDFS": "OFF",
|
||||
"USE_AZURE": "OFF",
|
||||
"USE_S3": "OFF",
|
||||
|
||||
"PLUGIN_UPDATER_GPU": "OFF",
|
||||
"JVM_BINDINGS": "ON"
|
||||
}
|
||||
|
||||
|
||||
@contextmanager
|
||||
def cd(path):
|
||||
path = normpath(path)
|
||||
cwd = os.getcwd()
|
||||
os.chdir(path)
|
||||
print("cd " + path)
|
||||
try:
|
||||
yield path
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
def maybe_makedirs(path):
|
||||
path = normpath(path)
|
||||
print("mkdir -p " + path)
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
|
||||
def run(command, **kwargs):
|
||||
print(command)
|
||||
subprocess.check_call(command, shell=True, **kwargs)
|
||||
|
||||
|
||||
def cp(source, target):
|
||||
source = normpath(source)
|
||||
target = normpath(target)
|
||||
print("cp {0} {1}".format(source, target))
|
||||
shutil.copy(source, target)
|
||||
|
||||
|
||||
def normpath(path):
|
||||
"""Normalize UNIX path to a native path."""
|
||||
return os.path.join(*path.split("/"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if sys.platform == "darwin":
|
||||
# Enable of your compiler supports OpenMP.
|
||||
CONFIG["USE_OPENMP"] = "OFF"
|
||||
os.environ["JAVA_HOME"] = check_output(
|
||||
"/usr/libexec/java_home").strip().decode()
|
||||
|
||||
print("building Java wrapper")
|
||||
with cd(".."):
|
||||
maybe_makedirs("build")
|
||||
with cd("build"):
|
||||
if sys.platform == "win32":
|
||||
# Force x64 build on Windows.
|
||||
maybe_generator = ' -G"Visual Studio 14 Win64"'
|
||||
else:
|
||||
maybe_generator = ""
|
||||
|
||||
args = ["-D{0}:BOOL={1}".format(k, v) for k, v in CONFIG.items()]
|
||||
run("cmake .. " + " ".join(args) + maybe_generator)
|
||||
run("cmake --build .")
|
||||
|
||||
with cd("demo/regression"):
|
||||
run(sys.executable + " mapfeat.py")
|
||||
run(sys.executable + " mknfold.py machine.txt 1")
|
||||
|
||||
print("copying native library")
|
||||
library_name = {
|
||||
"win32": "xgboost4j.dll",
|
||||
"darwin": "libxgboost4j.dylib",
|
||||
"linux2": "libxgboost4j.so"
|
||||
}[sys.platform]
|
||||
maybe_makedirs("xgboost4j/src/main/resources/lib")
|
||||
cp("../lib/" + library_name, "xgboost4j/src/main/resources/lib")
|
||||
|
||||
print("copying pure-Python tracker")
|
||||
cp("../dmlc-core/tracker/dmlc_tracker/tracker.py",
|
||||
"xgboost4j/src/main/resources")
|
||||
|
||||
print("copying train/test files")
|
||||
maybe_makedirs("xgboost4j-spark/src/test/resources")
|
||||
with cd("../demo/regression"):
|
||||
run("{} mapfeat.py".format(sys.executable))
|
||||
run("{} mknfold.py machine.txt 1".format(sys.executable))
|
||||
|
||||
for file in glob.glob("../demo/regression/machine.txt.t*"):
|
||||
cp(file, "xgboost4j-spark/src/test/resources")
|
||||
for file in glob.glob("../demo/data/agaricus.*"):
|
||||
cp(file, "xgboost4j-spark/src/test/resources")
|
||||
@ -1,47 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e -x
|
||||
|
||||
echo "build java wrapper"
|
||||
|
||||
# cd to script's directory
|
||||
pushd `dirname $0` > /dev/null
|
||||
|
||||
#settings according to os
|
||||
dl="so"
|
||||
USE_OMP=ON
|
||||
|
||||
if [ $(uname) == "Darwin" ]; then
|
||||
export JAVA_HOME=$(/usr/libexec/java_home)
|
||||
dl="dylib"
|
||||
#change this to 0 if your compiler support openmp
|
||||
USE_OMP=OFF
|
||||
fi
|
||||
|
||||
cd ..
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake .. -DJVM_BINDINGS:BOOL=ON -DUSE_OPENMP:BOOL=${USE_OMP}
|
||||
make
|
||||
cd ../jvm-packages
|
||||
echo "move native lib"
|
||||
|
||||
libPath="xgboost4j/src/main/resources/lib"
|
||||
if [ ! -d "$libPath" ]; then
|
||||
mkdir -p "$libPath"
|
||||
fi
|
||||
|
||||
rm -f xgboost4j/src/main/resources/lib/libxgboost4j.${dl}
|
||||
cp ../lib/libxgboost4j.${dl} xgboost4j/src/main/resources/lib/libxgboost4j.${dl}
|
||||
# copy python to native resources
|
||||
cp ../dmlc-core/tracker/dmlc_tracker/tracker.py xgboost4j/src/main/resources/tracker.py
|
||||
# copy test data files
|
||||
mkdir -p xgboost4j-spark/src/test/resources/
|
||||
cd ../demo/regression
|
||||
python mapfeat.py
|
||||
python mknfold.py machine.txt 1
|
||||
cd -
|
||||
cp ../demo/regression/machine.txt.t* xgboost4j-spark/src/test/resources/
|
||||
cp ../demo/data/agaricus.* xgboost4j-spark/src/test/resources/
|
||||
popd > /dev/null
|
||||
echo "complete"
|
||||
@ -11,97 +11,7 @@
|
||||
<artifactId>xgboost4j</artifactId>
|
||||
<version>0.7</version>
|
||||
<packaging>jar</packaging>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>NotWindows</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>!windows</family>
|
||||
</os>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<configuration>
|
||||
<show>protected</show>
|
||||
<nohelp>true</nohelp>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipAssembly>false</skipAssembly>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<version>1.6.0</version>
|
||||
<executions>
|
||||
<execution><!-- Run our version calculation script -->
|
||||
<id>native</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>create_jni.sh</executable>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>Windows</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>windows</family>
|
||||
</os>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<configuration>
|
||||
<show>protected</show>
|
||||
<nohelp>true</nohelp>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipAssembly>false</skipAssembly>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<executions>
|
||||
<execution><!-- Run our version calculation script -->
|
||||
<id>native</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>create_jni.bat</executable>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@ -122,4 +32,45 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<configuration>
|
||||
<show>protected</show>
|
||||
<nohelp>true</nohelp>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipAssembly>false</skipAssembly>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>native</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>python</executable>
|
||||
<arguments>
|
||||
<argument>create_jni.py</argument>
|
||||
</arguments>
|
||||
<workingDirectory>${user.dir}</workingDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user