Skip to content

Commit

Permalink
use new module installation mechanism
Browse files Browse the repository at this point in the history
very basic functionality works

start on making hashes work

seems more or less functional now

started rewriting cmake, stuff compiles but crashes at runtime

everything seems functional on Linux

windows fixes, stuff compiles but weird runtime error

building on windows works from a clean build, but more testing is needed

more tweaks, update to renv 1.0.2

updates for fallback without lockfile

start unifying stuff across OSes

autogenerated lockfiles seem to be work okay but need more testing

reorganize file + pkgdepends fallback

bump jaspModuleInstaller

spaces -> tabs

bump jaspModuleInstaller

spaces -> tabs

moved getModuleDependencies to jaspModuleInstaller

call setupRenv in setup_renv_rcpp_rinside_jaspModuleInstaller.R.in

remove custom Matrix installation

make configuration work on macos

compilation still fails though...

do follow symlinks otherwise it patches nothing

move searching for fortran outside of the "does framework not exist if()f"

jaspModuleInstaller and fixing of r pkgs needs jaspEngine

so change the order in which things are installed

add R_LIBS for windows and macos

make windows start
  • Loading branch information
vandenman authored and JorisGoosen committed Jan 24, 2024
1 parent 8d21882 commit 22341ae
Show file tree
Hide file tree
Showing 19 changed files with 664 additions and 376 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@
[submodule "Modules/jaspProcess"]
path = Modules/jaspProcess
url = https://github.com/jasp-stats/jaspProcess
[submodule "Engine/jaspModuleInstaller"]
path = Engine/jaspModuleInstaller
url = https://github.com/vandenman/jaspModuleInstaller.git
2 changes: 1 addition & 1 deletion Desktop/modules/dynamicmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ Json::Value DynamicModule::requestJsonForPackageLoadingRequest()

std::string DynamicModule::getLibPathsToUse() const
{
return "c('" + AppDirs::rHome().toStdString() + "/library', '" + shortenWinPaths(moduleRLibrary()).toStdString() + "')";
return "c('" + shortenWinPaths(moduleRLibrary()).toStdString() + "', '" + AppDirs::rHome().toStdString() + "/library')";
}

///It would probably be better to move all of this code to jasp-r-pkg or something, but for now this works fine.
Expand Down
15 changes: 11 additions & 4 deletions Desktop/utilities/processhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ QProcessEnvironment ProcessHelper::getProcessEnvironmentForJaspEngine()

#undef ARCH_SUBPATH

env.insert("R_LIBS", R_HOME + "/library");
env.insert("R_LIBS", programDir.absoluteFilePath(R_HOME + "/R_cpp_includes_library") + ";" + R_HOME + "/library");

env.insert("R_ENVIRON", "something-which-doesn't-exist");
env.insert("R_PROFILE", "something-which-doesn't-exist");
Expand All @@ -72,7 +72,7 @@ QProcessEnvironment ProcessHelper::getProcessEnvironmentForJaspEngine()
env.insert("R_HOME", rHome.absolutePath());
env.insert("RHOME", rHome.absolutePath()); //For Rscript
env.insert("JASP_R_HOME", rHome.absolutePath()); //Used by the modified R script in jasp-required-files/Framework/etc/bin to make sure we use the actual R of JASP! (https://github.com/jasp-stats/INTERNAL-jasp/issues/452)
env.insert("R_LIBS", rHome.absoluteFilePath("library") + ":" + programDir.absoluteFilePath("R/library"));
env.insert("R_LIBS", programDir.absoluteFilePath("../R/R_cpp_includes_library") + ":" + rHome.absoluteFilePath("library") + ":" + programDir.absoluteFilePath("R/library") + custom_R_library);
env.insert("JAGS_HOME", rHome.absolutePath() + "/opt/jags/lib/JAGS/");
// env.insert("JAGS_LIBDIR", rHome.absolutePath() + "/opt/jags/lib/");

Expand All @@ -85,9 +85,11 @@ QProcessEnvironment ProcessHelper::getProcessEnvironmentForJaspEngine()
env.insert("TZDIR", TZDIR);

#else // linux
env.insert("LD_LIBRARY_PATH", rHome.absoluteFilePath("lib") + ":" + rHome.absoluteFilePath("library/RInside/lib") + ":" + rHome.absoluteFilePath("library/Rcpp/lib") + ":" + rHome.absoluteFilePath("site-library/RInside/lib") + ":" + rHome.absoluteFilePath("site-library/Rcpp/lib") + ":/app/lib/:/app/lib64/");
// env.insert("LD_LIBRARY_PATH", rHome.absoluteFilePath("lib") + ":" + rHome.absoluteFilePath("library/RInside/lib") + ":" + rHome.absoluteFilePath("library/Rcpp/lib") + ":" + rHome.absoluteFilePath("site-library/RInside/lib") + ":" + rHome.absoluteFilePath("site-library/Rcpp/lib") + ":/app/lib/:/app/lib64/");
env.insert("R_HOME", rHome.absolutePath());
env.insert("R_LIBS", programDir.absoluteFilePath("R/library") + custom_R_library + ":" + rHome.absoluteFilePath("library") + ":" + rHome.absoluteFilePath("site-library"));
// env.insert("R_LIBS", programDir.absoluteFilePath("R/library") + custom_R_library + ":" + rHome.absoluteFilePath("library") + ":" + rHome.absoluteFilePath("site-library") + ":" + programDir.absoluteFilePath("../R/R_cpp_includes_library"));
// TODO: the last one should be the sandbox, not the actual library!
env.insert("R_LIBS", programDir.absoluteFilePath("../R/R_cpp_includes_library") + ":" + programDir.absoluteFilePath("R/library") + custom_R_library);
#endif

env.insert("R_LIBS_SITE", "");
Expand All @@ -98,5 +100,10 @@ QProcessEnvironment ProcessHelper::getProcessEnvironmentForJaspEngine()
env.insert("R_LIBS_USER", (AppDirs::programDir().absolutePath().toStdString() + "/../R/library").c_str());
#endif

Log::log() << "R_LIBS:" << env.value("R_LIBS") << "\n" <<
"R_LIBS_USER:" << env.value("R_LIBS_USER") << "\n" <<
"LD_LIBRARY_PATH:" << env.value("LD_LIBRARY_PATH") << "\n" <<
std::endl;

return(env);
}
5 changes: 4 additions & 1 deletion Engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,16 @@ void Engine::receiveModuleRequestMessage(const Json::Value & jsonRequest)
std::string moduleCode = jsonRequest["moduleCode"].asString();
std::string moduleName = jsonRequest["moduleName"].asString();

Log::log() << "About to run module request for module '" << moduleName << "' and code to run:\n'" << moduleCode << "'" << std::endl;
Log::log() << "About to run module request for module '" << moduleName << "' and code to run:\n'" << moduleCode << "'" << std::endl;

std::string result = jaspRCPP_evalRCode(moduleCode.c_str(), false);
bool succes = result == "succes!"; //Defined in DynamicModule::succesResultString()

Log::log() << "Was " << (succes ? "succesful" : "a failure") << ", now crafting answer." << std::endl;

if(moduleStatusFromString((moduleRequest)) == moduleStatus::loading)
jaspRCPP_init_jaspBase();

Json::Value jsonAnswer = Json::objectValue;

jsonAnswer["moduleRequest"] = moduleRequest;
Expand Down
1 change: 1 addition & 0 deletions Engine/jaspModuleInstaller
Submodule jaspModuleInstaller added at 89ee61
23 changes: 23 additions & 0 deletions Modules/Rcpp_RInside.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"R": {
"Version": "4.3.1",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cran.rstudio.com"
}
]
},
"Packages": {
"RInside": {
"Package": "RInside",
"Version": "0.2.18",
"Source": "Repository"
},
"Rcpp": {
"Package": "Rcpp",
"Version": "1.0.11",
"Source": "Repository"
}
}
}
9 changes: 0 additions & 9 deletions Modules/install-RInside.R.in

This file was deleted.

64 changes: 0 additions & 64 deletions Modules/install-jaspBase.R.in

This file was deleted.

93 changes: 93 additions & 0 deletions Modules/install-jaspModuleInstaller.R.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Generated from install-jaspBase.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")

#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")
source("@PROJECT_SOURCE_DIR@/Engine/jaspModuleInstaller/R/installModule.R")

# The R_LIBRARY_PATH might already be there, but depending on the configuration
# of the CMake, we might be installing in a different location, so, I just add
# it anyway! It gets to if-y.

if (@IS_FLATPAK_USED@) {
source("/app/lib64/Rprofile.R")
options(repos = "@R_REPOSITORY@")
}

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

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")

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
)

print("Installing jaspModuleInstaller")
.libPaths(JASPMODULEINSTALLER_LIBRARY)
setupRenv("@R_LIBRARY_PATH@", modulePkg)

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")

