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 any characters in filenames / labels #374

Open
damienmg opened this issue Aug 13, 2015 · 92 comments
Open

Allow any characters in filenames / labels #374

damienmg opened this issue Aug 13, 2015 · 92 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob type: feature request
Milestone

Comments

@damienmg
Copy link
Contributor

Ultimately any character can be part of a filename. We should probably allow that.

Some mangling to generate the corresponding label should probably be done.

Original report on the mailing-list:
https://groups.google.com/d/msgid/bazel-discuss/CAN0GiO3__5jXo5rZqroSj0mFxpqCzUZZVkY%3DSNsJK1%2BZ1BdJLg%40mail.gmail.com

@abergmeier
Copy link
Contributor

  1. So are we talking Unicode?
  2. Where does any character stop?
  3. how do you treat characters that are not allowed on certain platforms?
  4. When using mangling, how do you handle collisions?

@kayasoze
Copy link

In POSIX, filenames are "bags of bytes"--there is no encoding; however, NUL and / are not allowed. Windows has a few more restrictions. Perhaps the BUILD file should be parsed in the encoding of the system locale, usually UTF-8, and filenames run though a ValidForCurrentPlatform() function which checks for disallowed characters. However, opting for strict platform neutrality in this way means that Bazel would have to represent filenames as a bag of bytes and not a Unicode string, as there is no guarantee that the filename will roundtrip through Unicode correctly. The problem can probably be simplified by restricting filenames to be UTF-8 or UTF-16, which should cover most people's needs even though that's not strict POSIX.

@ulfjack
Copy link
Contributor

ulfjack commented Oct 22, 2015

Well, I think we can probably require valid UTF-8 file names and strongly recommend that people use UTF-8 for their file system. For labels / BUILD files, we probably need an escaping scheme, at least for the control characters. If there's a file that isn't valid UTF-8, we give an error message?

@btelles
Copy link

btelles commented Nov 18, 2015

Our company codes mainly in C++, but our frontend uses a lot of JS and nodejs modules which have all sorts of characters in the filenames--for example, -, #, @, (, and ).

Right now this is a major blocker for getting all our codebase under one build system since we can't reference files with semi-special characters. I don't think Bazel should decide what characters are acceptable in file names, as that reduces file names to those that fit both (1) supported languages and (2) supported platforms. This seems unnecessarily restrictive, and is becoming a major pain point for us.

@ulfjack
Copy link
Contributor

ulfjack commented Nov 19, 2015

Agreed. Unfortunately, it's a bit tricky to fix, as a lot of code assumes that the mapping from labels to file names (and vice versa) is trivial, and doesn't require escaping. Any suggestions on an escaping scheme?

@damienmg
Copy link
Contributor Author

URL based?

@abergmeier
Copy link
Contributor

You mean an own URI scheme? Sounds good.

@damienmg
Copy link
Contributor Author

I mean replacing special characters by %XX where XX is the UTF-8 code in hexa.

@ulfjack ulfjack assigned philwo and unassigned ulfjack Mar 2, 2016
@ulfjack
Copy link
Contributor

ulfjack commented Mar 2, 2016

Sorry, I won't be able to work on this. @philwo had an interest, maybe he can make some progress here. :-/

@kayasoze
Copy link

This blocks our Bazel deployment as well.

@RonnieAtOracle
Copy link

This is blocking us. We have a templating system where we need to build our template files. The filenames themselves contains template variables (e.g. ${ServiceName}.java ). Both $, {, and } are not supported by Bazel in file names.

@philwo
Copy link
Member

philwo commented May 25, 2016

I totally agree that this is important, should be done, I want this myself, however I don't have the time to work on it in the coming months, thus I have to unassign it.

@DemiMarie
Copy link

Here is my proposal:

  • Metacharacters (:, %, =, any others) must be %-encoded
  • All other characters are allowed. This includes Unicode characters.
  • Non-UTF8 names are not allowed, even if escaped. This is because there is no good way to handle them cross-platform, nor to display them to the user.

@mihnita
Copy link

mihnita commented Oct 6, 2016

Plain ASCII (and even that partial) makes this feels like we are in the early 90s.

There are reasonable ways to handle that.
For POSIX using the default locale would be good enough.

If my project is C/C++, and it is cross-platform, and I have problems handling Unicode, then I will not use Unicode in file names. And the fact that bazel "explodes" is not such a problem.
But if I use something like Java, then "it just works", and bazel would work too.

Even better would be to to allow for a character-set option in the project file.
This is what maven does. And what Java does with -Dfile.encoding=UTF-8
So if it is there, use it. If not, then take the system charset.

