Skip to content

make builds resolve gitignored deps from the primary git worktree - #18030

Merged
kevinushey merged 4 commits into
mainfrom
developer/worktree-build-deps
Jun 22, 2026
Merged

kevinushey merged 4 commits into
mainfrom
developer/worktree-build-deps

Conversation

@kevinushey

@kevinushey kevinushey commented Jun 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Building from a secondary git worktree did not work out of the box: a freshly added worktree has empty dependency directories (node, gwtproject, quarto, etc. are gitignored and only populated in the primary checkout). This caused:

  • cmake configure to fail on the panmirror/quarto script (session/CMakeLists.txt), requiring a manual symlink;
  • node-based steps to use whatever node was on the developer's PATH — a mismatched system node (e.g. v26 vs the pinned 22.22.2) breaks npm postinstall.

src/gwt/build.xml already solved this for ant via ${git.main.worktree}. This PR extends the same idea to the other build entry points so worktree builds "just work" with no symlinks or manual node management.

Changes (all additive and gated)

  • cmake/git-worktree.cmake (new): resolves the primary checkout via git rev-parse --path-format=absolute --git-common-dir into RSTUDIO_GIT_MAIN_WORKTREE (empty when not in a git checkout; callers tolerate that).
  • cmake/globals.cmake: when this checkout's dependencies/ has no downloaded content, borrow the primary worktree's. Also auto-enable a compiler cache for development builds (see below).
  • src/cpp/session/CMakeLists.txt: fall back to the primary worktree for the gitignored panmirror/quarto md-writer.lua (the hard configure failure).
  • src/node/CMakeNodeTools.txt: fall back to the primary worktree's node toolchain (the Apple arm64 branch had no fallback at all).
  • e2e/rstudio/scripts/dev-common.ts: prepend the pinned node (resolved local → primary worktree → tools) to PATH for spawned npx/npm run start, so the dev e2e flow uses the project node, not a stray system node.

CI/official builders resolve their existing paths first (global tools dir / source tree), so they are unaffected.

Compiler cache (ccache / sccache)

For development builds only, auto-enable a compiler cache when available (opt out with -DRSTUDIO_USE_CCACHE=OFF):

  • Searches the architecture-appropriate Homebrew prefix first (/opt/homebrew/bin on Apple Silicon, /usr/local/bin otherwise) so a native tool wins over an x86_64 one in the Intel-Homebrew tree.
  • Accepts either ccache or sccache (both work as CMAKE_<LANG>_COMPILER_LAUNCHER); prefers ccache.
  • Each candidate is validated by an anchored --version match. This rejects a ccache that is actually a symlink to sccache — sccache invoked under the name ccache misparses cmake's -E feature probes and breaks the build; the real sccache is then found by its own name and used safely.

Coexistence with the existing SCCACHE_ENABLED mechanism: package/CI builds (package/osx, package/linux) already opt into sccache via the SCCACHE_ENABLED env/cmake var, wired through cmake/modules/sccache.cmake. Those builds also pass -DRSTUDIO_TARGET, so RSTUDIO_DEVELOPMENT is unset and this dev block never runs there. As belt-and-suspenders, the dev block also explicitly defers when SCCACHE_ENABLED is set, so the two mechanisms can never both configure a launcher (verified: with SCCACHE_ENABLED=1, sccache.cmake wins; without it, dev builds auto-select ccache).

Verification

In a clean secondary worktree (no manual setup):

  • cmake configure succeeds with no quarto symlink (resolves the primary worktree + its deps).
  • Full C++ build (rsession): 878/879 steps, 0 errors.
  • Compiler cache selects the genuine arm64 /opt/homebrew/bin/ccache; a rstudio-core build engages it (196/196 cacheable calls) with no breakage; the broken x86 ccache→sccache symlink is correctly rejected; SCCACHE_ENABLED=1 correctly defers to sccache.cmake.
  • CMakeNodeTools node resolution and the dev-common node resolution each verified to resolve to the primary checkout's node (the full packaged-desktop build was not run; the dev e2e flow uses npm run start, where the dev-common PATH pinning applies).
  • Reviewed package/osx (dual-arch x86_64 + arm64): unaffected — RSTUDIO_TARGET=Electron disables the dev cache block, and the deps/quarto/node fallbacks are inert when packaging from the main checkout.

