Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross platform paths #19

Merged
merged 2 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions R/cfunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,29 +275,16 @@ compileCode <- function(f, code, language, verbose) {
wd = getwd()
on.exit(setwd(wd))
## Prepare temp file names
if ( .Platform$OS.type == "windows" ) {
## windows files
dir <- gsub("\\\\", "/", tempdir())
libCFile <- paste(dir, "/", f, ".EXT", sep="")
libLFile <- paste(dir, "/", f, ".dll", sep="")
libLFile2 <- paste(dir, "/", f, ".dll", sep="")
}
else {
## UNIX-alike build
libCFile <- paste(tempdir(), "/", f, ".EXT", sep="")
libLFile <- paste(tempdir(), "/", f, .Platform$dynlib.ext, sep="")
libLFile2 <- paste(tempdir(), "/", f, ".sl", sep="")
}
extension <- switch(language, "C++"=".cpp", C=".c", Fortran=".f", F95=".f95",
ObjectiveC=".m", "ObjectiveC++"=".mm")
libCFile <- sub(".EXT$", extension, libCFile)
libCFile <- file.path(tempdir(), paste0(f, extension))
libLFile <- file.path(tempdir(), paste0(f, .Platform$dynlib.ext))
eddelbuettel marked this conversation as resolved.
Show resolved Hide resolved

## Write the code to the temp file for compilation
write(code, libCFile)

## Compile the code using the running version of R if several available
if ( file.exists(libLFile) ) file.remove( libLFile )
if ( file.exists(libLFile2) ) file.remove( libLFile2 )

setwd(dirname(libCFile))
errfile <- paste( basename(libCFile), ".err.txt", sep = "" )
Expand All @@ -308,7 +295,6 @@ compileCode <- function(f, code, language, verbose) {
errmsg <- readLines( errfile )
unlink( errfile )

if ( !file.exists(libLFile) && file.exists(libLFile2) ) libLFile <- libLFile2
if ( !file.exists(libLFile) ) {
cat("\nERROR(s) during compilation: source code errors or compiler configuration errors!\n")
if ( !verbose ) system2(cmd, args = paste(" CMD SHLIB --dry-run --preclean", basename(libCFile)))
Expand Down
5 changes: 3 additions & 2 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ setMethod("moveDLL",
# Create new path
if (!dir.exists(directory)) stop("There is no directory ", directory)
extension <- tools::file_ext(old_path)
new_path <- file.path(directory, paste(name, extension, sep = "."))
new_path <- normalizePath(file.path(directory, paste(name, extension, sep = ".")))

active_paths <- sapply(getLoadedDLLs(), function(di) di[["path"]])
active_paths <- sapply(getLoadedDLLs()[-1],
function(di) normalizePath(di[["path"]]))
if (new_path %in% active_paths) {
if (unload) {
if (inherits(try(dyn.unload(new_path)), "try-error"))
Expand Down