-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathbuild-osx-app.sh
executable file
·184 lines (144 loc) · 4.86 KB
/
build-osx-app.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
#!/bin/bash -e
# Build an OSX Applicaiton (.app) for Orange Canvas
#
# Example:
#
# $ build-osx-app.sh $HOME/Applications/Orange.app
#
function print_usage() {
echo 'build-osx-app.sh [-i] [--template] Orange.app
Build an Orange Canvas OSX application bundle (Orange.app).
NOTE: this script should be run from the source root directory.
Options:
--template TEMPLATE_URL Path or url to an application template as build
by "build-osx-app-template.sh. If not provided
a default one will be downloaded.
-i --inplace The provided target application path is already
a template into which Orange should be installed
(this flag cannot be combined with --template).
-h --help Print this help'
}
while [[ ${1:0:1} = "-" ]]; do
case $1 in
--template)
TEMPLATE_URL=$2
shift 2;
;;
-i|--inplace)
INPLACE=1
shift 1
;;
-h|--help)
print_usage
exit 0
;;
-*)
echo "Unknown argument $1"
print_usage
exit 1
;;
esac
done
# extended glob expansion / fail on filename expansion
shopt -s extglob failglob
if [[ ! -f setup.py ]]; then
echo "This script must be run from the source root directory!"
print_usage
exit 1
fi
APP=${1:-dist/Orange.app}
if [[ $INPLACE ]]; then
if [[ $TEMPLATE_URL ]]; then
echo "--inplace and --template can not be combined"
print_usage
exit 1
fi
if [[ -e $APP && ! -d $APP ]]; then
echo "$APP exists and is not a directory"
print_usage
exit 1
fi
fi
TEMPLATE_URL=${TEMPLATE_URL:-"http://orange.biolab.si/download/files/bundle-templates/Orange.app-template.tar.gz"}
SCHEMA_REGEX='^(https?|ftp|local)://.*'
if [[ ! $INPLACE ]]; then
BUILD_DIR=$(mktemp -d -t orange-build)
echo "Retrieving a template from $TEMPLATE_URL"
# check for a url schema
if [[ $TEMPLATE_URL =~ $SCHEMA_REGEX ]]; then
curl --fail --silent -L --max-redirs 2 "$TEMPLATE_URL" | tar -x -C "$BUILD_DIR"
TEMPLATE=( $BUILD_DIR/*.app )
elif [[ -d $TEMPLATE_URL ]]; then
cp -a $TEMPLATE_URL $BUILD_DIR
TEMPLATE=$BUILD_DIR/$(basename "$TEMPLATE_URL")
elif [[ -e $TEMPLATE_URL ]]; then
# Assumed to be an archive
tar -xf "$TEMPLATE_URL" -C "$BUILD_DIR"
TEMPLATE=( $BUILD_DIR/*.app )
else
echo "Invalid --template $TEMPLATE_URL"
exit 1
fi
else
TEMPLATE=$APP
fi
echo "Building application in $TEMPLATE"
PYTHON=$TEMPLATE/Contents/MacOS/python
PIP=$TEMPLATE/Contents/MacOS/pip
PREFIX=$("$PYTHON" -c'import sys; print sys.prefix')
SITE_PACKAGES=$("$PYTHON" -c'import sysconfig as sc; print(sc.get_path("platlib"))')
echo "Building Orange"
echo "==============="
"$PYTHON" setup.py build
echo "Building orangeqt extension"
echo "==========================="
FDIR=$TEMPLATE/Contents/Frameworks
# to find moc executable in the app bundle
EXTRA_PATH=$PREFIX/bin:$TEMPLATE/Contents/Resources/Qt4/bin
# for the compiler to find Qt's headers and frameworks
EXTRA_CXXFLAGS="-F$FDIR -I$FDIR/QtCore.framework/Headers -I$FDIR/QtGui.framework/Headers"
EXTRA_LDFLAGS="-F$FDIR -framework QtCore -framework QtGui"
echo "Fixing sip/pyqt configuration"
sed -i.bak "s@/.*/Orange.app/@$TEMPLATE/@g" "${SITE_PACKAGES}"/PyQt4/pyqtconfig.py
sed -i.bak "s@/.*/Orange.app/@$TEMPLATE/@g" "${SITE_PACKAGES}"/sipconfig.py
(
PATH=$EXTRA_PATH:$PATH
CXXFLAGS=${EXTRA_CXXFLAGS}${CXXFLAGS:+:$CXXFLAGS}
LDFLAGS=${EXTRA_LDFLAGS}:${LDFLAGS:+:$LDFLAGS}
"$PYTHON" setup.py build_pyqt_ext
)
echo "Installing Orange"
echo "================="
"$PYTHON" setup.py install
cat <<-'EOF' > "$TEMPLATE"/Contents/MacOS/Orange
#!/bin/bash
unset -v PYTHONPATH
DIRNAME=$(dirname "$0")
source "$DIRNAME"/ENV
# LaunchServices passes the Carbon process identifier to the application with
# -psn parameter - we do not want it
if [[ $1 == -psn_* ]]; then
shift 1
fi
exec -a "$0" "$DIRNAME"/PythonAppStart -m Orange.OrangeCanvas.main "$@"
EOF
chmod +x "$TEMPLATE"/Contents/MacOS/Orange
echo "Installing add ons"
echo "=================="
# Install as eggs. The application's Add-ons dialog has problem with
# upgrading flat installs.
"$PIP" install --egg hg+https://bitbucket.org/biolab/orange-bioinformatics
"$PIP" install --egg hg+https://bitbucket.org/biolab/orange-text
"$PIP" install --egg Orange-Network
echo "Installing optional dependencies"
echo "================================"
"$PIP" install slumber
"$PIP" install --allow-external PIL --allow-unverified PIL PIL
if [[ ! $INPLACE ]]; then
echo "Moving the application to $APP"
if [[ -e $APP ]]; then
rm -rf "$APP"
fi
mkdir -p $(dirname "$APP")
mv "$TEMPLATE" "$APP"
fi