-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
CROSSTOOLS wrapped_clang: handle spaces in paths #5147
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed in! |
CLAs look good, thanks! |
tools/osx/crosstool/wrapped_clang.cc
Outdated
// Splits txt using whitespace delimiter, pushing each substring into strs. | ||
// Splits txt on the first whitespace delimiter, pushing both substring into strs. | ||
// This is because the wrapped_clang binary is called with arguments like: | ||
// wrapped_clang '-isysroot a/path/that might have/spaces' and we need to |
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.
what if it's passed as -isysroota/path/that might have/spaces? or with the = syntax?
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.
Good point. I'm assuming this is called by Bazel right? I grepped for isysroot
and it seems Bazel does use a single space:
tools/osx/crosstool/CROSSTOOL.tpl: flag: "-isysroot %{sdk_dir}"
for example. Is it the intent to have it be general purpose and support all the different syntaxes? Note that this might be really hard, for instance in the -isysroota/path
case, how do you know where the flag ends and the path starts without knowing all of clang's flags?
Also note the previous version would fail in similar or worse ways with either of these other syntaxes.
Thinking a bit more about this change I'm wondering if it wouldn't be better to change Bazel to not combine multiple arguments into one. Is there a reason it does: |
As an update, I have found a case where this change breaks. When trying to build a sample app, I found Bazel calling the
I think what I said in my previous comment is the right way forward. |
+1 |
Okay, I played a little with this but I'm stuck. The way the flags end up with spaces in them is because in
I've verified that if I remove that space and make the flag two entries, like so:
The problem is solved. However that file says at the beginning:
Which makes me think that changing it directly is a bad idea. Also, there are other instances of spaces in the flags, but there is some kind of iteration going on, e.g.
I am not familiar with the language specification for this file so I don't know how that could be turned into multiple |
Those last commits kind of work for me but I'm not sure whether that |
tools/osx/crosstool/CROSSTOOL.tpl changes require a change in an internal Google script, correct. Is the patch in this CL the resulting file we need to get? |
I have a change to update the script that I'm about to send out. It should get referenced here once it's merged. |
Yeah, the changes to CROSSTOOL.tpl are what I'm testing with. Modulo my previous comments about my lack of knowledge of tpl format and whether it expands flag_groups as I think it expands them, then yeah. Note that I also removed the parsing from the clang wrapper. Thank you for taking a look at this. |
One step towards #5147. PiperOrigin-RevId: 199281558
My change was merged. Please rebase and let me know whether you can get it to work now. |
@ulfjack I tested this with my workspace and the test case that I had added before. Note that I removed splitting on spaces that |
Generally looks good. I triggered the CI. |
I should probably fix the comments before you merge and reference the commit you did that fixes the caller side... |
Before commit 53700e2 Bazel was quoting some calls to wrapped_clang like so: '-isysroot /some/path maybe with spaces' and wrapped_clang was parsing to split on spaces (assuming the paths themselves didn't have spaces). After 53700e2 the arguments to wrapped_clang don't need to be parsed so this commit removes the parsing. Also add a test for spaces in pathnames.
Ok, pushed a NFC with better comments... sorry I didn't do the comments right the first time. I thought the CI was triggered automatically. |
@ob, you can't trigger CI yourself. Security told us we're required to do a code review first. |
@ulfjack that makes sense... in a way triggering a CI on unreviewed code changes can be seen as a remote execution attack ;-) Could you please trigger a CI run again? |
Triggered. |
Hmm... the test failure seems unrelated to my changes... FWIW, |
Yeah, the test is flaky - I just disabled it earlier today. I'm going to merge this PR now. |
When bazel calls wrapped_clang, it single-quotes all arguments. However it passes flags with arguments quoted as a whole. That is, wrapped_clang will be called with arguments like these: wrapped_clang '-isysroot /a/path/with spaces' '/a/file with spaces.m' Before this commit, wrapped_clang was blindly splitting on space and calling clang with invalid arguments. Now it only splits on the _first_ space, and only if the argument starts with '-'. Closes bazelbuild#5147. PiperOrigin-RevId: 200259496
When bazel calls wrapped_clang, it single-quotes all arguments. However it passes flags with arguments quoted as a whole. That is, wrapped_clang will be called with arguments like these: wrapped_clang '-isysroot /a/path/with spaces' '/a/file with spaces.m' Before this commit, wrapped_clang was blindly splitting on space and calling clang with invalid arguments. Now it only splits on the _first_ space, and only if the argument starts with '-'. Closes bazelbuild#5147. PiperOrigin-RevId: 200259496
When bazel calls wrapped_clang, it single-quotes all arguments. However
it passes flags with arguments quoted as a whole. That is, wrapped_clang
will be called with arguments like these:
wrapped_clang '-isysroot /a/path/with spaces' '/a/file with spaces.m'
Before this commit, wrapped_clang was blindly splitting on space and
calling clang with invalid arguments. Now it only splits on the first
space, and only if the argument starts with '-'.