git: 9884a43067a4 - main - devel/RStudio: Fix bug that RStudio-server didn't have /usr/local/bin in PATH

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Tue, 29 Aug 2023 08:39:47 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=9884a43067a47d9f4088306ad29d1ec373b25eee

commit 9884a43067a47d9f4088306ad29d1ec373b25eee
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2023-08-29 08:37:27 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2023-08-29 08:39:44 +0000

    devel/RStudio: Fix bug that RStudio-server didn't have /usr/local/bin in PATH
    
    This was previously fixed in post-install but the previous fix
    relied on the other path that changed, which eroded this fix.
    
    The new fix adds /usr/local/bin to PATH in the C++ code.
---
 devel/RStudio/Makefile                             | 12 +++++------
 .../patch-src_cpp_session_modules_SessionGit.cpp   | 24 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/devel/RStudio/Makefile b/devel/RStudio/Makefile
index dcc39863ecb0..a6df10b46383 100644
--- a/devel/RStudio/Makefile
+++ b/devel/RStudio/Makefile
@@ -4,7 +4,7 @@
 PORTNAME=	RStudio
 DISTVERSIONPREFIX=	v
 DISTVERSION=	2022.12.0+353
-PORTREVISION=	4
+PORTREVISION=	5
 CATEGORIES=	devel math java
 MASTER_SITES=	https://s3.amazonaws.com/rstudio-buildtools/dictionaries/:dictionaries \
 		https://s3.amazonaws.com/rstudio-buildtools/:buildtools
@@ -117,6 +117,10 @@ post-patch:
 	@${REINPLACE_CMD} -e ' \
 		s|<condition property="node.bin" value="../../../$${node.dir}/bin/node">|<condition property="node.bin" value="${LOCALBASE}/bin/node">|' \
 		${WRKSRC}/src/gwt/build.xml
+	# add $PREFIX/bin to PATH for the server daemon
+.if ${FLAVOR:U} == server
+	@${REINPLACE_CMD} -e 's|%%PREFIX%%|${PREFIX}|' ${WRKSRC}/src/cpp/session/modules/SessionGit.cpp
+.endif
 
 pre-build:
 	@${CP} ${FILESDIR}/global-setenv.h ${WRKSRC}/src/cpp/desktop/
@@ -143,12 +147,6 @@ post-install:
 	# Some functions expect the pandoc symlink.
 	@${MKDIR} ${STAGEDIR}${PREFIX}/lib/${INSTALL_SUBDIR}/bin/pandoc
 	@cd ${STAGEDIR}${PREFIX}/lib/${INSTALL_SUBDIR}/bin/pandoc && ${LN} -s ../../../../bin/pandoc
-	# Add $LOCALBASE/bin to PATH to allow RStudio-server to run gmake (R_HOME/etc/Renviron.site is installed, see https://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html)
-.if ${FLAVOR:U} == server
-	#@${MKDIR} ${STAGEDIR}${LOCALBASE}/lib/R/etc
-	#@${ECHO} "PATH=\"${LOCALBASE}/bin:\$$PATH\"" > ${STAGEDIR}${LOCALBASE}/lib/R/etc/Renviron.site # it should be this way, but this fails: https://github.com/rstudio/rstudio/issues/9815
-	@${LN} -s ${LOCALBASE}/bin/${GMAKE} ${STAGEDIR}${PREFIX}/lib/rstudio-server/bin/postback/${GMAKE} # hack, should be as above, but at least gmake is in the path now
-.endif
 	# There is a variability in .js file names due to use of random numbers, so we use the automatic plist.
 	@${SETENV} ${CO_ENV} ${SH} ${SCRIPTSDIR}/check-stagedir.sh makeplist | ${GREP} -v ^\/ | ${SED} -e 's|%%WWWDIR%%|www/rstudio| ; s|%%CMAKE_BUILD_TYPE%%|${CMAKE_BUILD_TYPE:tl}|' > ${TMPPLIST}
 
diff --git a/devel/RStudio/files/patch-src_cpp_session_modules_SessionGit.cpp b/devel/RStudio/files/patch-src_cpp_session_modules_SessionGit.cpp
new file mode 100644
index 000000000000..c72a605a439a
--- /dev/null
+++ b/devel/RStudio/files/patch-src_cpp_session_modules_SessionGit.cpp
@@ -0,0 +1,24 @@
+- add path %%PREFIX%%/bin to PATH so that gmake and cmake executable would be found
+
+--- src/cpp/session/modules/SessionGit.cpp.orig	2023-08-29 01:47:30 UTC
++++ src/cpp/session/modules/SessionGit.cpp
+@@ -130,6 +130,9 @@ core::system::ProcessOptions procOptions()
+    FilePath postbackDir = session::options().rpostbackPath().getParent();
+    core::system::addToPath(&childEnv, postbackDir.getAbsolutePath());
+ 
++   // add $PREFIX/bin to path
++   core::system::addToPath(&childEnv, "%%PREFIX%%/bin");
++
+    options.workingDir = projects::projectContext().directory();
+ 
+ #ifdef _WIN32
+@@ -3370,6 +3373,9 @@ core::Error initialize()
+    }
+ 
+    core::system::addToPath(postbackDir.getAbsolutePath());
++
++   // add $PREFIX/bin to path
++   core::system::addToPath("%%PREFIX%%/bin");
+ 
+    // add suspend/resume handler
+    addSuspendHandler(SuspendHandler(boost::bind(onSuspend, _2), onResume));