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

runfiles.Rlocation library returns relative paths #3376

Closed
gonzojive opened this issue Dec 4, 2022 · 4 comments · Fixed by #3377
Closed

runfiles.Rlocation library returns relative paths #3376

gonzojive opened this issue Dec 4, 2022 · 4 comments · Fixed by #3377

Comments

@gonzojive
Copy link

What version of rules_go are you using?

v0.36.0

What version of gazelle are you using?

n/a

What version of Bazel are you using?

5.3.2

Does this issue reproduce with the latest releases of all the above?

Yes.

What operating system and processor architecture are you using?

Linux amd64.

Any other potentially useful information about your toolchain?

What did you do?

Documentation says "// Rlocation returns the absolute path name of a runfile", but I am getting "bazel-out/k8-opt-exec-2B5CBBC6/bin/bazel/web/targets/plugin/plugin_/plugin.runfiles/bazel/web/targets/protoc-gen-ts-proto."

The Go binary is executing within a genrule, FWIW.

What did you expect to see?

An absolute path in the output.

What did you see instead?

An relative path in the output.

@fmeum
Copy link
Member

fmeum commented Dec 4, 2022

Thanks for the report, I submitted #3377 to update the docs. I think it's beneficial for users and devs if we allow relative paths as outputs when they are more convenient, so I just updated the docs.

@gonzojive Let me know if you think that this is not a good solution.

@gonzojive
Copy link
Author

Seems ok. https://github.com/bazelbuild/bazel/blob/master/tools/java/runfiles/Runfiles.java doesn't seem to make paths absolute either.

@gonzojive
Copy link
Author

gonzojive commented Dec 4, 2022

Actually, please see the design doc language:

TL;DR: Every language's library will implement rlocation(runfile_path), which returns the absolute path of a runfile. Later we'll implement rfind(runfile_path_pattern) that emulates running find(1) in a runfiles tree.

I typically want absolute paths from runfiles so I can be sure they will be found even when the working directory changes.

@fmeum
Copy link
Member

fmeum commented Dec 4, 2022

The unfortunate situation with runfiles libraries is that the design doc is pretty outdated and not consistent with in-the-wild implementations. The Bazel-provided runfiles libraries all return the same mix of relative and absolute paths as the rules_go one, favoring relative paths if available for improved incidental hermeticity.

If you really always want absolute paths, I would recommend adding your own wrapper around the global runfiles object or explicitly passing in the value of RUNFILES_DIR turned into an absolute path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants