-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Trimming in variable substitution #4287
Conversation
b382021
to
9451d8d
Compare
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.
@tstenner There's a linter/vendor error in the CI. https://github.com/moby/buildkit/blob/master/.github/CONTRIBUTING.md#run-the-helper-commands |
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.
I'm recommending a different method of creating the regular expression. As mentioned in one of the comments, I find constructing regular expressions by using strings.Replace
and regexp.QuoteMeta
to be hard to reason about and verify. Since filepath matches and regular expressions are both types of regular expressions, it would be easier and more reliable to scan the string and emit the appropriate character. It's also easier to verify the behavior as correct since you don't have to think about "was this already escaped?" or "do I have to match the escaped version?" Each character has a simple and direct translation.
1d6dae0
to
40dfe83
Compare
Many thanks for the detailled feedback! It's currently a long holiday weekend so I haven't tested it one real world Dockerfiles yet, but the code should be ready and the unit tests cover quite a lot more. |
It looks much better. I'm working on a second pass of a review, but got delayed and need some time to think about some recommendations. I did want to give a high-level overview of some things that were concerning me.
|
Could we also get some some more general tests in dockerfile_test.go? We don't need to test all the possible edge case behaviour (that can be done in the lex_test.go), but it would good to at least have some sanity checks as well, just to check it works in the actual Dockerfile! @tstenner thanks so much for looking at this, nice to see someone following up on #3611 🎉 |
7c6b196
to
e5b8134
Compare
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.
Squash and get the tests working and I think this is good.
There's one additional change that I was thinking about, but I don't feel strongly enough about it at the moment to ask you to do it so I'll just mark it down here as a potential future change.
fc622dc
to
2243567
Compare
I rebased + squashed the code and the non-pushing pipelines are green in my branch. Someone with more rights than I have could go ahead and trigger the CI pipeline and hope for the best. |
I gave CI a kick to run |
There's one check failing, but I don't see what this PR could have to do with it:
|
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.
Suggest some rewording and adding examples (the list format is getting unwieldy here but I think this can work for now)
10c68d8
to
351fc8b
Compare
@dvdksn Thanks for the documentation proposal. I have merged + squashed them. |
Added a commit to make it clear what syntax is new. Reverted the change in the code example. If we want to change the code example, then it should not use the new syntax and can therefore be a separate PR, or there should be a separate code example for the new syntax. PTAL |
@tonistiigi Sounds good. I also applied @dvdksn's suggestions. Should I rebase them or will they get squashed anyway? |
@tstenner we don't squash commits during merge, so we can preserve history (it's so much easier to look through a git-blame when each commit is a single piece of work, instead of having to constantly go look at github). If you could rebase, that would be excellent ❤️ |
Review comments and edge cases - the `${}` parser handles escapes, but needs to preserve them for `#`/`%` - but `\}` needs to be de-escaped - reversing strings need to handle escapes, i.e. `a\*c` -> `c\*a` - build the regex with a scanner, not QuoteMeta+StringReplace - add more complicated cases to the tests Separate out + unit test helper functions Add trim test to dockerfile_test Signed-off-by: Tristan Stenner <[email protected]>
2f3d0bc
to
4f459a4
Compare
@jedevc I rebased and squashed everything. |
Apart from two (unrelated?) CI failures everything seems fine. Is there anything left for me to do? |
@tstenner Thanks! |
Add
#
,##
,%
and%%
to variable substitution (inspired by #3611 and the almost identical shell functionality).Can be used like this: