mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-30 23:28:04 +08:00
bake: keep escaped interpolation in print output
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
36
bake/bake.go
36
bake/bake.go
@@ -3,6 +3,7 @@ package bake
|
||||
import (
|
||||
"context"
|
||||
"encoding"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"maps"
|
||||
"os"
|
||||
@@ -733,6 +734,41 @@ type Target struct {
|
||||
linked bool
|
||||
}
|
||||
|
||||
func (t *Target) MarshalJSON() ([]byte, error) {
|
||||
tgt := *t
|
||||
esc := func(s string) string {
|
||||
return strings.ReplaceAll(strings.ReplaceAll(s, "${", "$${"), "%{", "%%{")
|
||||
}
|
||||
|
||||
tgt.Annotations = slices.Clone(t.Annotations)
|
||||
for i, v := range tgt.Annotations {
|
||||
tgt.Annotations[i] = esc(v)
|
||||
}
|
||||
|
||||
if tgt.DockerfileInline != nil {
|
||||
escaped := esc(*tgt.DockerfileInline)
|
||||
tgt.DockerfileInline = &escaped
|
||||
}
|
||||
|
||||
tgt.Labels = maps.Clone(t.Labels)
|
||||
for k, v := range t.Labels {
|
||||
if v != nil {
|
||||
escaped := esc(*v)
|
||||
tgt.Labels[k] = &escaped
|
||||
}
|
||||
}
|
||||
|
||||
tgt.Args = maps.Clone(t.Args)
|
||||
for k, v := range t.Args {
|
||||
if v != nil {
|
||||
escaped := esc(*v)
|
||||
tgt.Args[k] = &escaped
|
||||
}
|
||||
}
|
||||
|
||||
return json.Marshal(tgt)
|
||||
}
|
||||
|
||||
var (
|
||||
_ hclparser.WithEvalContexts = &Target{}
|
||||
_ hclparser.WithGetName = &Target{}
|
||||
|
Reference in New Issue
Block a user