forked from virtualstaticvoid/heroku-buildpack-r
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile
executable file
·119 lines (89 loc) · 3.21 KB
/
compile
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
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# fail fast
set -e
# debug
# set -x
shopt -s extglob
function error() {
echo " ! $*" >&2
exit 1
}
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
# clean up leaking environment
unset GIT_DIR
# parse and derive params
BUILD_DIR=$1
CACHE_DIR="$2/vendor"
LP_DIR=`cd $(dirname $0); cd ..; pwd`
BUILDPACK_DIR="$(dirname $(dirname $0))"
# config
BUILD_PACK_VERSION="20130729"
GCC_VERSION="4.3"
GLIBC_VERSION="2.7"
R_VERSION="2.15.1"
S3_BUCKET="heroku-buildpack-r"
R_BINARIES="http://${S3_BUCKET}.s3.amazonaws.com/R-${R_VERSION}-binaries-${BUILD_PACK_VERSION}.tar.gz"
VENDOR_DIR="$BUILD_DIR/vendor"
#R_BASE="$VENDOR_DIR/R"
CRAN_MIRROR="http://cran.revolutionanalytics.com"
mkdir -p $CACHE_DIR
# vendor R into the slug
echo "Vendoring R $R_VERSION" | indent
echo "R gz $R_BINARIES" | indent
echo `ls -l /usr/lib/libreadline*`
# download and unpack binaries
echo "Downloading and unpacking R binaries" | indent
mkdir -p $VENDOR_DIR && curl $R_BINARIES -s -o - | tar xzf - -C $VENDOR_DIR
#mario create these as links , not copy them
ln -s $VENDOR_DIR /app/vendor
R_BASE="/app/vendor/R"
# need to copy the binaries to /app/vendor so that R works
#cp -R $VENDOR_DIR/gcc-$GCC_VERSION /app/vendor/gcc-$GCC_VERSION
#cp -R $VENDOR_DIR/glibc-$GLIBC_VERSION /app/vendor/glibc-$GLIBC_VERSION
#cp -R $VENDOR_DIR/R /app/vendor/R
# R needs to know where gfortran and glibc header files are
export PATH=/app/vendor/R/bin:/app/vendor/gcc-$GCC_VERSION/bin:$PATH
export LDFLAGS="-L/app/vendor/gcc-$GCC_VERSION/lib64/"
export CPPFLAGS="-I/app/vendor/glibc-$GLIBC_VERSION/string/ -I/app/vendor/glibc-$GLIBC_VERSION/time"
export R_HOME=$R_BASE/lib64/R
export R_INCLUDE=$R_HOME/include
#export LD_LIBRARY_PATH=/app/vendor/gcc-$GCC_VERSION/lib64:$R_HOME:$R_HOME/lib:$LD_LIBRARY_PATH
# copy over environment
mkdir -p $BUILD_DIR/.profile.d
cp "$BUILDPACK_DIR/bin/r_environment.sh" $BUILD_DIR/.profile.d/r_environment.sh
# prevent warnings
mkdir -p /app/vendor/R/lib64/R/doc/html
touch /app/vendor/R/lib64/R/doc/html/R.css
# install dependencies from CRAN
echo "Executing init.r script" | indent
# set the CRAN mirror and run the init.r program
/app/vendor/R/bin/R -s <<RPROG > indent
Sys.setenv(BUILD_DIR="$BUILD_DIR")
setwd("$BUILD_DIR")
r <- getOption("repos");
r["CRAN"] <- "$CRAN_MIRROR";
options(repos=r);
`cat $BUILD_DIR/init.r`
RPROG
echo "R $R_VERSION successfully installed" | indent
# need to copy binaries back so that any installed packages are included in the slug
rm -rf $VENDOR_DIR && mkdir -p $VENDOR_DIR
mkdir -p $VENDOR_DIR/gcc-$GCC_VERSION
cp -R /app/vendor/gcc-$GCC_VERSION $VENDOR_DIR/gcc-$GCC_VERSION
mkdir -p $VENDOR_DIR/glibc-$GLIBC_VERSION
cp -R /app/vendor/glibc-$GLIBC_VERSION $VENDOR_DIR/glibc-$GLIBC_VERSION
mkdir -p $VENDOR_DIR/R
cp -R /app/vendor/R/* $VENDOR_DIR/R
# HACK
mkdir -p $VENDOR_DIR/R/lib64/R/lib
cp /app/vendor/gcc-$GCC_VERSION/lib64/* $VENDOR_DIR/R/lib64/R/lib
# remove unneeded files to make slug smaller
# pushd $VENDOR_DIR/gcc-$GCC_VERSION > /dev/null && rm -rf !(lib64) && popd > /dev/null
# pushd $VENDOR_DIR/glibc-$GLIBC_VERSION > /dev/null && rm -rf !(string|time) && popd > /dev/null