Skip to content

Append the workspace name to the runfiles directory name#856

Merged
aiuto merged 1 commit intobazelbuild:mainfrom
EdSchouten:eschouten/20240417-workspace-name
Apr 24, 2024
Merged

Append the workspace name to the runfiles directory name#856
aiuto merged 1 commit intobazelbuild:mainfrom
EdSchouten:eschouten/20240417-workspace-name

Conversation

@EdSchouten
Copy link
Contributor

@EdSchouten EdSchouten commented Apr 17, 2024

The runfiles directory is broken down by workspace name. This means that files belonging to the main workspace are placed at "${name}.runfiles/${ctx.workspace_name}/${short_path}". Files belonging to externals have a short_path starting with "../${external_name}".

Because we currently don't append ctx.workspace_name to the computed runfiles path, files belonging to the main workspace are placed at the top level of the runfiles directory, which is incorrect. Even worse is that files belonging to external repositories end up alongside the runfiles directory, instead of being contained within.

This makes the runfiles directory layout consistent with how Bazel creates it locally:

$ find bazel-bin/tests/an_executable.runfiles \! -type d 
bazel-bin/tests/an_executable.runfiles/MANIFEST
bazel-bin/tests/an_executable.runfiles/_repo_mapping
bazel-bin/tests/an_executable.runfiles/_main/tests/testdata/hello.txt
bazel-bin/tests/an_executable.runfiles/_main/tests/foo.cc
bazel-bin/tests/an_executable.runfiles/_main/tests/an_executable

The runfiles directory is broken down by workspace name. This means that
files belonging to the main workspace are placed at
"${name}.runfiles/${ctx.workspace_name}/${short_path}". Files belonging
to externals have a short_path starting with "../${external_name}".

Because we currently don't append ctx.workspace_name to the computed
runfiles path, files belonging to the main workspace are placed at the
top level of the runfiles directory, which is incorrect. Even worse is
that files belonging to external repositories end up alongside the
runfiles directory, instead of being contained within.
@cgrindel
Copy link
Collaborator

I will wait to merge until @aiuto has had a chance to look at this.

@aiuto
Copy link
Collaborator

aiuto commented Apr 24, 2024

This is probably going to break people, but it is the right thing to do. We're going to have to bump the major version # on the next release.

@aiuto aiuto merged commit a811e7f into bazelbuild:main Apr 24, 2024
@EdSchouten EdSchouten deleted the eschouten/20240417-workspace-name branch April 24, 2024 04:27
@korjek
Copy link

korjek commented May 16, 2024

is this supposed to be released soon?

@aiuto
Copy link
Collaborator

aiuto commented May 17, 2024

I can do a release by end of month.

@korjek
Copy link

korjek commented Jun 3, 2024

@aiuto sorry for bothering you.
Are there any updates on release that contains this change?

@aiuto
Copy link
Collaborator

aiuto commented Jun 3, 2024 via email

@yx-altera
Copy link

I ran into the issue of

/<target-name>.runfiles/_main/path/to/data_file.json

Exists, but runfile API returns a bazel module named path

/<target-name>.runfiles/<module-name>/path/to/data_file.json

The above path /<target-name>.runfiles/<module-name>/path/to/data_file.json does not exist in oci_image built container image.

The overall setup of the rules:

py_binary(
    name = "app",
    ...
)

pkg_tar(
    name = "app_tar",
    srcs = [":app"],
    ...
)

oci_image(
    name = "app_image",
    tars = [":app_tar"],
    ...
)

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 this pull request may close these issues.

5 participants