diff options
Diffstat (limited to 'patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch')
| -rw-r--r-- | patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch b/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch new file mode 100644 index 0000000..5105001 --- /dev/null +++ b/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | From 6172ab0908e8b80bd5838ed4336335d224b80941 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Ricardo Wurmus <rekado@elephly.net> | ||
| 3 | Date: Fri, 18 Dec 2020 10:32:01 +0100 | ||
| 4 | Subject: [PATCH 2/7] sessionProcessConfig: Configure R version from active | ||
| 5 | session. | ||
| 6 | |||
| 7 | When switching projects the R version is recorded in the active | ||
| 8 | session. Before launching a new rsession process R environment | ||
| 9 | variables need to be set to select the variant of libR.so that should | ||
| 10 | be used to launch the embedded R. | ||
| 11 | |||
| 12 | * src/cpp/server/ServerSessionManager.cpp (sessionProcessConfig): | ||
| 13 | Configure R environment using the R version that has been recorded in | ||
| 14 | the active session. | ||
| 15 | --- | ||
| 16 | src/cpp/server/ServerSessionManager.cpp | 26 ++++++++++++++++++++++++- | ||
| 17 | 1 file changed, 25 insertions(+), 1 deletion(-) | ||
| 18 | |||
| 19 | diff --git a/src/cpp/server/ServerSessionManager.cpp b/src/cpp/server/ServerSessionManager.cpp | ||
| 20 | index 6e37578cab..86d212779a 100644 | ||
| 21 | --- a/src/cpp/server/ServerSessionManager.cpp | ||
| 22 | +++ b/src/cpp/server/ServerSessionManager.cpp | ||
| 23 | @@ -2,6 +2,7 @@ | ||
| 24 | * ServerSessionManager.cpp | ||
| 25 | * | ||
| 26 | * Copyright (C) 2021 by RStudio, PBC | ||
| 27 | + * Copyright (C) 2020-2021 Ricardo Wurmus | ||
| 28 | * | ||
| 29 | * Unless you have received this program directly from RStudio pursuant | ||
| 30 | * to the terms of a commercial license agreement with RStudio, then | ||
| 31 | @@ -21,10 +22,14 @@ | ||
| 32 | |||
| 33 | #include <shared_core/SafeConvert.hpp> | ||
| 34 | #include <core/system/Process.hpp> | ||
| 35 | +#include <shared_core/system/User.hpp> | ||
| 36 | #include <core/system/PosixUser.hpp> | ||
| 37 | #include <core/system/Environment.hpp> | ||
| 38 | #include <core/json/JsonRpc.hpp> | ||
| 39 | |||
| 40 | +#include <core/r_util/RActiveSessions.hpp> | ||
| 41 | +#include <core/r_util/RUserData.hpp> | ||
| 42 | + | ||
| 43 | #include <monitor/MonitorClient.hpp> | ||
| 44 | #include <session/SessionConstants.hpp> | ||
| 45 | |||
| 46 | @@ -156,7 +161,26 @@ core::system::ProcessConfig sessionProcessConfig( | ||
| 47 | std::copy(extraArgs.begin(), extraArgs.end(), std::back_inserter(args)); | ||
| 48 | |||
| 49 | // append R environment variables | ||
| 50 | - r_util::RVersion rVersion = r_environment::rVersion(); | ||
| 51 | + // Get the active session (e.g. after switching projects) and set R | ||
| 52 | + // variables according to the configured R version. | ||
| 53 | + core::system::User user; | ||
| 54 | + core::system::User::getUserFromIdentifier(context.username, user); | ||
| 55 | + FilePath userScratchPath_ = core::system::xdg::userDataDir(context.username); | ||
| 56 | + | ||
| 57 | + r_util::ActiveSessions activeSessions(userScratchPath_); | ||
| 58 | + std::vector<boost::shared_ptr<r_util::ActiveSession> > sessions = | ||
| 59 | + activeSessions.list(user.getHomePath(), false); | ||
| 60 | + | ||
| 61 | + r_util::RVersion rVersion; | ||
| 62 | + if (sessions.size() > 0) { | ||
| 63 | + // Get the R version from the active user session. This will | ||
| 64 | + // have been set earlier when the user switched to a project. | ||
| 65 | + std::string errorMsg; | ||
| 66 | + bool success = r_environment::detectRVersion(FilePath((*sessions.front()).rVersionHome()).completePath("bin/R"), | ||
| 67 | + &rVersion, &errorMsg); | ||
| 68 | + } else { | ||
| 69 | + rVersion = r_environment::rVersion(); | ||
| 70 | + } | ||
| 71 | core::system::Options rEnvVars = rVersion.environment(); | ||
| 72 | environment.insert(environment.end(), rEnvVars.begin(), rEnvVars.end()); | ||
| 73 | |||
| 74 | -- | ||
| 75 | 2.31.1 | ||
| 76 | |||
