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

Recompile if .o and .so are from a different arch or R version #177

Open
gaborcsardi opened this issue Nov 4, 2023 · 2 comments
Open

Recompile if .o and .so are from a different arch or R version #177

gaborcsardi opened this issue Nov 4, 2023 · 2 comments
Labels
feature a feature request or enhancement

Comments

@gaborcsardi
Copy link
Member

So that pkgload::load_all() recompiles in this case.

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label Nov 4, 2023
@DavisVaughan
Copy link
Member

See also r-lib/pkgload#226

@DavisVaughan
Copy link
Member

Random thought to use otool on mac? Could compare R version seen here with current R version!

r_version_last_compiled_on <- function(package, dir) {
  # find `.so` file
  dir <- file.path(dir, "src", paste0(package, ".so"))

  # get libraries used
  result <- processx::run(
    "otool", 
    args = c("-L", dir)
  )

  if (result$status != 0L) {
    # Don't know, process failed, say no.
    return(FALSE)
  }
  if (length(result$stdout) == 0L) {
    return(FALSE)
  }

  # here is what this looks like
  cat("The stdout:\n")
  cat(result$stdout)
  cat("\n")

  lines <- strsplit(result$stdout, "\n")[[1L]]
  line <- lines[grepl("libR.dylib", lines, fixed = TRUE)]

  if (length(line) != 1L) {
    return(FALSE)
  }

  match <- stringr::str_match(
    line, 
    "current version ([0|[1-9]\\d*]\\.[0|[1-9]\\d*]\\.0|[1-9]\\d*])"
  )

  if (nrow(match) != 1L || ncol(match) != 2L) {
    return(FALSE)
  }

  match[[1L, 2L]]
}

package <- "rlang"
dir <- getwd()

r_version_last_compiled_on(package, dir)
The stdout:
/Users/davis/files/r/packages/rlang/src/rlang.so:
	rlang.so (compatibility version 0.0.0, current version 0.0.0)
	/Library/Frameworks/R.framework/Versions/4.5/Resources/lib/libR.dylib (compatibility version 4.5.0, current version 4.5.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 2202.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.61.1)

[1] "4.5.0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants