pkgload
pkgload copied to clipboard
Use of single quotes in `linking_to_flags()` on Windows can prevent compilation database from successfully loading
The use of single quotes in linking_to_flags() does not work with clangd's compilation database on Windows, as single quotes are not correctly parsed on whatever Windows shell clangd uses to parse the command args. You can see this referenced in an related problem on the clangd repo, see this issue: https://github.com/clangd/clangd/issues/1094. The single quotes are only used for the LinkingTo flags, and I noticed that the symbols that were successfully being imported corresponded to those headers in double quotes.
This function is the issue:
linking_to_flags <- function(desc) {
linking_to <- desc$get_field("LinkingTo", default = NULL)
if (is.null(linking_to)) {
return("")
}
# Split by comma
linking_to <- strsplit(linking_to, " *, *",)[[1]]
# Remove version if any
linking_to <- strsplit(linking_to, " *\\(",)
linking_to <- vapply(linking_to, function(pkg) pkg[[1]], "")
paths <- vapply(linking_to, function(pkg) system.file("include", package = pkg), "")
paths <- paths[paths != ""]
paste(paste0("-I'", paths, "'"), collapse = " ") //// This is the issue
}
To fix this, I simply replaced this line:
paste(paste0("-I'", paths, "'"), collapse = " ")
with an escaped quote:
paste(paste0("-I\"", paths, "\""), collapse = " ")
Which I have confirmed fixed the issue for my packages on Windows.