forked from piloubazin/nighres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·221 lines (175 loc) · 6.02 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bash
# set -e -x
#
## SETUP
#
set -euo pipefail
unset CDPATH; cd "$( dirname "${BASH_SOURCE[0]}" )"; cd "$(pwd -P)"
fatal() { echo -e "$1"; exit 1; }
function join_by { local IFS="$1"; shift; echo "$*"; }
cbstools_repo="https://github.com/piloubazin/cbstools-public.git"
imcntk_repo="https://github.com/piloubazin/imcn-imaging.git"
release="release-1.3.0"
# Check the system has the necessary commands
hash wget tar javac jar python3 2>/dev/null || fatal "This script needs the following commands available: wget tar javac jar python3"
# Check for setuptools and wheels
pip_modules=$(python3 -m pip list | tr -s ' ' | cut -f 1 -d ' ')
echo "${pip_modules}" | grep setuptools > /dev/null || fatal 'This script requires setuptools.\nInstall with `python3 -m pip install --upgrade setuptools`'
echo "${pip_modules}" | grep wheel > /dev/null || fatal 'This script requires wheel.\nInstall with `python3 -m pip install --upgrade wheel`'
# echo "Before detection: $JAVA_HOME"
# Set the JAVA_HOME variable if it is not set
detected_home=$(java -XshowSettings:properties -version 2>&1 | tr -d ' '| grep java.home | cut -f 2 -d '=')
export JAVA_HOME=${JAVA_HOME:-"$detected_home"}
# echo "After detection: $JAVA_HOME"
# Check that JCC is installed
echo "${pip_modules}" | grep JCC > /dev/null || fatal 'This script requires JCC.\nInstall with `apt-get install jcc` or equivalent and `python3 -m pip install jcc`'
# Attempt to check for python development headers
# Inspired by https://stackoverflow.com/a/4850603
python_include_path=$(python3 -c "from distutils import sysconfig as s; print(s.get_config_vars()['INCLUDEPY'])")
test -f "${python_include_path}/Python.h" || fatal 'This script requires python development headers.\nInstall with `apt-get install python-dev`, or \n `apt-get install python3-dev`, or equivalent'
#
## COMPILE CBSTOOLS
#
# Get cbstools git clone
test -d cbstools-public && (
cd cbstools-public
#git checkout $release
git checkout master
git pull
cd ..
) || (
git clone $cbstools_repo
cd cbstools-public
#git checkout $release
git checkout master
git pull
cd ..
)
# Java dependencies. Order matters
deps=(
"."
"lib/Jama-mipav.jar"
"lib/commons-math3-3.5.jar"
)
deps_list=$(join_by ":" "${deps[@]}")
# List of library files needed to run the cbstools core functions
source cbstools-lib-files.sh
echo $cbstools_files # result is in $cbstools_files
cbstools_list=$(join_by " " "${cbstools_files[@]}")
# Compilation options
javac_opts=(
# "-d build" # Output dir
"-Xlint:none" # Disable all warnings
# "-server" # ?
"-g" # Generate all debugging info
"-O" # ?
"-deprecation" # Show information about deprecated Java calls
"-encoding UTF-8" # Require UTF-8, rather than platform-specifc
)
echo "Compiling..."
cd cbstools-public
javac -cp ${deps_list} ${javac_opts[@]} ca/concordia/qpi/*/*.java de/mpg/cbs/core/*/*.java $cbstools_list
echo "Assembling..."
mkdir -p ../nighresjava/src
mkdir -p ../nighresjava/lib
#jar cf cbstools.jar de/mpg/cbs/core/*/*.class
jar cf ../nighresjava/src/nighresjava.jar de/mpg/cbs/core/*/*.class ca/concordia/qpi/*/*.class
jar cf ../nighresjava/src/cbstools-lib.jar de/mpg/cbs/*/*.class
cp lib/*.jar ../nighresjava/lib/
cd ..
#
## COMPILE IMCNTK
#
# Get imcntk git clone
test -d imcn-imaging && (
cd imcn-imaging
git checkout master
git pull
cd ..
) || (
git clone $imcntk_repo
cd imcn-imaging
git checkout master
git pull
cd ..
)
# Java dependencies. Order matters
deps=(
"."
"lib/Jama-mipav.jar"
"lib/commons-math3-3.5.jar"
)
deps_list=$(join_by ":" "${deps[@]}")
# List of library files needed to run the cbstools core functions
source imcntk-lib-files.sh
echo $imcntk_files # result is in $cbstools_files
imcntk_list=$(join_by " " "${imcntk_files[@]}")
# Compilation options
javac_opts=(
# "-d build" # Output dir
"-Xlint:none" # Disable all warnings
# "-server" # ?
"-g" # Generate all debugging info
"-O" # ?
"-deprecation" # Show information about deprecated Java calls
"-encoding UTF-8" # Require UTF-8, rather than platform-specifc
)
echo "Compiling..."
cd imcn-imaging
javac -cp ${deps_list} ${javac_opts[@]} nl/uva/imcn/algorithms/*.java $imcntk_list
echo "Assembling..."
jar uf ../nighresjava/src/nighresjava.jar nl/uva/imcn/algorithms/*.class
jar cf ../nighresjava/src/imcntk-lib.jar nl/uva/imcn/libraries/*.class nl/uva/imcn/methods/*.class nl/uva/imcn/structures/*.class nl/uva/imcn/utilities/*.class
cp lib/*.jar ../nighresjava/lib/
cd ..
#
## WRAP TO PYTHON
#
cd nighresjava
jcc_args=(
# All public methods in this JAR will be wrapped
"--jar src/nighresjava.jar"
# Dependencies
"--include src/cbstools-lib.jar"
"--include src/imcntk-lib.jar"
"--include lib/commons-math3-3.5.jar"
"--include lib/Jama-mipav.jar"
# Name the python module
"--python nighresjava"
# Java VM heap size limit
"--maxheap 4096M"
# Compile
"--build"
)
python3 -m jcc ${jcc_args[@]}
# post-processing for Mac users: replace __dir__ variable in __init__.py
sed -i -e 's/__dir__/__ndir__/g' build/nighresjava/__init__.py
#
# Assemble PYPI package
#
echo "Copying necessary files for nires pypi package..."
cp -rv build/nighresjava/ ../
# Find and copy the shared object file for the current architecture
find build/ -type f | grep '.so$' | head -n 1 | xargs -I '{}' -- cp '{}' ../nighresjava/_nighresjava.so
cd ..
echo ""
echo "======="
echo "You should now be able to install nighres with pip"
echo " python3 -m pip install ."
echo "======="
echo ""
#python3 -m pip install .
# Make the python wheel
# PLT=$(uname | tr '[:upper:]' '[:lower:]')
# for now use manylinux
# PLT="manylinux1"
# CPU=$(lscpu | grep -oP 'Architecture:\s*\K.+')
# PY="$(python -V 2>&1)"
# if [[ $PY == *2\.*\.* ]]; then
# python setup.py bdist_wheel --dist-dir dist --plat-name ${PLT}_${CPU} --python-tag py2
# elif [[ $PY == *3\.*\.* ]]; then
# python setup.py bdist_wheel --dist-dir dist --plat-name ${PLT}_${CPU} --python-tag py3
# fi
# remove unused folders (optional, requires re-download
#rm -rf cbstools-public
#rm -rf imcn-imaging