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

Error when trying to access workspace_root field from a repository_ctx object. #16042

Closed
digit-google opened this issue Aug 3, 2022 · 3 comments

Comments

@digit-google
Copy link

Description of the bug:

The documentation for repository_ctx states that it has a workspace_root field that returns a path to the top-level workspace directory.

When trying to use this inside an actual repository rule implementation, Bazel complains with an error that says:

Error: 'repository_ctx' value has no field or method 'workspace_root'

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I have uploaded a minimal reproduction case here:
https://github.com/digit-google/bazel-experiments/tree/main/repository-rules/error-using-workspace_root

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

Bazel 5.3.0rc1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

I initially found the issue when using repository rule from a BzlMod module extension function, but could also reproduce it with simpler WORKSPACE directives.

For my project, I am currently working around the issue by using a hard-coded a relative path, which only works because we use a custom output_base that is in a parallel directory from the workspace one, but this is fragile, and not a general solution.

@fmeum
Copy link
Collaborator

fmeum commented Aug 3, 2022

It's available on HEAD, but the cherry-pick into 5.2.0 failed here and I don't think anybody has tried cherry-picking it into 5.3.0 again. You will probably have to wait for 6.0.0.

@digit-google
Copy link
Author

Thanks, good to know it will be fixed eventually. I'll stick with my work-around until then :-)

@sgowroji
Copy link
Member

sgowroji commented Aug 4, 2022

@fmeum Thank you for sharing the resolution. @digit-google We are closing this issue now. Please feel free to reopen if you have any further queries.

@sgowroji sgowroji closed this as completed Aug 4, 2022
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

No branches or pull requests

3 participants