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

Allow Rlocation() also for existing folders #4172

Open
mering opened this issue Nov 14, 2024 · 2 comments
Open

Allow Rlocation() also for existing folders #4172

mering opened this issue Nov 14, 2024 · 2 comments

Comments

@mering
Copy link
Contributor

mering commented Nov 14, 2024

What version of rules_go are you using?

0.50.1

What version of gazelle are you using?

0.39.1

What version of Bazel are you using?

7.0.2

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

What operating system and processor architecture are you using?

Linux

Any other potentially useful information about your toolchain?

What did you do?

r, err := runfiles.New()
if err != nil {
	return "", err
}
repoBasePath, err := r.Rlocation("my_repo")
repoBasePath, err = r.Rlocation("my_repo/my_pkg")

What did you expect to see?

The previous snippet should succeed without error and return the runfiles path for my_repo or my_repo/my_pkg.

What did you see instead?

The call to Rlocation() returnes an error for runfiles paths like directories which are not files. This works in the runfiles implementation of other programming languages like C++:

repoBasePath = Runfiles::Create("")->Rlocation("my_repo");
repoBasePath = Runfiles::Create("")->Rlocation("my_repo/my_pkg");
@fmeum
Copy link
Member

fmeum commented Nov 14, 2024

Rlocation is not a good place for this as it's not necessarily true that all entries looked up via repo/X are actually in one physical directory on disk. Whether this works depends on the backing runfiles implementation (directory vs. manifest).

Instead, have you tried using https://pkg.go.dev/github.com/bazelbuild/rules_go/go/runfiles#New to obtain a *Runfiles that implements fs.FS? With that, you can get and walk directories across all backing implementations.

@mering
Copy link
Contributor Author

mering commented Nov 14, 2024

Rlocation is not a good place for this as it's not necessarily true that all entries looked up via repo/X are actually in one physical directory on disk. Whether this works depends on the backing runfiles implementation (directory vs. manifest).

We only use Linux, so it should always be directory IIUC.

Instead, have you tried using https://pkg.go.dev/github.com/bazelbuild/rules_go/go/runfiles#New to obtain a *Runfiles that implements fs.FS? With that, you can get and walk directories across all backing implementations.

This is what we are doing as a workaround but this doesn't exist in other languages likek C++ and Python. We would prefer to have our approaches aligned to make it easier for our developers switching between different languages.

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

2 participants