From 8b1cc3237dbc768abfc120b5ff381e6cdaf3b680 Mon Sep 17 00:00:00 2001 From: Joris Goosen Date: Wed, 29 Nov 2023 17:09:12 +0100 Subject: [PATCH] jaspModuleInstaller and fixing of r pkgs needs jaspEngine so change the order in which things are installed --- Modules/install-jaspModuleInstaller.R.in | 79 ++++++++++++------- ...ller.R.in => setup_renv_rcpp_rinside.R.in} | 19 +---- Tools/CMake/Modules.cmake | 31 +++----- Tools/CMake/R.cmake | 6 +- 4 files changed, 66 insertions(+), 69 deletions(-) rename Modules/{setup_renv_rcpp_rinside_jaspModuleInstaller.R.in => setup_renv_rcpp_rinside.R.in} (81%) diff --git a/Modules/install-jaspModuleInstaller.R.in b/Modules/install-jaspModuleInstaller.R.in index e7eb20f9d56..7c6b214e07e 100644 --- a/Modules/install-jaspModuleInstaller.R.in +++ b/Modules/install-jaspModuleInstaller.R.in @@ -6,12 +6,7 @@ Sys.setenv(RENV_PATHS_CACHE = "@MODULES_RENV_CACHE_PATH@") Sys.setenv(RENV_PATHS_SANDBOX = "@RENV_SANDBOX@") Sys.setenv(JASPENGINE_LOCATION = "@JASP_ENGINE_PATH@/JASPEngine") -#Load the post-install fixes from jaspBase. Think Baron von Munchausen ;) -#source("@PROJECT_SOURCE_DIR@/Engine/jaspBase/R/utility.R") -#source("@PROJECT_SOURCE_DIR@/Engine/jaspBase/R/checkSums.R") -#source("@PROJECT_SOURCE_DIR@/Engine/jaspBase/R/assignFunctionInPackage.R") -#source("@PROJECT_SOURCE_DIR@/Engine/jaspBase/R/moduleInstall.R") - +#Load the post-install fixes from jaspBase. Think Baron von Munchhausen ;) source("@PROJECT_SOURCE_DIR@/Engine/jaspModuleInstaller/R/renvOverrides.R") source("@PROJECT_SOURCE_DIR@/Engine/jaspModuleInstaller/R/checksums.R") source("@PROJECT_SOURCE_DIR@/Engine/jaspModuleInstaller/R/utils.R") @@ -26,43 +21,73 @@ if (@IS_FLATPAK_USED@) { options(repos = "@R_REPOSITORY@") } -.libPaths("@JASPMODULEINSTALLER_LIBRARY@") +.libPaths("@RENV_LIBRARY@") sandboxPaths <- renv:::renv_sandbox_activate() -moduleLibrary <- "@JASPMODULEINSTALLER_LIBRARY@" +JASPMODULEINSTALLER_LIBRARY <- "@JASPMODULEINSTALLER_LIBRARY@" +PKGDEPENDS_LIBRARY <- "@PKGDEPENDS_LIBRARY@" +RENV_LIBRARY <- "@RENV_LIBRARY@" +R_CPP_INCLUDES_LIBRARY <- "@R_CPP_INCLUDES_LIBRARY@" + +ENGINE <- file.path("@PROJECT_SOURCE_DIR@", "Engine") +MODULES <- file.path("@PROJECT_SOURCE_DIR@", "Modules") +TOOLS <- file.path("@PROJECT_SOURCE_DIR@", "Tools") + modulePkg <- file.path("@PROJECT_SOURCE_DIR@", "Engine", "jaspModuleInstaller") -if (md5SumsChanged(modulePkg, moduleLibrary)) { -# Sys.setenv(JASP_R_INTERFACE_LIBRARY="Oh yes indeed") - setupRenv("@R_LIBRARY_PATH@", modulePkg) +cat("Restoring pkgdepends\n") +setupRenv(PKGDEPENDS_LIBRARY) +renv::restore( + library = PKGDEPENDS_LIBRARY, + lockfile = file.path(MODULES, "pkgdepends.lock"), + clean = TRUE +) - record <- createLocalRecord(modulePkg, getModuleInfo(modulePkg), cacheAble = FALSE, addJaspToVersion = FALSE) - lf <- renv::lockfile_read(file.path(modulePkg, "renv.lock")) - lf <- renv::record(record, lockfile = lf) - cat(".libPaths()", .libPaths(), sep = "\n") +cat("Restoring jaspModuleInstaller\n") +setupRenv(JASPMODULEINSTALLER_LIBRARY) +renv::restore( + library = JASPMODULEINSTALLER_LIBRARY, + lockfile = file.path(ENGINE, "jaspModuleInstaller", "renv.lock"), + exclude = "jaspModuleInstaller", # otherwise "clean" would remove jaspModuleInstaller + clean = TRUE +) - # remove the package if it is installed, otherwise renv doesn't realize we want to reinstall it - pkgName <- basename(modulePkg) - if (dir.exists(file.path(.libPaths()[1L], pkgName))) - utils::remove.packages(pkgs = pkgName, lib = .libPaths()[1L]) +print("Installing jaspModuleInstaller") +.libPaths(JASPMODULEINSTALLER_LIBRARY) +setupRenv("@R_LIBRARY_PATH@", modulePkg) - renv::restore(lockfile = lf, library = .libPaths(), rebuild = pkgName) +record <- createLocalRecord(modulePkg, getModuleInfo(modulePkg), cacheAble = FALSE, addJaspToVersion = FALSE) +lf <- renv::lockfile_read(file.path(modulePkg, "renv.lock")) +lf <- renv::record(record, lockfile = lf) +cat(".libPaths()", .libPaths(), sep = "\n") - if (TRUE) # TODO: validate installation - writeMd5Sums(modulePkg, moduleLibrary) +# remove the package if it is installed, otherwise renv doesn't realize we want to reinstall it +pkgName <- basename(modulePkg) +if (dir.exists(file.path(.libPaths()[1L], pkgName))) + utils::remove.packages(pkgs = pkgName, lib = .libPaths()[1L]) + +renv::restore(lockfile = lf, library = .libPaths(), rebuild = pkgName) -} else { - cat("jaspModuleInstaller is unchanged, not reinstalling.\n") -} + +print("jaspModuleInstaller::writeModuleStatusObject(@PROJECT_SOURCE_DIR@") jaspModuleInstaller::writeModuleStatusObject("@PROJECT_SOURCE_DIR@") +#This is necessary because of conflicts with Matrix dep of base R lib. +#Can be removed when a new version of R updates its Matrix +if (!@IS_FLATPAK_USED@) { + + if (Sys.info()["sysname"] == "Darwin") { + options(pkgType = "source") + } + + renv::install("Matrix", library = JASPMODULEINSTALLER_LIBRARY, prompt = FALSE) +} + # Converting the absolute symlinks to relative symlinks on macOS # Todo, I can do this using CMake like I do on Windows if (Sys.info()["sysname"] == "Darwin") { - renv::install("Matrix", type="binary", library = moduleLibrary, prompt = FALSE) - source('@MODULES_BINARY_PATH@/symlinkTools.R') convertAbsoluteSymlinksToRelative('@R_LIBRARY_PATH@', '@MODULES_RENV_CACHE_PATH@') } diff --git a/Modules/setup_renv_rcpp_rinside_jaspModuleInstaller.R.in b/Modules/setup_renv_rcpp_rinside.R.in similarity index 81% rename from Modules/setup_renv_rcpp_rinside_jaspModuleInstaller.R.in rename to Modules/setup_renv_rcpp_rinside.R.in index 8d87ed79b5f..720b8a002a4 100644 --- a/Modules/setup_renv_rcpp_rinside_jaspModuleInstaller.R.in +++ b/Modules/setup_renv_rcpp_rinside.R.in @@ -62,21 +62,4 @@ renv::restore( library = R_CPP_INCLUDES_LIBRARY, lockfile = file.path(MODULES, "Rcpp_RInside.lock"), clean = TRUE -) - -cat("Restoring pkgdepends\n") -setupRenv(PKGDEPENDS_LIBRARY) -renv::restore( - library = PKGDEPENDS_LIBRARY, - lockfile = file.path(MODULES, "pkgdepends.lock"), - clean = TRUE -) - -cat("Restoring jaspModuleInstaller\n") -setupRenv(JASPMODULEINSTALLER_LIBRARY) -renv::restore( - library = JASPMODULEINSTALLER_LIBRARY, - lockfile = file.path(ENGINE, "jaspModuleInstaller", "renv.lock"), - exclude = "jaspModuleInstaller", # otherwise "clean" would remove jaspModuleInstaller - clean = TRUE -) +) \ No newline at end of file diff --git a/Tools/CMake/Modules.cmake b/Tools/CMake/Modules.cmake index 4e0a3f4cca8..607a52babb2 100644 --- a/Tools/CMake/Modules.cmake +++ b/Tools/CMake/Modules.cmake @@ -155,33 +155,27 @@ execute_process( ${MODULES_BINARY_PATH}/) add_custom_target( - jaspBase + jaspModuleInstaller WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/R-Interface - DEPENDS ${MODULES_BINARY_PATH}/jaspBase/jaspBaseHash.rds) + DEPENDS ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller) configure_file("${PROJECT_SOURCE_DIR}/Modules/install-jaspModuleInstaller.R.in" ${SCRIPT_DIRECTORY}/install-jaspModuleInstaller.R @ONLY) -# I'm using a custom_command here to make sure that jaspBase is installed once -# and only once before everything else. So, `install-jaspBase.R` creates an empty -# file, i.e., `jaspBase-installed-successfully.log` and all other Modules look for -# it. If they find it, they proceed, if not, they trigger this custom command. -# TODO: -# - [ ] The following commands can be turned into a function or a macro, but -# for now, I would like to keep a granular control over differnt steps +# I'm using a custom_command here to make sure that jaspModuleInstaller is installed once if(APPLE) - add_dependencies(jaspBase JASPEngine) + add_dependencies(jaspModuleInstaller JASPEngine) add_custom_command( WORKING_DIRECTORY ${R_HOME_PATH} - OUTPUT ${R_HOME_PATH}/jaspModuleInstaller_md5sums.rds ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller + OUTPUT ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller USES_TERMINAL COMMAND ${CMAKE_COMMAND} -E env "JASP_R_HOME=${R_HOME_PATH}" ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/install-jaspModuleInstaller.R COMMENT "------ Installing 'jaspModuleInstaller'") else() add_custom_command( WORKING_DIRECTORY ${R_HOME_PATH} - OUTPUT ${R_HOME_PATH}/jaspModuleInstaller_md5sums.rds ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller + OUTPUT ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller USES_TERMINAL COMMAND ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/install-jaspModuleInstaller.R @@ -219,7 +213,7 @@ if(APPLE) ${MODULE} USES_TERMINAL WORKING_DIRECTORY ${R_HOME_PATH} - DEPENDS ${R_HOME_PATH}/jaspModuleInstaller_md5sums.rds ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller + DEPENDS ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller COMMAND ${CMAKE_COMMAND} -E env "JASP_R_HOME=${R_HOME_PATH}" ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/install-${MODULE}.R # COMMAND # ${CMAKE_COMMAND} -D PATH=${MODULES_BINARY_PATH}/${MODULE} -D @@ -237,7 +231,7 @@ else() ${MODULE} USES_TERMINAL WORKING_DIRECTORY ${R_HOME_PATH} - DEPENDS ${R_HOME_PATH}/jaspModuleInstaller_md5sums.rds ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller + DEPENDS ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller COMMAND ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/install-${MODULE}.R BYPRODUCTS ${MODULES_BINARY_PATH}/${MODULE} @@ -271,9 +265,7 @@ if(APPLE) ${MODULE} USES_TERMINAL WORKING_DIRECTORY ${R_HOME_PATH} - DEPENDS - JASPEngine - ${R_HOME_PATH}/jaspModuleInstaller_md5sums.rds ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller + DEPENDS JASPEngine ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller $<$:${jags_VERSION_H_PATH}> $<$:${jags_VERSION_H_PATH}> COMMAND ${CMAKE_COMMAND} -E env "JASP_R_HOME=${R_HOME_PATH}" ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/install-${MODULE}.R @@ -291,10 +283,7 @@ else() ${MODULE} USES_TERMINAL WORKING_DIRECTORY ${R_HOME_PATH} - DEPENDS - ${R_HOME_PATH}/jaspModuleInstaller_md5sums.rds ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller - $<$:${jags_VERSION_H_PATH}> - $<$:${jags_VERSION_H_PATH}> + DEPENDS ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller $<$:${jags_VERSION_H_PATH}> $<$:${jags_VERSION_H_PATH}> COMMAND ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/install-${MODULE}.R diff --git a/Tools/CMake/R.cmake b/Tools/CMake/R.cmake index 02712f68de7..4e2ac42f35f 100644 --- a/Tools/CMake/R.cmake +++ b/Tools/CMake/R.cmake @@ -747,14 +747,14 @@ 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_jaspModuleInstaller.R.in - ${SCRIPT_DIRECTORY}/setup_renv_rcpp_rinside_jaspModuleInstaller.R @ONLY) +configure_file(${PROJECT_SOURCE_DIR}/Modules/setup_renv_rcpp_rinside.R.in + ${SCRIPT_DIRECTORY}/setup_renv_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_renv_rcpp_rinside_jaspModuleInstaller.R) + COMMAND ${R_EXECUTABLE} --slave --no-restore --no-save --file=${SCRIPT_DIRECTORY}/setup_renv_rcpp_rinside.R) if(APPLE) # Patch RInside and RCpp