Skip to content

Commit

Permalink
release v1.7.0-beta-6'
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Oct 14, 2024
2 parents 16b5302 + b7af706 commit 1572b69
Show file tree
Hide file tree
Showing 72 changed files with 2,707 additions and 102 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ vendor/github.com/onsi/
vendor/github.com/pelletier/
vendor/github.com/pointlander/
vendor/github.com/spf13/
/.project
/.settings/
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ VERBOSE=-v

all: vendor grammar test release

build:
go build -o spiff

grammar:
go generate ./...

release: spiff_linux_amd64.zip spiff_darwin_amd64.zip spiff_linux_ppc64le.zip spiff_linux_arm64.zip
release: spiff_linux_amd64.zip spiff_darwin_amd64.zip spiff_linux_ppc64le.zip spiff_linux_arm64.zip spiff_windows_amd64.zip spiff_windows_386.zip

linux:
GOOS=linux GOARCH=amd64 go build -o spiff++/spiff++ .
Expand Down Expand Up @@ -37,6 +40,18 @@ spiff_linux_ppc64le.zip:
(cd spiff++; zip spiff_linux_ppc64le.zip spiff++)
rm spiff++/spiff++

spiff_windows_amd64.zip:
GOOS=windows GOARCH=amd64 go build -o spiff++/spiff++.exe .
rm -f spiff++/spiff_windows_amd64.zip
(cd spiff++; zip spiff_windows_amd64.zip spiff++.exe)
rm spiff++/spiff++.exe

spiff_windows_386.zip:
GOOS=windows GOARCH=386 go build -o spiff++/spiff++_386.exe .
rm -f spiff++/spiff_windows_386.zip
(cd spiff++; zip spiff_windows_386.zip spiff++_386.exe)
rm spiff++/spiff++_386.exe

.PHONY: vendor
vendor:
go mod vendor
Expand Down
5 changes: 5 additions & 0 deletions dynaml/catch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dynaml

import (
"fmt"

"github.com/mandelsoft/spiff/debug"
"github.com/mandelsoft/spiff/yaml"
)
Expand All @@ -15,6 +16,10 @@ type CatchExpr struct {
Lambda Expression
}

func (e CatchExpr) IncludesDirectMerge() bool {
return IncludesDirectMerge(e.A)
}

func (e CatchExpr) Evaluate(binding Binding, locally bool) (interface{}, EvaluationInfo, bool) {
resolved := true
var value interface{}
Expand Down
4 changes: 4 additions & 0 deletions dynaml/concatenation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type ConcatenationExpr struct {
B Expression
}

func (e ConcatenationExpr) IncludesDirectMerge() bool {
return IncludesDirectMerge(e.A) || IncludesDirectMerge(e.B)
}

func (e ConcatenationExpr) Evaluate(binding Binding, locally bool) (interface{}, EvaluationInfo, bool) {
resolved := true

Expand Down
4 changes: 4 additions & 0 deletions dynaml/cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type CondExpr struct {
F Expression
}

func (e CondExpr) IncludesDirectMerge() bool {
return IncludesDirectMerge(e.T) || IncludesDirectMerge(e.F)
}

func (e CondExpr) Evaluate(binding Binding, locally bool) (interface{}, EvaluationInfo, bool) {
resolved := true
info := DefaultInfo()
Expand Down
13 changes: 12 additions & 1 deletion dynaml/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ type Expression interface {
Evaluate(Binding, bool) (interface{}, EvaluationInfo, bool)
}

type MergeInfoExpression interface {
IncludesDirectMerge() bool
}

func IncludesDirectMerge(e Expression) bool {
if m, ok := e.(MergeInfoExpression); ok {
return m.IncludesDirectMerge()
}
return false
}

type StaticallyScopedValue interface {
StaticResolver() Binding
SetStaticResolver(binding Binding) StaticallyScopedValue
Expand Down Expand Up @@ -197,7 +208,7 @@ func (i *EvaluationInfo) PropagateError(value interface{}, state Status, msgfmt
if i.LocalError {
value = nil
}
return value, *i, false //!i.LocalError
return value, *i, false // !i.LocalError
}

func (i EvaluationInfo) CleanError() EvaluationInfo {
Expand Down
4 changes: 4 additions & 0 deletions dynaml/grouped.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ type GroupedExpr struct {
Expr Expression
}

func (e GroupedExpr) IncludesDirectMerge() bool {
return IncludesDirectMerge(e.Expr)
}

func (e GroupedExpr) String() string {
return fmt.Sprintf("( %s )", e.Expr)
}
Expand Down
8 changes: 8 additions & 0 deletions dynaml/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type MarkerExpr struct {
expr Expression
}

func (e MarkerExpr) IncludesDirectMerge() bool {
return IncludesDirectMerge(e.expr)
}

func NewTemplateMarker(expr Expression) MarkerExpr {
return MarkerExpr{list: []string{TEMPLATE}, expr: expr}
}
Expand Down Expand Up @@ -144,6 +148,10 @@ type MarkerExpressionExpr struct {
expr Expression
}

func (e MarkerExpressionExpr) IncludesDirectMerge() bool {
return IncludesDirectMerge(e.expr)
}

func (e MarkerExpressionExpr) String() string {
return e.contents
}
Expand Down
4 changes: 4 additions & 0 deletions dynaml/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type MergeExpr struct {
KeyName string
}

func (e MergeExpr) IncludesDirectMerge() bool {
return !e.Redirect
}

func (e MergeExpr) Evaluate(binding Binding, locally bool) (interface{}, EvaluationInfo, bool) {
var info EvaluationInfo
info.KeyName = e.KeyName
Expand Down
4 changes: 4 additions & 0 deletions dynaml/or.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type OrExpr struct {
B Expression
}

func (e OrExpr) IncludesDirectMerge() bool {
return IncludesDirectMerge(e.A) || IncludesDirectMerge(e.B)
}

func (e OrExpr) Evaluate(binding Binding, locally bool) (interface{}, EvaluationInfo, bool) {
a, infoa, ok := e.A.Evaluate(binding, false)
if ok && !infoa.Undefined {
Expand Down
60 changes: 44 additions & 16 deletions flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func flowMap(root yaml.Node, env dynaml.Binding, shouldOverride, template bool)
}
}
}
//flags |= yaml.FLAG_INJECTED
// flags |= yaml.FLAG_INJECTED
}
}
var result interface{}
Expand Down Expand Up @@ -482,7 +482,7 @@ func flowList(root yaml.Node, env dynaml.Binding, template bool) yaml.Node {
rootList := root.Value().([]yaml.Node)

debug.Debug("HANDLE LIST %v\n", env.Path())
merged, process, replaced, redirectPath, keyName, ismerged, flags, tag, stub := processMerges(root, rootList, env, template)
merged, process, replaced, redirectPath, keyName, ismerged, flags, tag, stub, nomerge := processMerges(root, rootList, env, template)

if process {
debug.Debug("process list (key: %s) %v\n", keyName, env.Path())
Expand All @@ -494,13 +494,13 @@ func flowList(root yaml.Node, env dynaml.Binding, template bool) yaml.Node {
if effkey == "" {
effkey = "name"
}
keys := map[string]bool{}
unique := keyName != NO_LIST_KEY
if unique {
resolved := true
keys := map[string]bool{}
var step string
var resolved bool
for idx, val := range merged.([]yaml.Node) {
var step string
step, resolved, unique = stepName(idx, val, keyName, env, true)
step, _, resolved, unique = stepName(idx, val, keyName, env, true)
if !resolved || !unique || keys[step] {
unique = false
break
Expand All @@ -510,8 +510,12 @@ func flowList(root yaml.Node, env dynaml.Binding, template bool) yaml.Node {
}

for idx, val := range merged.([]yaml.Node) {
step, resolved, _ := stepName(idx, val, keyName, env, unique)
step, keyed, resolved, _ := stepName(idx, val, keyName, env, unique)
debug.Debug(" step %s\n", step)
_, _ = keyed, nomerge
if !keyed && nomerge {
val = yaml.MergedNode(val)
}
if resolved {
val = flow(val, env.WithPath(step), false, false)
}
Expand Down Expand Up @@ -579,17 +583,16 @@ func FlowString(root yaml.Node, env dynaml.Binding) (yaml.Node, error) {
return yaml.SubstituteNode(expr, root), nil
}

func stepName(index int, value yaml.Node, keyName string, env dynaml.Binding, unique bool) (string, bool, bool) {
func stepName(index int, value yaml.Node, keyName string, env dynaml.Binding, unique bool) (stepName string, keyed bool, resolved bool, uni bool) {
if keyName == "" {
keyName = "name"
}
if unique {
name, ok := yaml.FindString(value, env.GetFeatures(), keyName)
if ok {
return keyName + ":" + name, true, true
return keyName + ":" + name, true, true, true
}
}

step := fmt.Sprintf("[%d]", index)
v, ok := yaml.FindR(true, value, env.GetFeatures(), keyName)
if ok && v.Value() != nil {
Expand All @@ -599,20 +602,27 @@ func stepName(index int, value yaml.Node, keyName string, env dynaml.Binding, un
v = flow(v, env.WithPath(step), false, false)
_, ok := v.Value().(dynaml.Expression)
if ok {
return step, false, false
return step, false, false, false
}
}
name, ok := v.Value().(string)
if ok && unique {
return keyName + ":" + name, true, true
return keyName + ":" + name, true, true, true
}
} else {
debug.Debug("raw %s not found", keyName)
}
return step, true, false
return step, false, true, false
}

func useMerge(n yaml.Node) bool {
if e, ok := n.Value().(dynaml.Expression); ok {
return dynaml.IncludesDirectMerge(e)
}
return false
}

func processMerges(orig yaml.Node, root []yaml.Node, env dynaml.Binding, template bool) (interface{}, bool, bool, []string, string, bool, yaml.NodeFlags, string, yaml.Node) {
func processMerges(orig yaml.Node, root []yaml.Node, env dynaml.Binding, template bool) (interface{}, bool, bool, []string, string, bool, yaml.NodeFlags, string, yaml.Node, bool) {
var flags yaml.NodeFlags
var stub yaml.Node
flags, stub = get_inherited_flags(env)
Expand All @@ -624,6 +634,24 @@ func processMerges(orig yaml.Node, root []yaml.Node, env dynaml.Binding, templat
replaced := orig.ReplaceFlag()
redirectPath := orig.RedirectPath()

// first, check for omitted stub merging for non-keyed values
nomerge := false
for _, val := range root {
if val == nil {
continue
}

inlineNode, _, ok := yaml.UnresolvedListEntryMerge(val)
if ok {
if useMerge(inlineNode) {
// do not merge list entries for list with merge expression because
// the list order would change or the potential merge candidates will
// be inserted.
nomerge = true
}
}
}

for _, val := range root {
if val == nil {
continue
Expand Down Expand Up @@ -724,7 +752,7 @@ func processMerges(orig yaml.Node, root []yaml.Node, env dynaml.Binding, templat
}

debug.Debug("--> %+v proc=%v replaced=%v redirect=%v key=%s\n", result, process, replaced, redirectPath, keyName)
return result, process, replaced, redirectPath, keyName, merged, flags, tag, stub
return result, process, replaced, redirectPath, keyName, merged, flags, tag, stub, nomerge
}

const NO_LIST_KEY = "<<<NO LIST KEY>>"
Expand Down Expand Up @@ -794,7 +822,7 @@ func newEntries(a []yaml.Node, b []yaml.Node, keyName string) []yaml.Node {
}
}

added = append(added, val)
added = append(added, yaml.MergedNode(val))
}

return added
Expand Down
Loading

0 comments on commit 1572b69

Please sign in to comment.