-
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
Allow POSIX variable substitution to remove optional colon #3611
Conversation
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
ae6aac3
to
580eb93
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.
LGTM, nice enhancement. PTAL @tonistiigi
If interested in comparing the results with the previous implementation:
Both master and this patch produce the same results into
|
This SGTM but rather than getting more compatible with posix I'm more interested in support for the specific new patterns #1772 (comment) . @thaJeztah @tianon Do you want to get this in? |
Overall SGTM to support the syntax without I was curious what we did before with PR with docker build -t foo -<<'EOF'
# syntax=docker/dockerfile:1
FROM alpine
ARG BUILD-ARG=hello world
LABEL mylabel=${BUILD-ARG}
EOF With BuildKit:
Classic builder:
When used without docker build -t foo -<<'EOF'
# syntax=docker/dockerfile:1
FROM alpine
ARG BUILD-ARG=hello world
LABEL mylabel=$BUILD-ARG
EOF docker image inspect foo --format='{{json .Config.Labels}}' | jq .
{
"mylabel": "-ARG"
} Which looks to match behavior in the shell; echo "${BUILD-ARG}"
ARG
echo "$BUILD-ARG"
-ARG |
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.
Sorry for missing this ping sooner!!! 🙇 ❤️
I looked over the test cases, and they all looked correct to me, and pretty easy to verify in shell too: 👀
$ FOO=xxx BAR= sh -c 'echo "${FOO-aaa} ${BAR-bbb} ${BAZ-ccc}"'
xxx ccc
$ FOO=xxx BAR= sh -c 'echo "${FOO:-aaa} ${BAR:-bbb} ${BAZ:-ccc}"'
xxx bbb ccc
$ FOO=xxx BAR= sh -c 'echo "--${FOO+aaa} ${BAR+bbb} ${BAZ+ccc}--"'
--aaa bbb --
$ FOO=xxx BAR= sh -c 'echo "--${FOO:+aaa} ${BAR:+bbb} ${BAZ:+ccc}--"'
--aaa --
(I don't personally use these often, but the distinction is useful sometimes, so I'm in favor of supporting them 👍)
🛠️ Partial implementation of #2389 (comment)
POSIX allows the colon in variable expansion to be optional, see https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05
This PR updates buildkit's variable expansion to include this, so all the following are now supported:
${FOO-bar}
,${FOO:-bar}
${FOO+bar}
,${FOO:+bar}
${FOO?bar}
,${FOO:?bar}
Additionally, I've updated the tests to use matrix-style tests, essentially filling out the table from "2.6.2 Parameter Expansion", to track for regressions.
As a next-step, I'm looking at implementing support for the rest of #2389, with
${parameter%[word]}
and${parameter#[word]}
as well as hopefully${parameter//[word]//[new_word]}
.