I did not move one project to bazel because test units check that Unicode file names work.
So the files are there, make it through git, work with maven and ant and gradle and java.
But bazel fails because there is an "@" in the file name... Which is supported on all OSes.

@phst
Copy link
Contributor

phst commented Jan 15, 2025

Thanks!
What about the runfiles manifest on Windows? It can't be UTF-16 (that would be the appropriate OS encoding, but not ASCII-compatible), so is it UTF-8 even on Windows?

@phst
Copy link
Contributor

phst commented Jan 15, 2025

Starlark and other Bazel files (e.g. .bazelrc, manifests, ...) are assumed (but not enforced) to be encoded in UTF-8

Stardoc assumes Latin-1 for docstrings, though. Encoding a Starlark file in UTF-8 will result in double-encoding, cf. https://github.com/phst/rules_elisp/blob/master/docs/generate.py#L236-L239

@phst
Copy link
Contributor

phst commented Jan 15, 2025

If Starlark files are now asssumed to be UTF-8, then I guess for Stardoc https://github.com/bazelbuild/bazel/blob/8.0.0/src/main/java/com/google/devtools/build/lib/starlarkdocextract/RuleInfoExtractor.java#L65 and similar occurrences (basically wherever a string proto field in the Stardoc proto is set) need to be fixed

@fmeum
Copy link
Collaborator

fmeum commented Jan 16, 2025

Thanks! What about the runfiles manifest on Windows? It can't be UTF-16 (that would be the appropriate OS encoding, but not ASCII-compatible), so is it UTF-8 even on Windows?

Yes, all output files produced by Bazel should use UTF-8 and \n line endings on all platforms, including Windows.

If Starlark files are now asssumed to be UTF-8, then I guess for Stardoc https://github.com/bazelbuild/bazel/blob/8.0.0/src/main/java/com/google/devtools/build/lib/starlarkdocextract/RuleInfoExtractor.java#L65 and similar occurrences (basically wherever a string proto field in the Stardoc proto is set) need to be fixed

Thanks for pointing that out, I sent #24935 to fix this.

phst added a commit to phst/rules_python that referenced this issue Jan 20, 2025
See bazelbuild/bazel#374 (comment):

> all output files produced by Bazel should use UTF-8 and \n line endings on
> all platforms, including Windows.
phst added a commit to phst/rules_python that referenced this issue Jan 20, 2025
See bazelbuild/bazel#374 (comment):

> all output files produced by Bazel should use UTF-8 and \n line endings on
> all platforms, including Windows.
phst added a commit to phst/rules_python that referenced this issue Jan 20, 2025
See bazelbuild/bazel#374 (comment):

> all output files produced by Bazel should use UTF-8 and \n line endings on
> all platforms, including Windows.
@phst
Copy link
Contributor

phst commented Jan 22, 2025

I wasn't aware of that docs statement, I will update it.

Here's another doc that I guess is outdated now: https://bazel.build/concepts/labels

  • Repository names: No documentation, but I'd assume that even with this change repository names (both canonical and apparent) are ASCII-only, with some more restrictions (no newlines, spaces, slashes, ...)
  • Package names: Since package names correspond to directory names, these can now also contain non-ASCII characters?
  • Target names: Definitely can contain non-ASCII characters now.

@phst
Copy link
Contributor

phst commented Jan 22, 2025

Yes, all output files produced by Bazel should use UTF-8 and \n line endings on all platforms, including Windows.

OK, then the runfiles libraries also need to be adapted.

  • Go: Probably no change needed, Go uses WTF-8 for filenames on Windows
  • Python: Probably only need to make sure that files are opened with the correct encoding (fix: Fix encoding of runfiles manifest and repository mapping files. rules_python#2568)
  • C++: A lot more changes required. The use of narrow strings throughout makes manifest files and directories with non-ASCII characters nonportable/impossible. We need at least overloads for Create and Rlocation with std::wstring on Windows.
  • Others: ???

phst added a commit to phst/rules_python that referenced this issue Jan 22, 2025
See bazelbuild/bazel#374 (comment):

> all output files produced by Bazel should use UTF-8 and \n line endings on
> all platforms, including Windows.
@fmeum
Copy link
Collaborator

fmeum commented Jan 22, 2025

Thanks for sending the fix for Python!

C++: A lot more changes required. The use of narrow strings throughout makes manifest files and directories with non-ASCII characters nonportable/impossible. We need at least overloads for Create and Rlocation with std::wstring on Windows.

Microsoft now recommends using the -A variety of functions with the UTF-8 code page (forced via an app manifest) instead of the wide string functions for new software. Existing software probably already has its own conversion functions to and from UTF-8, so I would personally lean against complicating the API for everyone by adding more overloads.

github-merge-queue bot pushed a commit to bazelbuild/rules_python that referenced this issue Jan 22, 2025
…2568)

