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

fix renv install on mac #5697

Merged
merged 1 commit into from
Oct 14, 2024
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
58 changes: 58 additions & 0 deletions Modules/setup_rcpp_rinside.R.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated from Tools/setup_rcpp_rinside.R.in
#
Sys.setenv(GITHUB_PAT = "@GITHUB_PAT@")
Sys.setenv(RENV_PATHS_ROOT = "@MODULES_RENV_ROOT_PATH@")
Sys.setenv(RENV_PATHS_CACHE = "@MODULES_RENV_CACHE_PATH@")
Sys.setenv(RENV_PATHS_SANDBOX = "@RENV_SANDBOX@")
Sys.setenv(JASPENGINE_LOCATION = "@JASP_ENGINE_PATH@/JASPEngine")

if("@R_PKG_CELLAR_PATH@" != "")
Sys.setenv(RENV_PATHS_CELLAR = "@R_PKG_CELLAR_PATH@")

RENV_LIBRARY <- "@RENV_LIBRARY@"
R_CPP_INCLUDES_LIBRARY <- "@R_CPP_INCLUDES_LIBRARY@"
JASPMODULEINSTALLER_LIBRARY <- "@JASPMODULEINSTALLER_LIBRARY@"
PKGDEPENDS_LIBRARY <- "@PKGDEPENDS_LIBRARY@"

ENGINE <- file.path("@PROJECT_SOURCE_DIR@", "Engine")
MODULES <- file.path("@PROJECT_SOURCE_DIR@", "Modules")
TOOLS <- file.path("@PROJECT_SOURCE_DIR@", "Tools")

# defines assignFunctionInRenv, getOS, and setupRenv
source(file.path(ENGINE, "jaspModuleInstaller", "R", "renvOverrides.R"))

mkdir <- function(paths) {
for (path in paths)
if (!dir.exists(path))
dir.create(path, recursive = TRUE)
}

mkdir(c(RENV_LIBRARY, R_CPP_INCLUDES_LIBRARY, JASPMODULEINSTALLER_LIBRARY))

# used by renv
options(
install.opts = "--no-multiarch --no-docs --no-test-load",
# these two could be added to setupRenv
renv.config.install.verbose = TRUE,
renv.config.ppm.default = TRUE
)

.libPaths(RENV_LIBRARY)
sandboxPaths <- renv:::renv_sandbox_activate()

#to fix flatpak issue cleaning up on interrupt
if (@IS_FLATPAK_USED@) {
system2(command="chmod", args=c("-R", "777", "@RENV_LIBRARY@/../"))
}

cat("Using sandbox paths:\n")
for (path in sandboxPaths)
cat(" ", path, "\n", sep = "")

cat("Restoring Rcpp & RInside\n")
setupRenv(R_CPP_INCLUDES_LIBRARY)
renv::restore(
library = R_CPP_INCLUDES_LIBRARY,
lockfile = file.path(MODULES, "Rcpp_RInside.lock"),
clean = TRUE
)
30 changes: 1 addition & 29 deletions Modules/setup_renv_rcpp_rinside.R.in → Modules/setup_renv.R.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated from Tools/setup_renv_rcpp_rinside_jaspModuleInstaller.R.in
# Generated from Tools/setup_renv.R.in
#
Sys.setenv(GITHUB_PAT = "@GITHUB_PAT@")
Sys.setenv(RENV_PATHS_ROOT = "@MODULES_RENV_ROOT_PATH@")
Expand Down Expand Up @@ -49,31 +49,3 @@ if (!dir.exists(file.path(RENV_LIBRARY, "renv"))) {
} else {
cat("renv already installed, not reinstalling\n")
}

# used by renv
options(
install.opts = "--no-multiarch --no-docs --no-test-load",
# these two could be added to setupRenv
renv.config.install.verbose = TRUE,
renv.config.ppm.default = TRUE
)

.libPaths(RENV_LIBRARY)
sandboxPaths <- renv:::renv_sandbox_activate()

#to fix flatpak issue cleaning up on interrupt
if (@IS_FLATPAK_USED@) {
system2(command="chmod", args=c("-R", "777", "@RENV_LIBRARY@/../"))
}

cat("Using sandbox paths:\n")
for (path in sandboxPaths)
cat(" ", path, "\n", sep = "")

cat("Restoring Rcpp & RInside\n")
setupRenv(R_CPP_INCLUDES_LIBRARY)
renv::restore(
library = R_CPP_INCLUDES_LIBRARY,
lockfile = file.path(MODULES, "Rcpp_RInside.lock"),
clean = TRUE
)
32 changes: 29 additions & 3 deletions Tools/CMake/R.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -838,14 +838,40 @@ message(STATUS "Setting up renv, Rcpp, RInside, and jaspModuleInstaller")
message(STATUS "RENV_LIBRARY = ${RENV_LIBRARY}")
message(STATUS "R_CPP_INCLUDES_LIBRARY = ${R_CPP_INCLUDES_LIBRARY}")

configure_file(${PROJECT_SOURCE_DIR}/Modules/setup_renv_rcpp_rinside.R.in
${SCRIPT_DIRECTORY}/setup_renv_rcpp_rinside.R @ONLY)
configure_file(${PROJECT_SOURCE_DIR}/Modules/setup_renv.R.in
${SCRIPT_DIRECTORY}/setup_renv.R @ONLY)

execute_process(
COMMAND_ECHO STDOUT
#ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${R_HOME_PATH}
COMMAND ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/setup_renv_rcpp_rinside.R)
COMMAND ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/setup_renv.R)

if(APPLE)
# Patch renv
message(CHECK_START "Patching ${RENV_LIBRARY}")
execute_process(
COMMAND_ECHO STDOUT
#ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${R_HOME_PATH}
COMMAND
${CMAKE_COMMAND} -D
NAME_TOOL_PREFIX_PATCHER=${PROJECT_SOURCE_DIR}/Tools/macOS/install_name_prefix_tool.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RensDofferhoff just for my understanding, which .so file needed to get patched here? Something from Rcpp of RInside?

Copy link
Contributor Author

@RensDofferhoff RensDofferhoff Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the renv changelog: https://rstudio.github.io/renv/news/index.html

There now exist a renv.so in libs/ when it is build
This needs to be patched and signed so it may be loaded later on.
before this version 1.0.11 it didn't exist.

-D PATH=${RENV_LIBRARY} -D R_HOME_PATH=${R_HOME_PATH} -D
R_DIR_NAME=${R_DIR_NAME} -D SIGNING_IDENTITY=${APPLE_CODESIGN_IDENTITY}
-D SIGNING=1 -D CODESIGN_TIMESTAMP_FLAG=${CODESIGN_TIMESTAMP_FLAG} -P
${PROJECT_SOURCE_DIR}/Tools/CMake/Patch.cmake
)
endif()

configure_file(${PROJECT_SOURCE_DIR}/Modules/setup_rcpp_rinside.R.in
${SCRIPT_DIRECTORY}/setup_rcpp_rinside.R @ONLY)

execute_process(
COMMAND_ECHO STDOUT
#ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${R_HOME_PATH}
COMMAND ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/setup_rcpp_rinside.R)

if(APPLE)
# Patch RInside and RCpp
Expand Down
Loading