Skip to content

Commit

Permalink
bake: fix print output
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Nov 23, 2021
1 parent 5c2b9bb commit 6ea4b44
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 110 deletions.
36 changes: 30 additions & 6 deletions bake/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,53 @@ func ReadLocalFiles(names []string) ([]File, error) {
return out, nil
}

func ReadTargets(ctx context.Context, files []File, targets, overrides []string, defaults map[string]string) (map[string]*Target, []*Group, error) {
func ReadTargets(ctx context.Context, files []File, inp *Input, targets []string, overrides []string, defaults map[string]string) (map[string]*Target, map[string]*Group, map[string]build.Options, error) {
c, err := ParseFiles(files, defaults)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}

o, err := c.newOverrides(overrides)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
m := map[string]*Target{}
for _, n := range targets {
for _, n := range c.ResolveGroup(n) {
t, err := c.ResolveTarget(n, o)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
if t != nil {
m[n] = t
}
}
}
return m, c.Groups, nil

bo, err := targetsToBuildOpt(m, inp)
if err != nil {
return nil, nil, nil, err
}

g := map[string]*Group{
"default": {
Targets: targets,
},
}
if len(targets) == 0 || (len(targets) == 1 && targets[0] == "default") {
for _, group := range c.Groups {
if group.Name != "default" {
continue
}
g = map[string]*Group{
"default": {
Targets: group.Targets,
},
}
}
}

return m, g, bo, nil
}

func ParseFiles(files []File, defaults map[string]string) (_ *Config, err error) {
Expand Down Expand Up @@ -557,7 +581,7 @@ func (t *Target) AddOverrides(overrides map[string]Override) error {
return nil
}

func TargetsToBuildOpt(m map[string]*Target, inp *Input) (map[string]build.Options, error) {
func targetsToBuildOpt(m map[string]*Target, inp *Input) (map[string]build.Options, error) {
m2 := make(map[string]build.Options, len(m))
for k, v := range m {
bo, err := toBuildOpt(v, inp)
Expand Down
Loading

0 comments on commit 6ea4b44

Please sign in to comment.