This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
270 lines (218 loc) · 7.84 KB
/
Makefile
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
# Makefile for biodb extensions packages, version 1.4.13
# vi: ft=make
# Mute R 3.6 "Registered S3 method overwritten" warning messages.
# Messages that were output:
# Registered S3 method overwritten by 'R.oo':
# method from
# throw.default R.methodsS3
# Registered S3 method overwritten by 'openssl':
# method from
# print.bytes Rcpp
export _R_S3_METHOD_REGISTRATION_NOTE_OVERWRITES_=no
# Constants
COMMA := ,
# Set and check name
PKG_NAME := $(notdir $(realpath $(CURDIR)))
ifeq (,$(shell echo $(PKG_NAME) | grep '^biodb\([A-Z][A-Za-z0-9]*\)\?$$'))
$(error "$(PKG_NAME)" is not a standard package name for a biodb extension. The package name for a biodb extension must respect the format "^biodb([A-Z][A-Za-z0-9]*)?")
endif
ifeq (biodb,$(PKG_NAME))
PKG_NAME_CAPS := BIODB
else
PKG_NAME_CAPS := BIODB_$(shell echo $(PKG_NAME) | sed 's/^biodb//' | tr '[:lower:]' '[:upper:]')
endif
# Get versions
PKG_VERSION=$(shell grep '^Version:' DESCRIPTION | sed 's/^Version: //')
PKG_MAJOR=$(shell echo $(PKG_VERSION) | sed "s/\..*$$//")
ifeq (0,$(PKG_MAJOR))
NEW_PKG=true
endif
ifeq (,$(R_VERSION))
#R_VERSION=$(shell grep '^ *R ' DESCRIPTION | sed 's/^.*[ =]\([0-9]\.[0-9]\(\.[0-9]\)\?\).*$$/\1/')
R_VERSION=4.1.2
endif
# Use system tar instead of R built-in tar in order to avoid the following warning:
# Warning: invalid uid value replaced by that for user 'nobody'
export R_BUILD_TAR=tar
# Bioconductor check flags
BIOC_CHECK_FLAGS=quit-with-status
ifeq (true,$(NEWPKG))
BIOC_CHECK_FLAGS+=new-package
endif
CHECK_RENVIRON=check.Renviron
export R_CHECK_ENVIRON=$(shell realpath $(CHECK_RENVIRON))
RENVIRON_BIOC=Renviron.bioc
export R_ENVIRON_USER=$(shell realpath $(RENVIRON_BIOC))
RENVIRON_FILES=$(CHECK_RENVIRON) $(RENVIRON_BIOC)
# Check files
ifeq (,$(wildcard DESCRIPTION))
$(error Missing file DESCRIPTION)
endif
# Set cache folder
CACHE=$(CURDIR)/cache
LONG_CACHE=$(CURDIR)/cache.long
export BIODB_CACHE_DIRECTORY=$(CACHE)
# Set testthat reporter
ifndef TESTTHAT_REPORTER
ifdef VIM
TESTTHAT_REPORTER=summary
# Call stack
# 8. .self$.parseDbLinks(parsed.content) R/KeggCompoundEntry.R:37:4
ERROR_MSG_FILTER= | sed -e 's!^ *\([0-9]\+\. \)!Callstack \1!'
# Adjust path to test source file in tests/testthat
ERROR_MSG_FILTER+= -e 's!\([^/A-Za-z_-]\)\(test[^/A-Za-z][^/]\+\.R\)!\1tests/testthat/\2!'
# TODO Adjust path to test source file in longtests/testthat
else
TESTTHAT_REPORTER=progress
ERROR_MSG_FILTER=
endif
endif
# Enable compiling
ifneq (,$(wildcard src))
COMPILE=compile
endif
# Set zip filename
ZIPPED_PKG=$(PKG_NAME)_$(PKG_VERSION).tar.gz
# Configure R version to use
export _R_CHECK_LENGTH_1_CONDITION_=true
export _R_CHECK_LENGTH_1_LOGIC2_=true
RFLAGS:=--slave --no-restore
R_FRONT:=$(wildcard $(CURDIR)/R_front $(CURDIR)/inst/templates/R_front)
#ifeq (,$(R_FRONT))
#export R_HOME=$(shell /usr/bin/env R $(RFLAGS) RHOME)
#R=R
#else
export R_HOME:=$(shell bash $(R_FRONT) -n --r-version $(R_VERSION) --print-home)
R:=$(shell bash $(R_FRONT) -n --r-version $(R_VERSION) --print-bin)
#endif
# For R CMD SHLIB
ifdef COMPILE
export PKG_CXXFLAGS:=$(shell $(R) $(RFLAGS) -e "install.packages(Filter(function(pkg) ! require(pkg, character.only=TRUE), c('Rcpp', 'devtools', 'testthat')), dependencies=TRUE, repos='https://cloud.r-project.org/') ; Rcpp:::CxxFlags()" 2>/dev/null | tail -n 1)
PKG_CXXFLAGS+=-I$(realpath $(shell $(R) $(RFLAGS) -e "cat(file.path(testthat::testthat_examples(),'../include'))"))
endif
# Set test file filter
ifndef TEST_FILE
TEST_FILE=NULL
else
TEST_FILE:='$(TEST_FILE)'
endif
# Default target
all:
# Debug: display values of main variables
debug::
$(info BIODB_CACHE_DIRECTORY=$(BIODB_CACHE_DIRECTORY))
$(info BIODB_TEST_FUNCTIONS=$(BIODB_TEST_FUNCTIONS))
$(info CODECOV_$(PKG_NAME_CAPS)_TOKEN=$(value CODECOV_$(PKG_NAME_CAPS)_TOKEN))
$(info PKG_CXXFLAGS=$(PKG_CXXFLAGS))
$(info PKG_NAME=$(PKG_NAME))
$(info PKG_NAME_CAPS=$(PKG_NAME_CAPS))
$(info PKG_VERSION=$(PKG_VERSION))
$(info R=$(R))
$(info RFLAGS=$(RFLAGS))
$(info R_CHECK_ENVIRON=$(R_CHECK_ENVIRON))
$(info R_ENVIRON_USER=$(R_ENVIRON_USER))
$(info R_FRONT=$(R_FRONT))
$(info R_HOME=$(R_HOME))
$(info R_VERSION=$(R_VERSION))
$(info TEST_FILE=$(TEST_FILE))
# Rebuild all & install
rebuild:
# We use a recursive call to force the clean target to be called each time needed (like for checking)
$(MAKE) clean.all
$(MAKE) compile
$(MAKE) doc
$(MAKE) test.all
$(MAKE) check.all
$(MAKE) install
compile: $(COMPILE)
# Compiling
ifdef COMPILE
compile: R/RcppExports.R src/RcppExports.cpp
$(R) $(RFLAGS) CMD SHLIB -o src/$(PKG_NAME).so src/*.cpp
R/RcppExports.R src/RcppExports.cpp: src/*.cpp
$(R) $(RFLAGS) -e "Rcpp::compileAttributes('$(CURDIR)')"
endif
# Code coverage
coverage:
$(R) $(RFLAGS) -e "covr::codecov(token='$(value CODECOV_$(PKG_NAME_CAPS)_TOKEN)', quiet=FALSE)"
# Plain check
check: clean.vignettes $(RENVIRON_FILES) $(ZIPPED_PKG)
$(R) $(RFLAGS) CMD check $(ZIPPED_PKG)
# Bioconductor check
bioc.check: clean.vignettes $(RENVIRON_FILES) $(ZIPPED_PKG)
$(R) $(RFLAGS) -e 'if ( ! require(BiocManager)) install.packages("BiocManager", dependencies=TRUE, repos="https://cloud.r-project.org/") ; if ( ! require(BiocCheck)) BiocManager::install("BiocCheck") ; BiocCheck::BiocCheck("$(ZIPPED_PKG)"$(patsubst %,$(COMMA) `%`=TRUE,$(BIOC_CHECK_FLAGS)))' 2>&1 | sed 's!^ *\(R\|man\|vignettes\)/!Issue in \1/!'
# Bioconductor check Git clone
bioc.check.clone: clean clean.cache
$(R) $(RFLAGS) -e 'if ( ! require(BiocManager)) install.packages("BiocManager", dependencies=TRUE, repos="https://cloud.r-project.org/") ; if ( ! require(BiocCheck)) BiocManager::install("BiocCheck") ; BiocCheck::BiocCheckGitClone()'
check.all: bioc.check.clone check bioc.check
$(CHECK_RENVIRON):
wget -O $@ 'https://raw.githubusercontent.com/Bioconductor/packagebuilder/master/check.Renviron'
$(RENVIRON_BIOC):
wget -O $@ 'http://bioconductor.org/checkResults/devel/bioc-LATEST/Renviron.bioc'
longtests: BIODB_CACHE_DIRECTORY=$(LONG_CACHE)
tests longtests: $(COMPILE)
$(R) $(RFLAGS) -e "testthat::test_dir('$(CURDIR)/$@/testthat', filter=$(TEST_FILE), reporter=c('$(TESTTHAT_REPORTER)', 'fail'), package='$(PKG_NAME)', load_package='source')" $(ERROR_MSG_FILTER)
# Run testthat tests
test: tests
# Run testthat long tests
test.long: longtests
# Run all tests
test.all: tests longtests
# Launch Windows tests on server
win:
$(R) $(RFLAGS) -e "devtools::check_win_devel('$(CURDIR)')"
# Build package zip
pkg: $(ZIPPED_PKG)
# Make zip
$(ZIPPED_PKG): clean.vignettes doc
$(R) $(RFLAGS) CMD build .
NAMESPACE: # First time creation, then roxygen2 will fill it and keep it updated
echo "# Generated by roxygen2: do not edit by hand" >$@
# Generation documentation
ifdef COMPILE
doc: install.deps NAMESPACE R/RcppExports.R
else
doc: install.deps NAMESPACE
endif
$(R) $(RFLAGS) -e "devtools::document('$(CURDIR)')"
# Generate vignettes
vignettes: clean.vignettes
$(R) $(RFLAGS) -e "devtools::build_vignettes('$(CURDIR)')"
upgrade:
$(R) $(RFLAGS) -e 'biodb::ExtPackage$$new(".")$$upgrade()'
# Install dependencies
install.deps:
$(R) $(RFLAGS) -e "devtools::install_dev_deps('$(CURDIR)')"
# Install package
install: uninstall
$(R) $(RFLAGS) -e "devtools::install_local('$(CURDIR)', dependencies=TRUE)"
# Uninstall package
uninstall:
$(R) $(RFLAGS) -e "try(devtools::uninstall('$(CURDIR)'), silent=TRUE)"
# Clean all, included biodb cache
clean.all: clean clean.cache
# Clean
clean: clean.vignettes
ifdef COMPILE
$(RM) src/*.o src/*.so src/*.dll
endif
$(RM) -r *tests/*/output
$(RM) -r $(PKG_NAME).Rcheck
$(RM) -r Meta
$(RM) *.log
$(RM) .Rhistory
$(RM) $(PKG_NAME)_*.tar.gz
$(RM) $(RENVIRON_FILES)
clean.all: clean clean.cache
@echo "Clean also what is versioned but can be rebuilt."
$(RM) -r inst/extdata/generated
$(RM) -r man
# Clean vignettes
clean.vignettes:
$(RM) vignettes/*.R vignettes/*.html
$(RM) -r doc
# Clean biodb cache
clean.cache:
$(RM) -r $(CACHE)
$(RM) -r $(LONG_CACHE)
.PHONY: vignettes doc tests longtests