bake: contexts support with x-bake

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2022-08-05 15:21:21 +02:00
parent 18023d7f32
commit 7f572eb044
4 changed files with 38 additions and 11 deletions

View File

@@ -134,7 +134,7 @@ func ReadTargets(ctx context.Context, files []File, targets, overrides []string,
gt = append(gt, target)
}
}
g = []*Group{{Targets: dedupString(gt)}}
g = []*Group{{Targets: dedupSlice(gt)}}
}
for name, t := range m {
@@ -146,7 +146,7 @@ func ReadTargets(ctx context.Context, files []File, targets, overrides []string,
return m, g, nil
}
func dedupString(s []string) []string {
func dedupSlice(s []string) []string {
if len(s) == 0 {
return s
}
@@ -161,6 +161,24 @@ func dedupString(s []string) []string {
return res
}
func dedupMap(ms ...map[string]string) map[string]string {
if len(ms) == 0 {
return nil
}
res := map[string]string{}
for _, m := range ms {
if len(m) == 0 {
continue
}
for k, v := range m {
if _, ok := res[k]; !ok {
res[k] = v
}
}
}
return res
}
func ParseFiles(files []File, defaults map[string]string) (_ *Config, err error) {
defer func() {
err = formatHCLError(err, files)
@@ -418,7 +436,7 @@ func (c Config) newOverrides(v []string) (map[string]map[string]Override, error)
}
func (c Config) ResolveGroup(name string) []string {
return dedupString(c.group(name, map[string][]string{}))
return dedupSlice(c.group(name, map[string][]string{}))
}
func (c Config) group(name string, visited map[string][]string) []string {