See
bazelbuild/bazel#374 (comment):

> all output files produced by Bazel should use UTF-8 and \n line
endings on
> all platforms, including Windows.

Previously this would use the legacy ANSI codepage on Windows.
copybara-service bot pushed a commit that referenced this issue Jan 22, 2025
Work towards #374

Closes #24935.

PiperOrigin-RevId: 718549143
Change-Id: Ibe6c685a2f8dd75430cae7f770d392de35bdeb68
phst added a commit to phst/bazel_features that referenced this issue Jan 26, 2025
bazelbuild/bazel#24935 changes the observable behavior
of starlark_doc_extract, and consumers need to adapt.

Work towards bazelbuild/bazel#374
Work towards phst/rules_elisp#818
tjgq pushed a commit to tjgq/bazel that referenced this issue Jan 27, 2025
Work towards bazelbuild#374

Closes bazelbuild#24935.

PiperOrigin-RevId: 718549143
Change-Id: Ibe6c685a2f8dd75430cae7f770d392de35bdeb68
github-merge-queue bot pushed a commit that referenced this issue Jan 27, 2025
…#25097)

Work towards #374

Closes #24935.

PiperOrigin-RevId: 718549143
Change-Id: Ibe6c685a2f8dd75430cae7f770d392de35bdeb68

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
phst added a commit to phst/bazel_features that referenced this issue Jan 28, 2025
bazelbuild/bazel#24935 changes the observable behavior
of starlark_doc_extract, and consumers need to adapt.

Work towards bazelbuild/bazel#374
Work towards phst/rules_elisp#818
fmeum pushed a commit to bazel-contrib/bazel_features that referenced this issue Jan 28, 2025
bazelbuild/bazel#24935 changes the observable
behavior of starlark_doc_extract, and consumers need to adapt.

Work towards bazelbuild/bazel#374
Work towards phst/rules_elisp#818
fmeum added a commit to fmeum/bazel that referenced this issue Jan 29, 2025
Work towards bazelbuild#374

Closes bazelbuild#24935.

PiperOrigin-RevId: 718549143
Change-Id: Ibe6c685a2f8dd75430cae7f770d392de35bdeb68
copybara-service bot pushed a commit that referenced this issue Jan 30, 2025
If enabled (or set to `error`), fail if Starlark files are not UTF-8 encoded. If set to `warning` (the default), emits a warning instead.

Bazel already assumes that Starlark files are UTF-8 encoded for e.g. filenames in actions executed remotely. This flag doesn't affect this, it only makes encoding failures more visible.

Work towards #374

Closes #24944.

PiperOrigin-RevId: 721513249
Change-Id: I1d3363168c6cd5d37abf96e0401e34866b6679d7
fmeum added a commit to fmeum/bazel that referenced this issue Jan 31, 2025
If enabled (or set to `error`), fail if Starlark files are not UTF-8 encoded. If set to `warning` (the default), emits a warning instead.

Bazel already assumes that Starlark files are UTF-8 encoded for e.g. filenames in actions executed remotely. This flag doesn't affect this, it only makes encoding failures more visible.

Work towards bazelbuild#374

Closes bazelbuild#24944.

PiperOrigin-RevId: 721513249
Change-Id: I1d3363168c6cd5d37abf96e0401e34866b6679d7

(cherry picked from commit e7934ce)
fmeum added a commit to fmeum/bazel that referenced this issue Jan 31, 2025
If enabled (or set to `error`), fail if Starlark files are not UTF-8 encoded. If set to `warning` (the default), emits a warning instead.

Bazel already assumes that Starlark files are UTF-8 encoded for e.g. filenames in actions executed remotely. This flag doesn't affect this, it only makes encoding failures more visible.

Work towards bazelbuild#374

Closes bazelbuild#24944.

PiperOrigin-RevId: 721513249
Change-Id: I1d3363168c6cd5d37abf96e0401e34866b6679d7

(cherry picked from commit e7934ce)
github-merge-queue bot pushed a commit that referenced this issue Jan 31, 2025
If enabled (or set to `error`), fail if Starlark files are not UTF-8
encoded. If set to `warning` (the default), emits a warning instead.

Bazel already assumes that Starlark files are UTF-8 encoded for e.g.
filenames in actions executed remotely. This flag doesn't affect this,
it only makes encoding failures more visible.

Work towards #374

Closes #24944.

PiperOrigin-RevId: 721513249
Change-Id: I1d3363168c6cd5d37abf96e0401e34866b6679d7

(cherry picked from commit e7934ce)

Fixes #25148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob type: feature request
Projects
None yet
Development

No branches or pull requests