feat(positron-r): support portable Mac R builds#13325
Open
jmwoliver wants to merge 1 commit into
Open
Conversation
When the R wrapper's hardcoded R_HOME_DIR doesn't point at a real R install, derive R_HOME from dirname(dirname(realpath(binpath))) instead. This rescues portable Mac R builds (rstudio/r-builds#284) extracted to arbitrary locations, where the build-time R_HOME_DIR baked into bin/R is stale. getRHomePathDarwin now follows a try-then-validate-then-fallback flow: 1. Parse R_HOME_DIR from the script. 2. If it validates (DESCRIPTION exists at <home>/library/utils) AND the binpath actually lives under it (realpath check), return it. The binpath-under-home guard prevents conflation: a portable R-4.5.3 with R_HOME_DIR baked to /Library/.../4.5-arm64/Resources will validate against a CRAN R 4.5.1 installed at that same path on the user's machine. Without the guard the portable would silently register with CRAN's homepath and version. 3. Otherwise derive R_HOME from the binpath. realpath the binpath first so a shim like /usr/local/bin/R points at the real script. 4. If neither validates, return undefined as before. New file-private helpers: derivedRHomePathDarwin, hasRBaseLibrary, binpathIsUnder. Linux and Windows discovery are unchanged. The RInstallation constructor's existing DESCRIPTION check stays as a final cross-platform guard. New unit tests in extensions/positron-r/src/test/r-installation.test.ts cover all five rows of the behavior matrix: - parsed R_HOME_DIR validates and binpath lives under it -> returned - parsed is stale and points at nothing -> derived rescues - parsed validates but binpath lives elsewhere (conflation) -> derived rescues - neither validates -> undefined - not an R wrapper script -> undefined Refs rstudio/r-builds#284.
|
E2E Tests 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The portable Mac R builds from rstudio/r-builds#284 that we just merged let you extract a tarball anywhere and have R work. Historically, Mac R builds have not been relocatable so Positron did not support this.
On Mac, the R wrapper script bakes in an absolute
R_HOME_DIRline at build time. Positron read that line and used it as-is, so portable installs ended up pointing at a path that didn't exist on the user's machine. If the user happened to have a CRAN R at that same path, Positron silently registered the portable with the CRAN install's metadata instead.The fix adds a path-derived fallback to
getRHomePathDarwin: if the parsedR_HOME_DIRdoesn't validate, or the binary doesn't actually live under it, fall back todirname(dirname(realpath(binpath))). This implements similar relative path discovery used by Windows since R is already relocatable on Windows. System R installs still take the parsed path; portable builds get rescued by the fallback.Test plan
Download a Mac R tarball and extract it:
Point Positron at it via user settings (adjust the path if you extracted elsewhere):
On current
mainthe portable install is rejected:On this branch it registers correctly with the right version and homepath: