Skip to content

Commit

Permalink
Search merge nodes for solve nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Oct 17, 2024
1 parent 27b46d3 commit 9aa7b31
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/buildscript/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
solveFuncName = "solve"
solveLegacyFuncName = "solve_legacy"
srcKey = "src"
mergeKey = "merge"
requirementsKey = "requirements"
platformsKey = "platforms"
)
Expand Down Expand Up @@ -237,6 +238,26 @@ func (b *BuildScript) getSolveNode(targets ...string) (*value, error) {
return node, nil
}

// If the target is a merge call, then look at right and left branches (in reverse order since the
// right branch has precedence).
if node.FuncCall.Name == mergeKey {
for i := len(node.FuncCall.Arguments) - 1; i >= 0; i-- {
arg := node.FuncCall.Arguments[i]
if arg.Assignment == nil {
continue
}
a := arg.Assignment
if a.Value.Ident != nil {
if node, err := b.getSolveNode(*a.Value.Ident); err == nil {
return node, nil
}
// Note: ignore errors because either branch may not contain a solve node.
// We'll return an error if both branches do not contain a solve node.
}
}
return nil, errNodeNotFound
}

// Otherwise, the "src" key contains a reference to the solve node.
// For example:
//
Expand Down

0 comments on commit 9aa7b31

Please sign in to comment.