rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

Allow `Rlocation()` also for existing folders

Open mering opened this issue 1 year ago • 2 comments

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");

mering avatar Nov 14 '24 15:11 mering

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.

fmeum avatar Nov 14 '24 15:11 fmeum

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.

mering avatar Nov 14 '24 16:11 mering