Developer-ergonomics change; no associated issue.

A freshly added `git worktree` has empty dependency directories -- node,
gwtproject, quarto, etc. are gitignored and only ever populated in the
primary checkout -- so cmake configure failed (panmirror/quarto) and npm
steps used a stray system node. src/gwt/build.xml already handled this via
${git.main.worktree}; this extends the same idea to the other tools.

- cmake/git-worktree.cmake: resolve the primary worktree via
  `git rev-parse --git-common-dir` (RSTUDIO_GIT_MAIN_WORKTREE)
- globals.cmake: fall back to the primary worktree's dependencies dir when
  this checkout has none; auto-enable ccache for development builds, but only
  a genuine ccache (a 'ccache' that is really sccache -- e.g. symlinked --
  breaks cmake's -E probes, so verify `ccache --version`)
- session/CMakeLists.txt: fall back to the primary worktree for the
  gitignored panmirror/quarto script
- CMakeNodeTools.txt: fall back to the primary worktree's node toolchain
- e2e/rstudio dev harness: prepend the pinned node (resolved the same way)
  to PATH so spawned npm/electron-forge use the project node, not a
  mismatched system node

All changes are additive and gated: CI/official builders resolve their
existing paths first and are unaffected.
@kevinushey kevinushey added this to the 2026.07 (Pacific Dogwood) milestone Jun 19, 2026
Generalize the dev compiler-cache detection:

- search /opt/homebrew/bin on Apple Silicon (and /usr/local/bin otherwise)
  first, so a native ccache/sccache is preferred over an x86_64 binary in the
  Intel-Homebrew tree
- accept either ccache or sccache as the launcher (both work as
  CMAKE_<LANG>_COMPILER_LAUNCHER), preferring ccache. Each is validated by an
  anchored `--version` match, which rejects a 'ccache' that is really a symlink
  to sccache (sccache invoked under the name 'ccache' misparses cmake's -E
  probes and breaks the build) -- the real sccache is then found by its own
  name, which works correctly.

Verified: configure selects /opt/homebrew/bin/ccache (genuine arm64 4.13.6),
and a rstudio-core build engages it (196/196 cacheable calls) with no breakage.
The package builds (package/osx, package/linux) already opt into sccache via
SCCACHE_ENABLED, wired through cmake/modules/sccache.cmake. They also pass
-DRSTUDIO_TARGET, so RSTUDIO_DEVELOPMENT is unset and the dev auto-ccache block
never runs there -- but guard it explicitly against SCCACHE_ENABLED too, so the
two mechanisms can never both configure a compiler launcher (e.g. a developer
who sets SCCACHE_ENABLED locally). With SCCACHE_ENABLED the dev block defers and
sccache.cmake wins; without it, dev builds auto-select ccache as before.
@github-actions

github-actions Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

❌ 1 test(s) failed

███████████████████░ 99% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
405 1 11 1
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · macos-26 ARM64 · commit 62e964a28c3533e4ca18d42dea77f238703ae3d2 · Run #129

@kevinushey
kevinushey requested a review from gtritchie June 20, 2026 00:23
@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

🪟 Windows Desktop E2E · Server 2025 x64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
403 0 16 1
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · Windows Server 2025 x64 · commit 62e964a28c3533e4ca18d42dea77f238703ae3d2 · Run #129

@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated multi-agent review. Strengths, dismissed findings, and ratings
are omitted. No critical issues were found.

Important

  1. e2e/rstudio/scripts/dev-common.ts:35 — const arch = process.arch === 'arm64' ? '-arm64' : ''
    applies the -arm64 dir suffix on Linux aarch64 too, but that suffix is a macOS-only convention
    in this repo (rstudio-tools.sh:74 gates on Darwin arm64; CMakeNodeTools.txt:38 on
    APPLE AND UNAME_M STREQUAL arm64). On Linux aarch64 node lives at .../node/<ver>/bin (no
    suffix), so pinnedNodeBinDir() misses and silently falls back to system node. Fix:
    process.platform === 'darwin' && process.arch === 'arm64' ? '-arm64' : ''.

Suggestions

  1. e2e/rstudio/scripts/dev-common.ts:52 — pathWithPinnedNode() returns the unmodified PATH when
    no pinned node is found, i.e. the "mismatched system node" failure the function exists to
    prevent, with no breadcrumb. Fix: emit a one-line console.warn when the fallback engages.

  2. src/node/CMakeNodeTools.txt:41 — the arm64 branch string-builds NODEJS/NPM/NPX instead of
    using find_program, so a non-existent path is still a non-empty string and passes the
    if(NODEJS) guard (line 83); the failure then surfaces later at first use rather than as the
    clear "node not found" the else-branch produces. (Pre-existing shape, not worsened here.) Fix:
    use find_program like the else branch, or add an EXISTS check before setting the vars.

  3. e2e/rstudio/scripts/dev-common.ts:13 — PINNED_NODE_VERSION = '22.22.2' is a new hardcoded
    copy of the node version not tracked by the rstudio-update-nodejs skill's file list, so a
    future bump following the skill leaves it stale (which then triggers the silent fallback in
    findings 1/2). Fix: add this file to the skill's file list, or derive the version at runtime.

  4. cmake/globals.cmake:145 — RSTUDIO_DEVELOPMENT is only set inside if(NOT RSTUDIO_TARGET)
    (line 132), so an explicit -DRSTUDIO_TARGET=Development configure never enables the compiler
    cache, narrower than the "For development builds" comment (line 136) implies. Fix: broaden the
    gate, or soften the comment to note the explicit-target case is excluded.

  5. cmake/globals.cmake:168 — the ccache and sccache detection blocks are identical but for the
    tool name (including the anchored --version symlink-rejection logic). Fix: collapse into a
    foreach(_cache_name ccache sccache) loop with break(); preserves ccache-preferred ordering
    and the anchored match while removing the copy-paste drift hazard.

  6. No unit tests added. dev-common.ts has testable pure functions (pinnedNodeBinDir,
    pathWithPinnedNode, parseDurationMs); finding 1 is exactly what a small test table would
    catch. Optional, but worth considering given the silent-failure modes.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See posted feedback

- dev-common.ts: gate the '-arm64' node dir suffix on Darwin (macOS-only
  convention); on Linux aarch64 node lives in an unsuffixed dir.
- dev-common.ts: warn when no pinned node is found before falling back to
  the system node on PATH.
- CMakeNodeTools.txt: resolve the arm64 node via find_program so a missing
  path leaves the var empty and trips the clear "not found" error rather
  than deferring the failure to first use.
- globals.cmake: collapse the ccache/sccache detection into a foreach loop
  (preserves ccache-preferred ordering and the anchored symlink-rejection),
  and note that an explicit -DRSTUDIO_TARGET=Development is intentionally
  outside the auto-enable gate.
- rstudio-update-nodejs skill: track the PINNED_NODE_VERSION constant in
  dev-common.ts so a future node bump updates it.
@kevinushey
kevinushey merged commit a9bf4a9 into main Jun 22, 2026
14 of 15 checks passed
@kevinushey
kevinushey deleted the developer/worktree-build-deps branch June 22, 2026 03:56
kevinushey added a commit that referenced this pull request Jun 22, 2026
* resolve panmirror dependency from primary worktree in gwt build

Completes #18030: lib.dir and node.dir gained a ${git.main.worktree} fallback so a fresh git worktree can borrow the primary checkout's gitignored deps, but panmirror.dir did not. Add the same fallback so 'ant draft' (and the cmake-driven GWT build) work in a secondary worktree instead of failing with '${panmirror.dir} does not exist'.

* re-enable the View() close/open race playwright test

The View()/documentCloseAllNoSave variant of the source-pane open-during-close race (#17738) was left as test.fixme when #17740 landed, because the data viewer iframe failed to finish loading even with the WindowFrame HIDE-state recovery. The data-viewer mount path has since been reworked and the race no longer reproduces -- the test passes reliably (20/20 stress runs on macOS desktop).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants