Schedule ordinary import contributions by dependency
This commit is contained in:
@@ -148,6 +148,42 @@ func (graph importInclusionGraph) scheduleCycle(closingEdge int, location Locati
|
||||
}, true
|
||||
}
|
||||
|
||||
func scheduleOrdinaryContributions(scope acquisitionScope, graph importInclusionGraph) acquisitionScope {
|
||||
positions := make(map[importNodeKey]int, len(scope.contributions))
|
||||
slots := make([]int, 0, len(scope.contributions))
|
||||
keys := make([]dependencyKey, 0, len(scope.contributions))
|
||||
for index, contribution := range scope.contributions {
|
||||
if contribution.scopeOwner != scope.owner || (contribution.role != importRoleMain && contribution.role != importRoleMapping) {
|
||||
continue
|
||||
}
|
||||
positions[contribution.identity] = len(keys)
|
||||
slots = append(slots, index)
|
||||
keys = append(keys, contribution.identity.dependencyKey())
|
||||
}
|
||||
if len(keys) < 2 {
|
||||
return scope
|
||||
}
|
||||
|
||||
edges := make([]dependencyEdge, 0, len(graph.edges))
|
||||
for _, edge := range graph.edges {
|
||||
importer, importerOK := positions[edge.importer]
|
||||
imported, importedOK := positions[edge.imported]
|
||||
if importerOK && importedOK {
|
||||
edges = append(edges, dependencyEdge{prerequisite: imported, dependent: importer})
|
||||
}
|
||||
}
|
||||
order, _ := scheduleDependencies(keys, edges)
|
||||
if len(order) != len(keys) {
|
||||
return scope
|
||||
}
|
||||
scheduled := scope
|
||||
scheduled.contributions = append([]acquiredContribution(nil), scope.contributions...)
|
||||
for position, scheduledIndex := range order {
|
||||
scheduled.contributions[slots[position]] = scope.contributions[slots[scheduledIndex]]
|
||||
}
|
||||
return scheduled
|
||||
}
|
||||
|
||||
func importKeyFor(access *filesystemAccess, canonical string, synthetic bool) importNodeKey {
|
||||
kind := "host"
|
||||
resourceKind := "file"
|
||||
|
||||
Reference in New Issue
Block a user