Skip to content

Commit

Permalink
jaspModuleInstaller and fixing of r pkgs needs jaspEngine
Browse files Browse the repository at this point in the history
so change the order in which things are installed
  • Loading branch information
JorisGoosen committed Nov 29, 2023
1 parent cc8cb37 commit 8b1cc32
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 69 deletions.
79 changes: 52 additions & 27 deletions Modules/install-jaspModuleInstaller.R.in
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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@')
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
31 changes: 10 additions & 21 deletions Tools/CMake/Modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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
$<$<STREQUAL:"${MODULE}","jaspMetaAnalysis">:${jags_VERSION_H_PATH}>
$<$<STREQUAL:"${MODULE}","jaspJags">:${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
Expand All @@ -291,10 +283,7 @@ else()
${MODULE}
USES_TERMINAL
WORKING_DIRECTORY ${R_HOME_PATH}
DEPENDS
${R_HOME_PATH}/jaspModuleInstaller_md5sums.rds ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller
$<$<STREQUAL:"${MODULE}","jaspMetaAnalysis">:${jags_VERSION_H_PATH}>
$<$<STREQUAL:"${MODULE}","jaspJags">:${jags_VERSION_H_PATH}>
DEPENDS ${JASPMODULEINSTALLER_LIBRARY}/jaspModuleInstaller $<$<STREQUAL:"${MODULE}","jaspMetaAnalysis">:${jags_VERSION_H_PATH}> $<$<STREQUAL:"${MODULE}","jaspJags">:${jags_VERSION_H_PATH}>
COMMAND ${R_EXECUTABLE} --slave --no-restore --no-save
--file=${SCRIPT_DIRECTORY}/install-${MODULE}.R

Expand Down
6 changes: 3 additions & 3 deletions Tools/CMake/R.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b1cc32

Please sign in to comment.