Skip to content
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

Use original path names in compiler outputs #198

Merged
merged 11 commits into from
Jul 14, 2021
Merged

Use original path names in compiler outputs #198

merged 11 commits into from
Jul 14, 2021

Conversation

jimhester
Copy link
Member

@jimhester jimhester commented Jun 30, 2021

This is a first draft at fixing #194.

It works for me locally on macOS. We would need to do some testing on Windows and maybe think about improving the search terms to be more specific. (include the trailing ':') in the error maybe?

Fixes #194
Fixes #202

@jimhester
Copy link
Member Author

@sbearrows if you could take this as a starting point and push it further it would be great!

You can use usethis::pr_fetch(198) to pull this code down to your machine, and usethis::pr_push() to push changes back to this PR after you have commited them.

@sbearrows
Copy link
Contributor

Okay definitely!

@jimhester
Copy link
Member Author

@sbearrows this looks like it needs a news entry still, and do you think we should try to address #202 in this PR or separately?

@sbearrows
Copy link
Contributor

I was thinking I would do #202 in this one for simplicity. Thoughts?

@jimhester
Copy link
Member Author

Sure, that is fine!

stop("Compilation failed.", call. = FALSE)
}


shared_lib <- file.path(dir, "src", paste0(tools::file_path_sans_ext(basename(file)), .Platform$dynlib.ext))
r_path <- file.path(dir, "R", "cpp11.R")
brio::write_lines(r_functions, r_path)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove set_cpp_name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check!

R/source.R Outdated

#change variable name to reflect this
file <- file.path(new_path, name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets name this something else, new_file_path???

R/source.R Outdated
name <- basename(file)
package <- tools::file_path_sans_ext(generate_cpp_name(file))
}
orig_path <- normalizePath(dirname(file), winslash = "/")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
orig_path <- normalizePath(dirname(file), winslash = "/")
orig_dir <- normalizePath(dirname(file), winslash = "/")

R/source.R Outdated
error_messages <- res$stderr

# Substitute temporary file path with original file path
error_messages <- gsub(file.path(new_path, basename(file)), file.path(orig_path, basename(file)), error_messages, fixed = TRUE)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error_messages <- gsub(file.path(new_path, basename(file)), file.path(orig_path, basename(file)), error_messages, fixed = TRUE)
error_messages <- sub(file.path(new_path, basename(file)), file.path(orig_path, basename(file)), error_messages, fixed = TRUE)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filename <- basename(file)
new_path <- file.path(new_dir, filename)
orig_path <- file.path(orig_dir, filename)
error_messages <- sub(paste0(new_path, ": "), paste0(orig_path, ": "), error_messages, fixed = TRUE)


# Substitute temporary file path with original file path
error_messages <- gsub(file.path(new_path, basename(file)), file.path(orig_path, basename(file)), error_messages, fixed = TRUE)
cat(error_messages)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cat(error_messages)
cat(error_messages, file = stderr())

@@ -197,4 +210,12 @@ test_that("check_valid_attributes returns an error if one or more registers is i
}
')
)

Copy link
Member Author

@jimhester jimhester Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

Copy link
Member Author

@jimhester jimhester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussed changes feel free to merge!

Copy link
Member Author

@jimhester jimhester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussed changes feel free to merge!

@jimhester jimhester changed the title Rough implementation to use the normal path names in the error outputs Use original path names in compiler outputs Jul 14, 2021
@sbearrows sbearrows merged commit 7ffe671 into master Jul 14, 2021
@vspinu
Copy link
Contributor

vspinu commented Nov 28, 2021

The consequence of this is that errors are printed now twice with different base paths. First ones with xyz_N.cpp and then the correct original files xyz.cpp.

I understand that this is a hack to account for some editors (per #194) but there are editors out there which do understand tmp paths and redirect automatically to the correct file location. So those _N.cpp errors are quite a pain in the neck.

Regardless of the editor I think it's cleaner and less confusing not to print _N in the first place. This was done in 4ef13b7, which was factored out of the code base later in ad6a19e and commits that followed. It's a bit hard for me to judge why that was done from the code history alone. So unless it's really critical for some reason to compile with those _N suffixes, could we please have that logic back?

@vspinu
Copy link
Contributor

vspinu commented Nov 28, 2021

While playing with it I think I know why the change was reverted. It's because the corner case of souring cpp11.cpp as per this test.

I think that corner case can just be addressed by changing only cpp11.cpp input file when detected. I am adding one more commit in #251 with tests and some clarification inline docs to avoid breaking this again.

@DavisVaughan DavisVaughan deleted the tweak-paths branch August 26, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants