blob: ea0573a259030c75791e96078d4817a3c3aa79a2 (
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
76
77
78
79
|
From 72b511ab4ab4bd60cabb54c66fe3e78d669791fb 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 | 35 ++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/src/cpp/session/SessionClientInit.cpp b/src/cpp/session/SessionClientInit.cpp
index 5610f4cffd..649f648e25 100644
--- a/src/cpp/session/SessionClientInit.cpp
+++ b/src/cpp/session/SessionClientInit.cpp
@@ -2,6 +2,7 @@
* SessionClientInit.hpp
*
* Copyright (C) 2022 by Posit Software, PBC
+ * Copyright (C) 2020-2026 Ricardo Wurmus
*
* Unless you have received this program directly from Posit Software pursuant
* to the terms of a commercial license agreement with Posit Software, then
@@ -63,6 +64,8 @@
#include <core/r_util/RSessionContext.hpp>
#include <core/system/Environment.hpp>
+#include <server_core/RVersionsScanner.hpp>
+
#include <session/SessionConsoleProcess.hpp>
#include <session/SessionClientEventService.hpp>
#include <session/SessionHttpConnection.hpp>
@@ -573,12 +576,32 @@ 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();
- rVersionsJson["r_version_module"] = module_context::rVersionModule();
- 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();
+ rVersionJson["r_version_module"] = rEntry.module();
+
+ 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_dir"] = module_context::rHomeDir();
+ rVersionsInfo["r_version_module"] = module_context::rVersionModule();
+ rVersionsInfo["default_r_version"] = module_context::rVersion();
+ rVersionsInfo["default_r_version_label"] = module_context::rVersionLabel();
+ rVersionsInfo["default_r_version_module"] = module_context::rVersionModule();
+ 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.52.0
|