-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtravis-tool.sh
executable file
·387 lines (336 loc) · 11.4 KB
/
travis-tool.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/bin/bash
# -*- sh-basic-offset: 4; sh-indentation: 4 -*-
# Bootstrap an R/travis environment.
set -e
# Comment out this line for quieter output:
set -x
CRAN=${CRAN:-"http://cran.rstudio.com"}
BIOC=${BIOC:-"http://bioconductor.org/biocLite.R"}
BIOC_USE_DEVEL=${BIOC_USE_DEVEL:-"TRUE"}
OS=$(uname -s)
PANDOC_VERSION='1.13.1'
PANDOC_DIR="${HOME}/opt/pandoc"
PANDOC_URL="https://s3.amazonaws.com/rstudio-buildtools/pandoc-${PANDOC_VERSION}.zip"
# MacTeX installs in a new $PATH entry, and there's no way to force
# the *parent* shell to source it from here. So we just manually add
# all the entries to a location we already know to be on $PATH.
#
# TODO(craigcitro): Remove this once we can add `/usr/texbin` to the
# root path.
PATH="${PATH}:/usr/texbin"
R_BUILD_ARGS=${R_BUILD_ARGS-"--no-build-vignettes --no-manual"}
R_CHECK_ARGS=${R_CHECK_ARGS-"--no-build-vignettes --no-manual --as-cran"}
R_USE_BIOC_CMDS="source('${BIOC}');"\
" tryCatch(useDevel(${BIOC_USE_DEVEL}),"\
" error=function(e) {if (!grepl('already in use', e$message)) {e}});"\
" options(repos=biocinstallRepos());"
Bootstrap() {
if [[ "Darwin" == "${OS}" ]]; then
BootstrapMac
elif [[ "Linux" == "${OS}" ]]; then
BootstrapLinux
else
echo "Unknown OS: ${OS}"
exit 1
fi
if ! (test -e .Rbuildignore && grep -q 'travis-tool' .Rbuildignore); then
echo '^travis-tool\.sh$' >>.Rbuildignore
fi
}
InstallPandoc() {
local os_path="$1"
mkdir -p "${PANDOC_DIR}"
curl -o /tmp/pandoc-${PANDOC_VERSION}.zip ${PANDOC_URL}
unzip -j /tmp/pandoc-${PANDOC_VERSION}.zip "pandoc-${PANDOC_VERSION}/${os_path}/pandoc" -d "${PANDOC_DIR}"
chmod +x "${PANDOC_DIR}/pandoc"
sudo ln -s "${PANDOC_DIR}/pandoc" /usr/local/bin
unzip -j /tmp/pandoc-${PANDOC_VERSION}.zip "pandoc-${PANDOC_VERSION}/${os_path}/pandoc-citeproc" -d "${PANDOC_DIR}"
chmod +x "${PANDOC_DIR}/pandoc-citeproc"
sudo ln -s "${PANDOC_DIR}/pandoc-citeproc" /usr/local/bin
}
BootstrapLinux() {
# Set up our CRAN mirror.
sudo add-apt-repository "deb ${CRAN}/bin/linux/ubuntu $(lsb_release -cs)/"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
# Add marutter's c2d4u repository.
sudo add-apt-repository -y "ppa:marutter/rrutter"
sudo add-apt-repository -y "ppa:marutter/c2d4u"
# Update after adding all repositories. Retry several times to work around
# flaky connection to Launchpad PPAs.
Retry sudo apt-get update -qq
# Install an R development environment. qpdf is also needed for
# --as-cran checks:
# https://stat.ethz.ch/pipermail/r-help//2012-September/335676.html
Retry sudo apt-get install --no-install-recommends r-base-dev r-recommended qpdf
# Change permissions for /usr/local/lib/R/site-library
# This should really be via 'staff adduser travis staff'
# but that may affect only the next shell
sudo chmod 2777 /usr/local/lib/R /usr/local/lib/R/site-library
# Process options
BootstrapLinuxOptions
}
BootstrapLinuxOptions() {
if [[ -n "$BOOTSTRAP_LATEX" ]]; then
# We add a backports PPA for more recent TeX packages.
sudo add-apt-repository -y "ppa:texlive-backports/ppa"
Retry sudo apt-get install --no-install-recommends \
texlive-base texlive-latex-base texlive-generic-recommended \
texlive-fonts-recommended texlive-fonts-extra \
texlive-extra-utils texlive-latex-recommended texlive-latex-extra \
texinfo lmodern
fi
if [[ -n "$BOOTSTRAP_PANDOC" ]]; then
InstallPandoc 'linux/debian/x86_64'
fi
}
BootstrapMac() {
# Install from latest CRAN binary build for OS X
wget ${CRAN}/bin/macosx/R-latest.pkg -O /tmp/R-latest.pkg
echo "Installing OS X binary package for R"
sudo installer -pkg "/tmp/R-latest.pkg" -target /
rm "/tmp/R-latest.pkg"
# Process options
BootstrapMacOptions
}
BootstrapMacOptions() {
if [[ -n "$BOOTSTRAP_LATEX" ]]; then
# TODO: Install MacTeX.pkg once there's enough disk space
MACTEX=mactex-basic.pkg
wget http://ctan.math.utah.edu/ctan/tex-archive/systems/mac/mactex/$MACTEX -O "/tmp/$MACTEX"
echo "Installing OS X binary package for MacTeX"
sudo installer -pkg "/tmp/$MACTEX" -target /
rm "/tmp/$MACTEX"
# We need a few more packages than the basic package provides; this
# post saved me so much pain:
# https://stat.ethz.ch/pipermail/r-sig-mac/2010-May/007399.html
sudo tlmgr update --self
sudo tlmgr install inconsolata upquote courier courier-scaled helvetic
fi
if [[ -n "$BOOTSTRAP_PANDOC" ]]; then
InstallPandoc 'mac'
fi
}
EnsureDevtools() {
if ! Rscript -e 'if (!("devtools" %in% rownames(installed.packages()))) q(status=1)' ; then
# Install devtools and testthat.
RBinaryInstall devtools testthat
fi
}
AptGetInstall() {
if [[ "Linux" != "${OS}" ]]; then
echo "Wrong OS: ${OS}"
exit 1
fi
if [[ "" == "$*" ]]; then
echo "No arguments to aptget_install"
exit 1
fi
echo "Installing apt package(s) $@"
Retry sudo apt-get install "$@"
}
DpkgCurlInstall() {
if [[ "Linux" != "${OS}" ]]; then
echo "Wrong OS: ${OS}"
exit 1
fi
if [[ "" == "$*" ]]; then
echo "No arguments to dpkgcurl_install"
exit 1
fi
echo "Installing remote package(s) $@"
for rf in "$@"; do
curl -OL ${rf}
f=$(basename ${rf})
sudo dpkg -i ${f}
rm -v ${f}
done
}
RInstall() {
if [[ "" == "$*" ]]; then
echo "No arguments to r_install"
exit 1
fi
echo "Installing R package(s): $@"
Rscript -e 'install.packages(commandArgs(TRUE), repos="'"${CRAN}"'")' "$@"
}
BiocInstall() {
if [[ "" == "$*" ]]; then
echo "No arguments to bioc_install"
exit 1
fi
echo "Installing R Bioconductor package(s): $@"
Rscript -e "${R_USE_BIOC_CMDS}"' biocLite(commandArgs(TRUE))' "$@"
}
RBinaryInstall() {
if [[ -z "$#" ]]; then
echo "No arguments to r_binary_install"
exit 1
fi
if [[ "Linux" != "${OS}" ]] || [[ -n "${FORCE_SOURCE_INSTALL}" ]]; then
echo "Fallback: Installing from source"
RInstall "$@"
return
fi
echo "Installing *binary* R packages: $*"
r_packages=$(echo $* | tr '[:upper:]' '[:lower:]')
r_debs=$(for r_package in ${r_packages}; do echo -n "r-cran-${r_package} "; done)
AptGetInstall ${r_debs}
}
InstallGithub() {
EnsureDevtools
echo "Installing GitHub packages: $@"
# Install the package.
Rscript -e 'library(devtools); library(methods); options(repos=c(CRAN="'"${CRAN}"'")); install_github(commandArgs(TRUE), build_vignettes = FALSE)' "$@"
}
InstallDeps() {
EnsureDevtools
Rscript -e 'library(devtools); library(methods); options(repos=c(CRAN="'"${CRAN}"'")); install_deps(dependencies = TRUE)'
}
InstallBiocDeps() {
EnsureDevtools
Rscript -e "${R_USE_BIOC_CMDS}"' library(devtools); install_deps(dependencies = TRUE)'
}
DumpSysinfo() {
echo "Dumping system information."
R -e '.libPaths(); sessionInfo(); installed.packages()'
}
DumpLogsByExtension() {
if [[ -z "$1" ]]; then
echo "dump_logs_by_extension requires exactly one argument, got: $@"
exit 1
fi
extension=$1
shift
package=$(find . -maxdepth 1 -name "*.Rcheck" -type d)
if [[ ${#package[@]} -ne 1 ]]; then
echo "Could not find package Rcheck directory, skipping log dump."
exit 0
fi
for name in $(find "${package}" -type f -name "*${extension}"); do
echo ">>> Filename: ${name} <<<"
cat ${name}
done
}
DumpLogs() {
echo "Dumping test execution logs."
DumpLogsByExtension "out"
DumpLogsByExtension "log"
DumpLogsByExtension "fail"
}
RunTests() {
echo "Building with: R CMD build ${R_BUILD_ARGS}"
R CMD build ${R_BUILD_ARGS} .
# We want to grab the version we just built.
FILE=$(ls -1t *.tar.gz | head -n 1)
# Create binary package (currently Windows only)
if [[ "${OS:0:5}" == "MINGW" ]]; then
R_CHECK_INSTALL_ARGS="--install-args=--build"
fi
echo "Testing with: R CMD check \"${FILE}\" ${R_CHECK_ARGS} ${R_CHECK_INSTALL_ARGS}"
_R_CHECK_CRAN_INCOMING_=${_R_CHECK_CRAN_INCOMING_:-FALSE}
if [[ "$_R_CHECK_CRAN_INCOMING_" == "FALSE" ]]; then
echo "(CRAN incoming checks are off)"
fi
_R_CHECK_CRAN_INCOMING_=${_R_CHECK_CRAN_INCOMING_} R CMD check "${FILE}" ${R_CHECK_ARGS} ${R_CHECK_INSTALL_ARGS}
# Check reverse dependencies
if [[ -n "$R_CHECK_REVDEP" ]]; then
echo "Checking reverse dependencies"
Rscript -e 'library(devtools); checkOutput <- unlist(revdep_check(as.package(".")$package));if (!is.null(checkOutput)) {print(data.frame(pkg = names(checkOutput), error = checkOutput));for(i in seq_along(checkOutput)){;cat("\n", names(checkOutput)[i], " Check Output:\n ", paste(readLines(regmatches(checkOutput[i], regexec("/.*\\.out", checkOutput[i]))[[1]]), collapse = "\n ", sep = ""), "\n", sep = "")};q(status = 1, save = "no")}'
fi
if [[ -n "${WARNINGS_ARE_ERRORS}" ]]; then
if DumpLogsByExtension "00check.log" | grep -q WARNING; then
echo "Found warnings, treated as errors."
echo "Clear or unset the WARNINGS_ARE_ERRORS environment variable to ignore warnings."
exit 1
fi
fi
}
Retry() {
if "$@"; then
return 0
fi
for wait_time in 5 20 30 60; do
echo "Command failed, retrying in ${wait_time} ..."
sleep ${wait_time}
if "$@"; then
return 0
fi
done
echo "Failed all retries!"
exit 1
}
COMMAND=$1
echo "Running command: ${COMMAND}"
shift
case $COMMAND in
##
## Bootstrap a new core system
"bootstrap")
Bootstrap
;;
##
## Ensure devtools is loaded (implicitly called)
"install_devtools"|"devtools_install")
EnsureDevtools
;;
##
## Install a binary deb package via apt-get
"install_aptget"|"aptget_install")
AptGetInstall "$@"
;;
##
## Install a binary deb package via a curl call and local dpkg -i
"install_dpkgcurl"|"dpkgcurl_install")
DpkgCurlInstall "$@"
;;
##
## Install an R dependency from CRAN
"install_r"|"r_install")
RInstall "$@"
;;
##
## Install an R dependency from Bioconductor
"install_bioc"|"bioc_install")
BiocInstall "$@"
;;
##
## Install an R dependency as a binary (via c2d4u PPA)
"install_r_binary"|"r_binary_install")
RBinaryInstall "$@"
;;
##
## Install a package from github sources (needs devtools)
"install_github"|"github_package")
InstallGithub "$@"
;;
##
## Install package dependencies from CRAN (needs devtools)
"install_deps")
InstallDeps
;;
##
## Install package dependencies from Bioconductor and CRAN (needs devtools)
"install_bioc_deps")
InstallBiocDeps
;;
##
## Run the actual tests, ie R CMD check
"run_tests")
RunTests
;;
##
## Dump information about installed packages
"dump_sysinfo")
DumpSysinfo
;;
##
## Dump build or check logs
"dump_logs")
DumpLogs
;;
##
## Dump selected build or check logs
"dump_logs_by_extension")
DumpLogsByExtension "$@"
;;
esac