some more work on dependency sorting...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-12-08 15:01:10 +03:00
parent 7883315598
commit 05450f261d

View File

@ -210,7 +210,11 @@ module.FeatureSet = {
// 2) remove the duplicate features except fot the first // 2) remove the duplicate features except fot the first
// occurance // occurance
// //
// NOTE: we do not do recursice dependency expansion. // NOTE: recursice dependency expansion is not needed here as if
// a dependency is not included in the list then it is not
// needed...
// their dependencies to be sorted, and if that does not work
// we can give up...
// NOTE: stage 2 is done later when filtering the list... // NOTE: stage 2 is done later when filtering the list...
// NOTE: if dependency errors/conflicts exist this will break at // NOTE: if dependency errors/conflicts exist this will break at
// the next step. // the next step.
@ -220,38 +224,43 @@ module.FeatureSet = {
// - dependency / priority conflict // - dependency / priority conflict
// X will have higher priority than one of its // X will have higher priority than one of its
// dependencies... // dependencies...
// var _sortDep = function(lst, missing){
// XXX do we add dependencies that are not included in the list??? var res = []
var res = [] lst.forEach(function(n){
var missing = {} var e = that[n]
lst.forEach(function(n){ // no dependencies...
var e = that[n] if(e.depends == null || e.depends.length == 0){
// no dependencies... res.push(n)
if(e.depends == null || e.depends.length == 0){
res.push(n)
} else { } else {
// skip dependencies that are not in list... // skip dependencies that are not in list...
var deps = e.depends.filter(function(d){ var deps = e.depends.filter(function(d){
if(lst.indexOf(d) < 0){ if(lst.indexOf(d) < 0){
if(missing[d] == null){ if(missing[d] == null){
missing[d] = [] missing[d] = []
}
missing[d].push(n)
return false
} }
return true
})
missing[d].push(n) // place dependencies before the depended...
res = res.concat(deps)
res.push(n)
}
return false })
} return res
return true }
})
// place dependencies before the depended... var missing = {}
res = res.concat(deps) // sort twice to cover the dependencies of dependencies...
res.push(n) // ...if this does not work we give up ;)
} lst = _sortDep(lst, missing)
lst = _sortDep(lst, missing)
})
lst = res
// sort features via priority keeping the order as close to // sort features via priority keeping the order as close to
// manual as possible... // manual as possible...