commit
50fb09375a
3 changed files with 39 additions and 26 deletions
45
context.go
45
context.go
|
@ -1024,6 +1024,30 @@ func (c *Context) updateDependencies() (errs []error) {
|
|||
|
||||
var check func(group *moduleGroup) []*moduleGroup
|
||||
|
||||
cycleError := func(cycle []*moduleGroup) {
|
||||
// We are the "start" of the cycle, so we're responsible
|
||||
// for generating the errors. The cycle list is in
|
||||
// reverse order because all the 'check' calls append
|
||||
// their own module to the list.
|
||||
errs = append(errs, &Error{
|
||||
Err: fmt.Errorf("encountered dependency cycle:"),
|
||||
Pos: cycle[len(cycle)-1].pos,
|
||||
})
|
||||
|
||||
// Iterate backwards through the cycle list.
|
||||
curGroup := cycle[len(cycle)-1]
|
||||
for i := len(cycle) - 1; i >= 0; i-- {
|
||||
nextGroup := cycle[i]
|
||||
errs = append(errs, &Error{
|
||||
Err: fmt.Errorf(" %q depends on %q",
|
||||
curGroup.properties.Name,
|
||||
nextGroup.properties.Name),
|
||||
Pos: curGroup.propertyPos["deps"],
|
||||
})
|
||||
curGroup = nextGroup
|
||||
}
|
||||
}
|
||||
|
||||
check = func(group *moduleGroup) []*moduleGroup {
|
||||
visited[group] = true
|
||||
checking[group] = true
|
||||
|
@ -1053,23 +1077,7 @@ func (c *Context) updateDependencies() (errs []error) {
|
|||
// for generating the errors. The cycle list is in
|
||||
// reverse order because all the 'check' calls append
|
||||
// their own module to the list.
|
||||
errs = append(errs, &Error{
|
||||
Err: fmt.Errorf("encountered dependency cycle:"),
|
||||
Pos: group.pos,
|
||||
})
|
||||
|
||||
// Iterate backwards through the cycle list.
|
||||
curGroup := group
|
||||
for i := len(cycle) - 1; i >= 0; i-- {
|
||||
nextGroup := cycle[i]
|
||||
errs = append(errs, &Error{
|
||||
Err: fmt.Errorf(" %q depends on %q",
|
||||
curGroup.properties.Name,
|
||||
nextGroup.properties.Name),
|
||||
Pos: curGroup.propertyPos["deps"],
|
||||
})
|
||||
curGroup = nextGroup
|
||||
}
|
||||
cycleError(cycle)
|
||||
|
||||
// We can continue processing this module's children to
|
||||
// find more cycles. Since all the modules that were
|
||||
|
@ -1095,8 +1103,11 @@ func (c *Context) updateDependencies() (errs []error) {
|
|||
if !visited[group] {
|
||||
cycle := check(group)
|
||||
if cycle != nil {
|
||||
if cycle[len(cycle)-1] != group {
|
||||
panic("inconceivable!")
|
||||
}
|
||||
cycleError(cycle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,10 +64,12 @@ func CopyProperties(dstValue, srcValue reflect.Value) {
|
|||
panic(fmt.Errorf("can't copy field %q: slice elements are "+
|
||||
"not strings", field.Name))
|
||||
}
|
||||
if srcFieldValue != dstFieldValue {
|
||||
newSlice := reflect.MakeSlice(field.Type, srcFieldValue.Len(),
|
||||
srcFieldValue.Len())
|
||||
reflect.Copy(newSlice, srcFieldValue)
|
||||
dstFieldValue.Set(newSlice)
|
||||
reflect.Copy(dstFieldValue, srcFieldValue)
|
||||
}
|
||||
} else {
|
||||
dstFieldValue.Set(srcFieldValue)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue