-
Notifications
You must be signed in to change notification settings - Fork 252
draft: fix: Overhaul quoting #1389
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
base: main
Are you sure you want to change the base?
Conversation
Converting to draft as I believe there is a lot more work to be done here. |
This is necessary to fix handling of directories with spaces on Windows platform.
66d595e
to
1646468
Compare
Note: there should also really be a test case which covers this. As a sanity check for future contributions, look at the generated |
Fixing the quoting in general is very hard; particularly as there are subtle differences in what is handled in different bash versions (e.g. bash 3 on macOS vs 4 on linux) and some configure scripts want quotes in different places when it comes to quoting things like CFLAGS and the like; I actually don't believe that there is a solution to the quoting that actually works robustly for all 'foreign' build systems. I think the way to make this more robust if we stay with the shell script approach is really to generate less shell and move the shell functions into shell library files which get sourced. The more portable method is to rewrite all the shell logic into a binary tool using rust or similar so that we're relying less on the environment of the enduser. I think for CMake we should be generating CMakePresets file and using a workflow to avoid needing to form complex CLI commandlines but my time for working on this is v. limited and so its not something that's likely to happen soon unless someone else picks this up! |
Considering we mandate Bash (and on Windows, MSYS2 Bash), I personally have not come across any quoting ambiguities between platform Bash implementations, at least for trivial use-cases and as long as we are not relying on particularly new features from Bash 4.x. The standard libraries of many languages already have pretty robust
Can you give an example of this? Wouldn't this just be handled at a project level if necessary?
Eh, I personally think that's over-the-top. Bazel overall leans pretty heavily on having a particular environment (as I have learned much to my chagrin). And I'd rather not have to worry about the quirks of a new tool, esp. a Rust one. This PR is really to get things "functional" on Windows for my use-case, where things are downright broken. Although it looks like I've broken some tests in CI. :) |
Yep agreed, there shouldn't be anything that stops us from being compatible; just know that in the past there have been differences between platforms that have crept in due to subtle differences, although I don't recall any specifics.
This tends to come from non-autotools configure make projects; I think openssl might be the prime example but its been a little while since I've tried to tackle this so I might be misremembering. However this is more to do with the escaping of variables that get passed to downstream tools; this is slightly different to what you are addressing in this PR though.
Yes, I think you've added escapes around variables that are then blindly concatenated with other paths and so end up with escapes in the middle of some paths. There's also likely some expected test strings that will need updating as a result of these changes in the starlark based tests. As you said before we should probably actually write out those expected test strings to files and lint them to ensure that we're generating valid shell scripts in these tests. I'm guessing the reason these issues haven't been picked up are partially because Bazel CI doesn't have any spaces in any of the paths it uses; I will raise this with the rules sig tomorrow as I think it'd be a useful addition to CI to be testing a common windows configuration of having a output_root that includes spaces. (Although I will note that I think a lot of windows users will use a path rooted at the root of the disk to reduce path lengths as its common to hit long path length issues on windows) |
"export BUILD_TMPDIR=\"$$INSTALLDIR$$.build_tmpdir" + "\"", | ||
"export EXT_BUILD_DEPS=\"$$INSTALLDIR$$.ext_build_deps" + "\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these two lines don't need the string concatenation for the final quote
I've started on #1390 which actually runs shellcheck on the generated build files, at least for the builtin tool builds which is a start; I'll try to get around to fixing the rest of the errors soon! |
@benjamin-branchware Can you test what went in on #1390 against the changes that you had here to see if there's anything that wasn't caught by shellcheck; I may have missed fixing up the windows versions of the commands. |
@jsharpe Hmm, the shellcheck integrated in my IDE still flags a lot of problems and indeed my Windows build still fails (for CMake). Here are some offending lines:
There are quite a few others - e.g. I would have guessed these would have been flagged by your shellcheck too, no? Is it missing these because it doesn't try to generate a CMake script? (seems your changes are in core util funcs) As an aside, is there not some standard Skylark path quoting function? It feels a little fragile dotting quotes here and there, especially when those strings are then passed to other functions. |
There's also other things:
|
In order to try to abate these issues, I moved my project sources and MSYS2 into directories without spaces. However, there is still a problem, as the |
There is a second issue which is blocking my testing: #1391. |
@jsharpe Any progress on this? Looks like your MR missed quite a bit. |
Yes, I expected that as the shellcheck is only running on linux / macos as shellcheck isn't built for windows in the upstream repo so the windows configuration is still not being tested. Happy to review any PRs that fix up the windows commands though! I don't have a windows dev environment setup so am unable to directly fix this except via CI on buildkite which doesn't contain spaces in the paths atm so won't pick up on issues directly. |
There are some serious issues around quoting all throughout this repo, which renders it completely ineffective for environments which may contain spaces in paths.
For example, if a user has installed MSYS2 using Scoop, it is likely that the install directory will contain their user folder, which more than likely contains a space.
This is far from a comprehensive fix. There needs to be a serious audit of all quoting. I have found instances of:
This is just the fix that we needed to get CMake builds working again on Windows.
Addresses #1388.