-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
89ce869
Rough implementation to use the normal path names in the error outputs
jimhester c332329
tests for error mesg with file path
a231226
Merge branch 'master' into tweak-paths
sbearrows 87c318e
support windows
e243b41
Merged upstream/tweak-paths into tweak-paths
70ff384
Fix compilation on windows
jimhester 41143ff
revert to old names but keep new error messages
be83ed7
Merged upstream/tweak-paths into tweak-paths
efeb77d
Merge branch 'master' into tweak-paths
jimhester c39a4e1
incorporate Jims edits
52a6326
tweak file path variable names
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
Member
Author
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)) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [[cpp11::register]] int foo() { return 1 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.