1# 2# SessionClang.R 3# 4# Copyright (C) 2021 by RStudio, PBC 5# 6# Unless you have received this program directly from RStudio pursuant 7# to the terms of a commercial license agreement with RStudio, then 8# this program is licensed to you under the terms of version 3 of the 9# GNU Affero General Public License. This program is distributed WITHOUT 10# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13# 14# 15 16 17 18.rs.addFunction("clangPCHPath", function(pkg, clangVersion) 19{ 20 paste( 21 packageVersion(pkg), 22 R.version$platform, 23 R.version$`svn rev`, 24 clangVersion, 25 sep = "-" 26 ) 27}) 28 29.rs.addFunction("isClangAvailable", function() { 30 cat("Attemping to load libclang for", R.version$platform, "\n") 31 .Call("rs_isLibClangAvailable", PACKAGE = "(embedding)") 32}) 33 34.rs.addFunction("setClangDiagnostics", function(level) 35{ 36 if (!is.numeric(level) || (level < 0) || (level > 2)) 37 stop("level must be 0, 1, or 2") 38 39 if (level > 0) 40 .rs.isClangAvailable() 41 42 .Call("rs_setClangDiagnostics", level, PACKAGE = "(embedding)") 43 44 .rs.restartR() 45 invisible(NULL) 46}) 47 48.rs.addFunction("packagePCH", function(linkingTo) 49{ 50 linkingTo <- .rs.parseLinkingTo(linkingTo) 51 packages <- c("RcppArmadillo", "RcppEigen", "Rcpp11", "Rcpp") 52 for (package in packages) 53 if (package %in% linkingTo) 54 return(package) 55 "" 56}) 57 58.rs.addFunction("includesForLinkingTo", function(linkingTo) 59{ 60 includes <- character() 61 62 linkingTo <- .rs.parseLinkingTo(linkingTo) 63 for (pkg in linkingTo) { 64 includeDir <- system.file("include", package = pkg) 65 if (file.exists(includeDir)) { 66 includes <- c( 67 includes, 68 paste("-I", .rs.asBuildPath(includeDir), sep = "") 69 ) 70 } 71 } 72 73 includes 74}) 75 76.rs.addFunction("asBuildPath", function(path) 77{ 78 if (.Platform$OS.type == "windows") { 79 path <- normalizePath(path) 80 if (grepl(' ', path, fixed = TRUE)) 81 path <- utils::shortPathName(path) 82 path <- gsub("\\\\", "/", path) 83 } 84 85 return(path) 86}) 87 88 89 90 91