This is an archive of the discontinued LLVM Phabricator instance.

[Support] Allow configuring the preferred type of slashes on Windows
ClosedPublic

Authored by mstorsjo on Oct 29 2021, 2:08 AM.

Details

Summary

Later we might want to make it settable at runtime - but even then,
we want to be able to set what the built-in default should be.

Default to preferring forward slashes when built for MinGW.

Not all tests pass yet, if configuring to prefer forward slashes though.

Diff Detail

Event Timeline

mstorsjo created this revision.Oct 29 2021, 2:08 AM
mstorsjo requested review of this revision.Oct 29 2021, 2:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2021, 2:08 AM

This is the last step needed to actually take the forward slash form of paths into use. There's still a number of test failures if built in that mode (I'll send more patches to try to remedy that afterwards).

@rnk 's desire was to be able to change it at runtime - I'm not currently planning on taking this feature that far, but this is at least one step along the way to that goal (even with runtime options, one can want to configure the default). If changing the preference at runtime, one has to redo parts of what D111880 does (running make_preferred() on a number of paths) after setting the new preference (e.g. when Argv[0] has been set early, based on the built-in preferred format, one would have to update that and all other paths derived from it).

aaron.ballman added inline comments.Nov 4 2021, 2:11 PM
llvm/CMakeLists.txt
363

Should this also happen for cygwin?

mstorsjo added inline comments.Nov 4 2021, 2:17 PM
llvm/CMakeLists.txt
363

I think cygwin shouldn't matter here - cygwin mostly presents itself as a unix; it doesn't define _WIN32 when compiling etc, so on cygwin you'd get the posix path style.

aaron.ballman added inline comments.Nov 4 2021, 2:34 PM
llvm/CMakeLists.txt
363

Ooohh! So because _WIN32 isn't defined, we will prefer forward slashes already? (What confused me is this looks like it prefers backslash on *all* Windows targets except mingw and it seems like we want the same for cygwin.)

mstorsjo added inline comments.Nov 4 2021, 2:46 PM
llvm/CMakeLists.txt
363

Yes - but not Windows-style paths with forward slashes - it gets plain posix paths only.

As cygwin doesn't define _WIN32 and thus doesn't present itself as Windows at all, LLVM built in cygwin thinks it's executing on a regular unix, so path::Style::native does evaluate to path::Style::posix, and it's executing code from llvm/lib/Support/Unix instead of llvm/lib/Support/Windows, etc.

So to avoid implying that it has an effect, I wouldn't add it to the if condition here, but I guess it would warrant a comment. Maybe something along these lines:

if (MINGW)
  # Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix as native path style,
  # regardless of what this is set to.
  set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT ON)
endif()
aaron.ballman accepted this revision.Nov 4 2021, 2:48 PM

LGTM modulo the comment request.

llvm/CMakeLists.txt
363

Thank you for the explanation! I think that comment would help others reading the CMake without that context in mind.

This revision is now accepted and ready to land.Nov 4 2021, 2:48 PM
mstorsjo updated this revision to Diff 384875.Nov 4 2021, 2:56 PM

Thanks for the review! Amended the patch with the comment as discussed; will land the series of these three patches tomorrow.