Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 52
Use original path names in compiler outputs#198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
89ce869c332329a23122687c318ee243b4170ff38441143ffbe83ed7efeb77dc39a4e152a6326File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -84,36 +84,34 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu | ||
| stop("`file` must have a `.cpp` or `.cc` extension") | ||
| } | ||
| base_cpp <- (basename(file) %in% "cpp11.cpp") | ||
| name <- generate_cpp_name(file) | ||
| package <- tools::file_path_sans_ext(name) | ||
| if (base_cpp) { | ||
| name <- set_cpp_name(file) | ||
| package <- tools::file_path_sans_ext(name) | ||
| } | ||
| else { | ||
| # name and package might be different if cpp_source was called multiple times | ||
| name <- basename(file) | ||
| package <- tools::file_path_sans_ext(generate_cpp_name(file)) | ||
| } | ||
| orig_dir <- normalizePath(dirname(file), winslash = "/") | ||
| new_dir <- normalizePath(file.path(dir, "src"), winslash = "/") | ||
| # file now points to another location | ||
| file.copy(file, file.path(new_dir, name)) | ||
| # file not points to another location | ||
| file.copy(file, file.path(dir, "src", name)) | ||
| #change variable name to reflect this | ||
| file <- file.path(dir, "src", name) | ||
| new_file_path <- file.path(new_dir, name) | ||
| new_file_name <- basename(new_file_path) | ||
| orig_file_path <- file.path(orig_dir, new_file_name) | ||
| suppressWarnings( | ||
| all_decorations <- decor::cpp_decorations(dir, is_attribute = TRUE) | ||
| ) | ||
| check_valid_attributes(all_decorations) | ||
| #provide original path for error messages | ||
| check_valid_attributes(all_decorations, file = orig_file_path) | ||
| cli_suppress( | ||
| funs <- get_registered_functions(all_decorations, "cpp11::register") | ||
| ) | ||
| cpp_functions_definitions <- generate_cpp_functions(funs, package = package) | ||
| cpp_path <- file.path(dirname(file), "cpp11.cpp") | ||
| cpp_path <- file.path(dirname(new_file_path), "cpp11.cpp") | ||
| brio::write_lines(c('#include "cpp11/declarations.hpp"', "using namespace cpp11;", cpp_functions_definitions), cpp_path) | ||
| linking_to <- union(get_linking_to(all_decorations), "cpp11") | ||
| @@ -128,17 +126,20 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu | ||
| makevars_content <- generate_makevars(includes, cxx_std) | ||
| brio::write_lines(makevars_content, file.path(dir, "src", "Makevars")) | ||
| brio::write_lines(makevars_content, file.path(new_dir, "Makevars")) | ||
| source_files <- normalizePath(c(file, cpp_path), winslash = "/") | ||
| res <- callr::rcmd("SHLIB", source_files, user_profile = TRUE, show = !quiet, wd = file.path(dir, "src")) | ||
| source_files <- normalizePath(c(new_file_path, cpp_path), winslash = "/") | ||
| res <- callr::rcmd("SHLIB", source_files, user_profile = TRUE, show = !quiet, wd = new_dir) | ||
| if (res$status != 0) { | ||
| cat(res$stderr) | ||
| error_messages <- res$stderr | ||
| # Substitute temporary file path with original file path | ||
| error_messages <- gsub(tools::file_path_sans_ext(new_file_path), tools::file_path_sans_ext(orig_file_path), error_messages, fixed = TRUE) | ||
| cat(error_messages) | ||
| stop("Compilation failed.", call. = FALSE) | ||
| } | ||
| shared_lib <- file.path(dir, "src", paste0(tools::file_path_sans_ext(basename(file)), .Platform$dynlib.ext)) | ||
| shared_lib <- file.path(dir, "src", paste0(tools::file_path_sans_ext(new_file_name), .Platform$dynlib.ext)) | ||
| r_path <- file.path(dir, "R", "cpp11.R") | ||
| brio::write_lines(r_functions, r_path) | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove set_cpp_name Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check! | ||
| source(r_path, local = env) | ||
| @@ -149,14 +150,6 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu | ||
| the <- new.env(parent = emptyenv()) | ||
| the$count <- 0L | ||
| set_cpp_name <- function(name) { | ||
| ext <- tools::file_ext(name) | ||
| root <- tools::file_path_sans_ext(basename(name)) | ||
| count <- 2 | ||
| new_name <- sprintf("%s_%i", root, count) | ||
| sprintf("%s.%s", new_name, ext) | ||
| } | ||
| generate_cpp_name <- function(name, loaded_dlls = c("cpp11", names(getLoadedDLLs()))) { | ||
| ext <- tools::file_ext(name) | ||
| root <- tools::file_path_sans_ext(basename(name)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [[cpp11::register]] int foo() { return 1 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.