From cc7a5cc72ce6f2a7365b64737635487e675c988e Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Tue, 1 Oct 2019 13:56:23 -0700 Subject: [PATCH] use helper R function for getting tinytex bin --- src/cpp/core/include/core/system/Xdg.hpp | 18 ++++++++++----- src/cpp/session/SessionModuleContext.cpp | 26 ++++++++++------------ src/cpp/session/modules/SessionRMarkdown.R | 15 ++++++++++++- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/cpp/core/include/core/system/Xdg.hpp b/src/cpp/core/include/core/system/Xdg.hpp index 0e0b5b4eb2d..cd18e3f1c40 100644 --- a/src/cpp/core/include/core/system/Xdg.hpp +++ b/src/cpp/core/include/core/system/Xdg.hpp @@ -31,16 +31,22 @@ namespace xdg { * All of these can be configured with environment variables as described below. */ -// Returns the RStudio XDG user config directory. On Unix-alikes, this is ~/.config/rstudio, or -// XDG_CONFIG_HOME. +// Returns the RStudio XDG user config directory. +// +// On Unix-alikes, this is ~/.config/rstudio, or XDG_CONFIG_HOME. +// On Windows, this is 'FOLDERID_RoamingAppData' (typically 'AppData/Roaming'). FilePath userConfigDir(); -// Returns the RStudio XDG user data directory. On Unix-alikes, this is ~/.local/share/rstudio, or -// XDG_DATA_HOME +// Returns the RStudio XDG user data directory. +// +// On Unix-alikes, this is ~/.local/share/rstudio, or XDG_DATA_HOME. +// On Windows, this is 'FOLDERID_LocalAppData' (typically 'AppData/Local'). FilePath userDataDir(); -// Returns the RStudio XDG system config directory. On Unix-alikes, this is /etc/rstudio, or -// XDG_CONFIG_DIRS +// Returns the RStudio XDG system config directory. +// +// On Unix-alikes, this is /etc/rstudio, XDG_CONFIG_DIRS. +// On Windows, this is 'FOLDERID_ProgramData' (typically 'C:/ProgramData'). FilePath systemConfigDir(); } // namespace xdg diff --git a/src/cpp/session/SessionModuleContext.cpp b/src/cpp/session/SessionModuleContext.cpp index 03eeedefe46..1fe2422e08e 100644 --- a/src/cpp/session/SessionModuleContext.cpp +++ b/src/cpp/session/SessionModuleContext.cpp @@ -1074,20 +1074,18 @@ bool addTinytexToPathIfNecessary() { if (isPdfLatexInstalled()) return false; - - FilePath binPath; - -#if defined(_WIN32) - FilePath appData(core::system::getenv("APPDATA")); - binPath = appData.complete("TinyTeX\\bin\\win32"); -#elif defined(__APPLE__) - binPath = resolveAliasedPath("~/Library/TinyTeX/bin/x86_64-darwin"); -#else - binPath = resolveAliasedPath("~/bin"); -#endif - - if (binPath.childPath("pdflatex").exists()) - core::system::addToSystemPath(binPath); + + std::string binDir; + Error error = r::exec::RFunction(".rs.tinytexBin").call(&binDir); + if (error) + LOG_ERROR(error); + + FilePath binPath = module_context::resolveAliasedPath(binDir); + if (!binPath.exists()) + return false; + + core::system::addToSystemPath(binPath); + return true; } bool isPdfLatexInstalled() diff --git a/src/cpp/session/modules/SessionRMarkdown.R b/src/cpp/session/modules/SessionRMarkdown.R index f667b59b17a..a8f866b0494 100644 --- a/src/cpp/session/modules/SessionRMarkdown.R +++ b/src/cpp/session/modules/SessionRMarkdown.R @@ -462,4 +462,17 @@ FALSE }) - +.rs.addFunction("tinytexBin", function() +{ + if (!requireNamespace("tinytex", quietly = TRUE)) + return(NULL) + + # NOTE: binary directory has a single arch-specific subdir; + # rather than trying to hard-code the architecture we just + # infer it directly + root <- tinytex:::tinytex_root() + bin <- file.path(root, "bin") + subbin <- list.files(bin, full.names = TRUE) + subbin[[1]] + +})