Skip to content

Commit 1e9bcfe

Browse files
committed
new package version exported based on header file #define
1 parent 7f4e64d commit 1e9bcfe

File tree

9 files changed

+98
-6
lines changed

9 files changed

+98
-6
lines changed

ChangeLog

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2019-04-25 Dirk Eddelbuettel <[email protected]>
2+
3+
* R/tools.R (getRcppVersion): Export R (and dev) package version
4+
* man/getRcppVersion.Rd: Documentation for new function
5+
6+
* inst/include/Rcpp/config.h (RCPP_VERSION_STRING): New version
7+
and development version string #define
8+
* src/api.cpp (getRcppVersionStrings): Expose new versions strings
9+
* src/internal.h: Register new version string exporter
10+
* src/rcpp_init.cpp (callEntries[]): Idem
11+
112
2019-03-23 Ralf Stubner <[email protected]>
213

314
* vignettes/Rcpp-modules.Rmd: Describe RCPP_EXPOSED_* macros

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ URL: http://www.rcpp.org, http://dirk.eddelbuettel.com/code/rcpp.html, https://g
2222
License: GPL (>= 2)
2323
BugReports: https://github.com/RcppCore/Rcpp/issues
2424
MailingList: Please send questions and comments regarding Rcpp to [email protected]
25-
RoxygenNote: 6.0.1
25+
RoxygenNote: 6.1.1

NAMESPACE

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export(Module,
3232
sizeof,
3333
cpp_object_initializer,
3434
cpp_object_dummy,
35-
Rcpp.plugin.maker
35+
Rcpp.plugin.maker,
36+
getRcppVersion
3637
)
3738
S3method(print, bytes)
3839
S3method(format, Rcpp_stack_trace)

R/tools.R

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
1+
# Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
22
#
33
# This file is part of Rcpp.
44
#
@@ -48,3 +48,31 @@ asBuildPath <- function(path) {
4848

4949
return(path)
5050
}
51+
52+
53+
##' Helper function to report the package version of the R installation.
54+
##'
55+
##' While \code{packageVersion(Rcpp)} exports the version registers in
56+
##' {DESCRIPTION}, this version does get incremented more easily
57+
##' during development and can therefore be higher than the released
58+
##' version. The actual \code{#define} long used at the C++ level
59+
##' corresponds more to an \sQuote{API Version} which is now provided
60+
##' by this function, and use for example in the package skeleton
61+
##' generator.
62+
##'
63+
##' @title Export the Rcpp (API) Package Version
64+
##' @param devel An logical value indicating if the development or
65+
##' release version number should be returned, default is release.
66+
##' @return A \code{package_version} object with either the release
67+
##' or development version.
68+
##' @author Dirk Eddelbuettel
69+
##' @seealso \code{\link{packageVersion}},
70+
##' \code{\link{Rcpp.package.skeleton}}
71+
##' @examples getRcppVersion()
72+
getRcppVersion <- function(devel = FALSE) {
73+
rcpp <- .Call("getRcppVersionStrings")[if(devel) 2 else 1]
74+
.make_numeric_version(rcpp,
75+
TRUE,
76+
.standard_regexps()$valid_package_version,
77+
"package_version")
78+
}

inst/include/Rcpp/config.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
#define RcppDevVersion(maj, min, rev, dev) (((maj)*1000000) + ((min)*10000) + ((rev)*100) + (dev))
2727

2828
// the currently released version
29-
#define RCPP_VERSION Rcpp_Version(1,0,1)
29+
#define RCPP_VERSION Rcpp_Version(1,0,1)
30+
#define RCPP_VERSION_STRING "1.0.1"
3031

3132
// the current source snapshot
32-
#define RCPP_DEV_VERSION RcppDevVersion(1,0,1,0)
33+
#define RCPP_DEV_VERSION RcppDevVersion(1,0,1,0)
34+
#define RCPP_DEV_VERSION_STRING "1.0.1.0"
3335

3436
#endif

man/getRcppVersion.Rd

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,11 @@ SEXP stack_trace(const char* file, int line) {
325325

326326
// }}}
327327

328+
329+
// [[Rcpp::internal]]
330+
SEXP getRcppVersionStrings() {
331+
Shield<SEXP> versionstring(Rf_allocVector(STRSXP,2));
332+
SET_STRING_ELT(versionstring, 0, Rf_mkChar(RCPP_VERSION_STRING));
333+
SET_STRING_ELT(versionstring, 1, Rf_mkChar(RCPP_DEV_VERSION_STRING));
334+
return versionstring;
335+
}

src/internal.h

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ CALLFUN_0(rcpp_capabilities);
128128
CALLFUN_0(rcpp_can_use_cxx0x);
129129
CALLFUN_0(rcpp_can_use_cxx11);
130130

131+
CALLFUN_0(getRcppVersionStrings);
132+
131133
/* .External functions */
132134
EXTFUN(CppMethod__invoke);
133135
EXTFUN(CppMethod__invoke_void);

src/rcpp_init.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ static R_CallMethodDef callEntries[] = {
5757
CALLDEF(rcpp_capabilities,0),
5858
CALLDEF(rcpp_can_use_cxx0x,0),
5959
CALLDEF(rcpp_can_use_cxx11,0),
60+
61+
CALLDEF(getRcppVersionStrings,0),
6062
{NULL, NULL, 0}
6163
};
6264

@@ -130,7 +132,7 @@ extern "C" void R_unload_Rcpp(DllInfo *) { // #nocov start
130132
extern "C" void R_init_Rcpp(DllInfo* dllinfo) {
131133
setCurrentScope(0);
132134

133-
registerFunctions(); // call wrapper to register export symbols
135+
registerFunctions(); // call wrapper to register export symbols
134136

135137
R_useDynamicSymbols(dllinfo, FALSE); // set up symbol symbol lookup (cf R 3.4.0)
136138

0 commit comments

Comments
 (0)