bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Files should be able to get their directories as File objects

Open matts1 opened this issue 1 year ago • 0 comments

Description of the feature request:

A bazel File object currently has the attribute dirname. This gets the path of the directory containing the file.

However, sometimes rather than a path, you want an actual file object. I believe it would be useful to have File objects have an attribute parent, of type Optional[File].

Which category does this issue belong to?

Rules API

What underlying problem are you trying to solve with this feature?

It makes starlark rules much more convenient to write, since you can perform any operation that works on files on the parent attribute.

What happens, for example, if you want to write f.parent.short_path? At the moment, f.dirname returns the full path, so you would be forced to write f.short_path.rsplit("/", 1)[0].

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

7.1.1

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 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?

No response

matts1 avatar May 06 '24 23:05 matts1