# 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)



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") {
source('@MODULES_BINARY_PATH@/symlinkTools.R')
convertAbsoluteSymlinksToRelative('@R_LIBRARY_PATH@', '@MODULES_RENV_CACHE_PATH@')
}
68 changes: 31 additions & 37 deletions Modules/install-module.R.in
Original file line number Diff line number Diff line change
@@ -1,60 +1,54 @@
# Generated from install-module.R.in
#
Sys.setenv(PATH=paste0("@R_HOME_PATH@/bin", .Platform$path.sep, Sys.getenv("PATH"))) #Make sure any Rscript calls use ours
Sys.setenv(RHOME="@R_HOME_PATH@") #Rscript looks for RHOME not R_HOME
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(JASPENGINE_LOCATION="@JASP_ENGINE_PATH@/JASPEngine")
Sys.setenv(JAGS_PREFIX="@jags_HOME@")
Sys.setenv(JAGS_INCLUDEDIR="@jags_INCLUDE_DIRS@")
Sys.setenv(JAGS_LIBDIR="@jags_LIBRARY_DIRS@")
Sys.setenv(JASP_R_INTERFACE_LIBRARY="Yes, do it")
Sys.setenv(PATH=paste0(file.path("@R_HOME_PATH@", "bin"), .Platform$path.sep, Sys.getenv("PATH"))) #Make sure any Rscript calls use ours
Sys.setenv(RHOME = "@R_HOME_PATH@") #Rscript looks for RHOME not R_HOME
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")
Sys.setenv(JAGS_PREFIX = "@jags_HOME@")
Sys.setenv(JAGS_INCLUDEDIR = "@jags_INCLUDE_DIRS@")
Sys.setenv(JAGS_LIBDIR = "@jags_LIBRARY_DIRS@")
Sys.setenv(JASP_R_INTERFACE_LIBRARY = "Yes, do it")

options(renv.config.install.verbose = TRUE)

if (@IS_LINUX_LOCAL_BUILD@) {
# Only set when building using LINUX_LOCAL_BUILD. This is to help jags finds its libraries
Sys.setenv(LD_LIBRARY_PATH="@jags_LIBRARY_DIRS@")
# Only set when building using LINUX_LOCAL_BUILD. This is to help jags finds its libraries
Sys.setenv(LD_LIBRARY_PATH="@jags_LIBRARY_DIRS@")
}


if (@IS_FLATPAK_USED@) {
source('/app/lib64/Rprofile.R');
source('/app/lib64/Rprofile.R');
}

# The R_LIBRARY_PATH might already be there, but depending on the configuration
# of the CMake, we might be installing in a different location, so, I just add
# it anyway! It gets to if-y.
.libPaths(c("@R_LIBRARY_PATH@"))
.libPaths("@JASPMODULEINSTALLER_LIBRARY@")
sandboxPaths <- renv:::renv_sandbox_activate()

options(
configure.vars = c(jaspBase = "INCLUDE_DIR='@PROJECT_SOURCE_DIR@/Common'") #Needed for flatpak build as it keeps recompiling jaspBase (which it shouldnt of course but I dont know why) and this is an easy fix to get it to work now
configure.vars = c(jaspBase = "INCLUDE_DIR='@PROJECT_SOURCE_DIR@/Common'"), #Needed for flatpak build as it keeps recompiling jaspBase (which it shouldnt of course but I dont know why) and this is an easy fix to get it to work now
PKGDEPENDS_LIBRARY = "@PKGDEPENDS_LIBRARY@"
)

if (jaspBase::getOS() == "osx") {
options(pkgType = "mac.binary")
} else if (jaspBase::getOS() == "windows") {
options(pkgType = "win.binary")
}

# Related to the comment above, there is variable here called,
# `libPathsToUse` but it is not connected to anything. If this works,
# then, I don't need to set the libPaths() anymore perhaps.
result <- jaspBase::installJaspModule("@MODULES_SOURCE_PATH@/@MODULE@",
repos="@R_REPOSITORY@",
moduleLibrary="@MODULES_BINARY_PATH@/@MODULE@",
onlyModPkg=FALSE,
libPathsToUse='',
frameworkLibrary="@R_LIBRARY_PATH@")
options(error = recover)
jaspModuleInstaller::installJaspModule(
modulePkg = "@MODULES_SOURCE_PATH@/@MODULE@",
repos = "@R_REPOSITORY@",
moduleLibrary = "@MODULES_BINARY_PATH@/@MODULE@",
onlyModPkg = FALSE,
frameworkLibrary = "@R_LIBRARY_PATH@"
)

result <- "succes"
if (result == "succes") {
cat(NULL, file="@MODULES_RENV_ROOT_PATH@/@[email protected]")
cat(NULL, file="@MODULES_RENV_ROOT_PATH@/@[email protected]")
}

# 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") {
source('@MODULES_BINARY_PATH@/symlinkTools.R')
convertAbsoluteSymlinksToRelative('@MODULES_BINARY_PATH@', '@MODULES_RENV_CACHE_PATH@')
if (Sys.info()["sysname"] == "Darwin") {
source('@MODULES_BINARY_PATH@/symlinkTools.R')
convertAbsoluteSymlinksToRelative('@MODULES_BINARY_PATH@', '@MODULES_RENV_CACHE_PATH@')
}
Loading

0 comments on commit 22341ae

Please sign in to comment.