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

Runfiles: support space in file paths #9351

Closed
wants to merge 9 commits into from

Conversation

laszlocsomor
Copy link
Contributor

@laszlocsomor laszlocsomor commented Sep 9, 2019

The runfiles manifest remains the same for files
without space in their runfiles-relative path.

For files with space in their runfiles-relative
path, the link path's spaces are replaced by the
ASCII 0x01 character (U+0001). This character is
very unlikely to appear in paths (so it's a safe
bet as an escape character) and it has a
single-byte UTF-8 encoding, so when looking up
paths from the runfiles manifest (which itself is
UTF-8 encoded) tools like 'sed' can easily
transform '\x01' to space and back.

Thus the first space on a line is always the
delimiter, but runfiles libraries must replace the
requested path's spaces with '\x01' upon every
manifest-based lookup.

This design ensures that manifest consumers keep
working without having to handle '\x01', as long
as all data-dependencies are space-free. Otherwise
they break, but they would break today anyway.

RELNOTES[NEW]: Runfiles: data-dependencies (runfiles) may now contain spaces.

Fixes #4327

Change-Id: I37ce3b3ef2a9e92691e987588b0e6d67969a78c5

Support space in paths of data-dependencies.

The runfiles manifest remains the same for files
without space in their runfiles-relative path.

For files with space in their runfiles-relative
path: the delimiter between runfile path and link
target is now '|' instead of space. Tools and
rules that consume runfiles manifests should test
for a '|' delimiter, and if missing, fall back to
space.

This design ensures that manifest consumers keep
working without having to handle '|', as long as
all data-dependencies are space-free. Otherwise
they break, but they would break today anyway.

Fixes bazelbuild#4327

Change-Id: I37ce3b3ef2a9e92691e987588b0e6d67969a78c5
@laszlocsomor laszlocsomor changed the title Runfiles: support space in file paths WIP: Runfiles: support space in file paths Sep 9, 2019
@irengrig irengrig added the WIP label Sep 11, 2019
Change-Id: I1072b65ee546d37dfe969c73c76980e43234a3fe
Change-Id: I611454ea7d6001b97d6f3417b7331c978070fc3f
@laszlocsomor laszlocsomor marked this pull request as ready for review September 11, 2019 11:53
@laszlocsomor laszlocsomor changed the title WIP: Runfiles: support space in file paths Runfiles: support space in file paths Sep 11, 2019
Change-Id: I636118c40f2c1ef6e2792e1d0ceb07aff9e30880
@laszlocsomor laszlocsomor removed the request for review from michajlo September 11, 2019 13:32
@laszlocsomor
Copy link
Contributor Author

Sorry, had to move the test to another directory and now it fails on Windows. Will ping the thread again when it's ready for review.

@laszlocsomor laszlocsomor changed the title Runfiles: support space in file paths WIP: Runfiles: support space in file paths Sep 12, 2019
@laszlocsomor laszlocsomor changed the title WIP: Runfiles: support space in file paths Runfiles: support space in file paths Sep 13, 2019
@laszlocsomor
Copy link
Contributor Author

Ready again :)

@jin
Copy link
Member

jin commented Oct 2, 2019

Is this waiting on a review from @michajlo?

@laszlocsomor
Copy link
Contributor Author

No, it's waiting input from me.
It's pending internal review but I didn't yet decide whether I want to import it or not.

Let's close it for now, I see PRs are getting cleaned up and I don't want to hinder that.

@laszlocsomor
Copy link
Contributor Author

(As in: there were some concerns about it by reviewers, and I haven't decided whether the PR carries its weight.)

@marmos91
Copy link

marmos91 commented Jul 2, 2020

@laszlocsomor, do you have any insight about the status of this fix? I am still facing #4327 because I need to run some Chromium-related tools on OSX, which have paths that contain spaces. Will this ever land? Is there another fix coming?

@ulfjack
Copy link
Contributor

ulfjack commented Jul 2, 2020

The problem is that the file is now a public interface, which means changing the format is a breaking change. It's going to be very difficult to roll anything like this out.

@laszlocsomor
Copy link
Contributor Author

@marmos91 : I don't have any insight. But with --experimental_inprocess_symlink_creation, Bazel allows data-deps with spaces under the runfiles directory.

The runfiles manifest is still broken (still uses space to separate link name and link target), so data-deps require using symlinks. Luckily, on macOS that is enabled by default.

Demo:

foo/BUILD:

sh_test(
    name = "x",
    srcs = ["x.sh"],
    data = glob(["*"]),
)

foo/x.sh:

#!/bin/bash
echo Hello
find $TEST_SRCDIR | sed 's|^.*__main__/||'
echo Bye

ls -la foo/:

  $ ls -la foo/
total 16
drwxrwxr-x 2 laszlo laszlo 4096 Jul  6 12:26  .
drwxrwxr-x 4 laszlo laszlo 4096 Jul  6 12:26  ..
-rw-rw-r-- 1 laszlo laszlo    0 Jul  6 12:10  a
-rw-rw-r-- 1 laszlo laszlo    0 Jul  6 12:10 'b c'
-rw-rw-r-- 1 laszlo laszlo   72 Jul  6 12:21  BUILD
-rwxrwxr-x 1 laszlo laszlo   75 Jul  6 12:26  x.sh

$ bazel test //foo:x --test_output=all --experimental_inprocess_symlink_creation:

(...)
INFO: From Testing //foo:x
==================== Test output for //foo:x:
Hello
bazel-out/k8-fastbuild/bin/foo/x.runfiles
bazel-out/k8-fastbuild/bin/foo/x.runfiles/__main__
foo
foo/x.sh
foo/BUILD
foo/b c
foo/x
foo/a
Bye
================================================================================
//foo:x 
(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Runfiles: support paths with spaces
6 participants