@@ -656,9 +656,9 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
656
656
# (don't do this for RStudio since it has it's own handling)
657
657
if (identical(Sys.info()[[' sysname' ]], " Windows" ) &&
658
658
! nzchar(Sys.getenv(" RSTUDIO" ))) {
659
- path <- .pathWithRtools ()
660
- if ( ! is.null( path ))
661
- buildEnv $ PATH <- path
659
+ env <- .environmentWithRtools ()
660
+ for ( var in names( env ))
661
+ buildEnv [[ var ]] <- env [[ var ]]
662
662
}
663
663
664
664
# create restore list
@@ -676,7 +676,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
676
676
677
677
# If we don't have the GNU toolchain already on the path then see if
678
678
# we can find Rtools and add it to the path
679
- .pathWithRtools <- function () {
679
+ .environmentWithRtools <- function () {
680
680
681
681
# Only proceed if we don't have the required tools on the path
682
682
hasRtools <- nzchar(Sys.which(" ls.exe" )) && nzchar(Sys.which(" gcc.exe" ))
@@ -691,24 +691,28 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
691
691
# If we found the key examine it
692
692
if (! is.null(key )) {
693
693
694
- # Check version -- we only support 2.15 and 2.16 right now
694
+ # Check version
695
695
ver <- key $ `Current Version`
696
- if (identical(" 2.15" , ver ) || identical(" 2.16" , ver ) ||
697
- identical(" 3.0" , ver ) || identical(" 3.1" , ver ) ||
698
- identical(" 3.2" , ver )) {
699
-
696
+ if (ver %in% (c(" 2.15" , " 2.16" , " 3.0" , " 3.1" , " 3.2" , " 3.3" ))) {
700
697
# See if the InstallPath leads to the expected directories
698
+ isGcc49 <- ver %in% c(" 3.3" )
701
699
rToolsPath <- key $ `InstallPath`
702
700
if (! is.null(rToolsPath )) {
703
-
704
- # Return modified PATH if execpted directories exist
705
- binPath <- file.path(rToolsPath , " bin" , fsep = " \\ " )
706
- gccPath <- file.path(rToolsPath , " gcc-4.6.3" , " bin" , fsep = " \\ " )
707
- if (file.exists(binPath ) && file.exists(gccPath ))
708
- return (paste(binPath ,
709
- gccPath ,
710
- Sys.getenv(" PATH" ),
711
- sep = .Platform $ path.sep ))
701
+ # add appropriate path entries
702
+ path <- file.path(rToolsPath , " bin" , fsep = " \\ " )
703
+ if (! isGcc49 )
704
+ path <- c(path , file.path(rToolsPath , " gcc-4.6.3" , " bin" , fsep = " \\ " ))
705
+
706
+ # if they all exist then return a list with modified
707
+ # environment variables for the compilation
708
+ if (all(file.exists(path ))) {
709
+ env <- list ()
710
+ path <- paste(path , collapse = .Platform $ path.sep )
711
+ env $ PATH <- paste(path , Sys.getenv(" PATH" ), sep = .Platform $ path.sep )
712
+ if (isGcc49 )
713
+ env $ RTOOLS <- .rtoolsPath(rToolsPath )
714
+ return (env )
715
+ }
712
716
}
713
717
}
714
718
}
@@ -718,6 +722,17 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
718
722
}
719
723
720
724
725
+ # Ensure that the path is suitable for passing as an RTOOLS
726
+ # environment variable
727
+ .rtoolsPath <- function (path ) {
728
+ path <- gsub(" \\\\ " , " /" , path )
729
+ path <- trimws(path )
730
+ if (substring(path , nchar(path )) != " /" )
731
+ path <- paste(path , " /" , sep = " " )
732
+ path
733
+ }
734
+
735
+
721
736
# Build CLINK_CPPFLAGS from include directories of LinkingTo packages
722
737
.buildClinkCppFlags <- function (linkingToPackages ) {
723
738
pkgCxxFlags <- NULL
0 commit comments