blob: 7e64e060ec1e562d504faf43eb4d6306da9b8ad3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
From 6a8348988fcd961a67d709aa37c5defd7159b27b Mon Sep 17 00:00:00 2001
From: Ricardo Wurmus <rekado@elephly.net>
Date: Fri, 18 Dec 2020 10:26:44 +0100
Subject: [PATCH 1/7] handleClientInit: Store R versions in sessionInfo.
This unlocks the multi-version feature needed to initialize version
selection widgets.
* src/cpp/session/SessionClientInit.cpp (handleClientInit): Read
version entries from /etc/rstudio/r-versions via the RVersionsScanner.
Add discovered entries to a JSON array at the sessionInfo object
r_versions_info->available_r_versions.
---
src/cpp/session/SessionClientInit.cpp | 31 ++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/cpp/session/SessionClientInit.cpp b/src/cpp/session/SessionClientInit.cpp
index e4b3b7dd71..52523fc896 100644
--- a/src/cpp/session/SessionClientInit.cpp
+++ b/src/cpp/session/SessionClientInit.cpp
@@ -2,6 +2,7 @@
* SessionClientInit.hpp
*
* Copyright (C) 2021 by RStudio, PBC
+ * Copyright (C) 2020 Ricardo Wurmus
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
@@ -62,6 +63,8 @@
#include <core/http/CSRFToken.hpp>
#include <core/system/Environment.hpp>
+#include <server_core/RVersionsScanner.hpp>
+
#include <session/SessionConsoleProcess.hpp>
#include <session/SessionClientEventService.hpp>
#include <session/SessionHttpConnection.hpp>
@@ -507,11 +510,29 @@ void handleClientInit(const boost::function<void()>& initFunction,
sessionInfo["multi_session"] = options.multiSession();
- json::Object rVersionsJson;
- rVersionsJson["r_version"] = module_context::rVersion();
- rVersionsJson["r_version_label"] = module_context::rVersionLabel();
- rVersionsJson["r_home_dir"] = module_context::rHomeDir();
- sessionInfo["r_versions_info"] = rVersionsJson;
+ // Read versions from /etc/rstudio/r-versions
+ json::Array availableRVersionsJson;
+ std::vector<r_util::RVersion> versions = RVersionsScanner().getRVersions();
+ for (r_util::RVersion& rEntry : versions)
+ {
+ json::Object rVersionJson;
+ rVersionJson["version"] = rEntry.number();
+ rVersionJson["label"] = rEntry.label();
+ rVersionJson["r_home"] = rEntry.homeDir().getAbsolutePath();
+
+ availableRVersionsJson.push_back(rVersionJson);
+ }
+
+ json::Object rVersionsInfo;
+ rVersionsInfo["available_r_versions"] = availableRVersionsJson;
+ rVersionsInfo["r_version"] = module_context::rVersion();
+ rVersionsInfo["r_version_label"] = module_context::rVersionLabel();
+ rVersionsInfo["r_home"] = module_context::rHomeDir();
+ rVersionsInfo["default_r_version"] = module_context::rVersion();
+ rVersionsInfo["default_r_version_label"] = module_context::rVersionLabel();
+ rVersionsInfo["default_r_home_dir"] = module_context::rHomeDir();
+ rVersionsInfo["restore_project_r_version"] = true;
+ sessionInfo["r_versions_info"] = rVersionsInfo;
sessionInfo["show_user_home_page"] = options.showUserHomePage();
sessionInfo["user_home_page_url"] = json::Value();
--
2.31.1
|