orderedDeps gets a list of all dependencies ordered so that items are always after any of their dependencies.
(mod string)
| 171 | |
| 172 | // orderedDeps gets a list of all dependencies ordered so that items are always after any of their dependencies. |
| 173 | func (m *Manager) orderedDeps(mod string) []string { |
| 174 | deps := m.listDeps(mod) |
| 175 | |
| 176 | // get a unique list of moduleNames, with a flag for whether they have been added to our result |
| 177 | uniq := map[string]bool{} |
| 178 | for _, dep := range deps { |
| 179 | uniq[dep] = false |
| 180 | } |
| 181 | |
| 182 | result := make([]string, 0, len(uniq)) |
| 183 | |
| 184 | // keep looping through all modules until they have all been added to the result. |
| 185 | |
| 186 | for len(result) < len(uniq) { |
| 187 | OUTER: |
| 188 | for name, added := range uniq { |
| 189 | if added { |
| 190 | continue |
| 191 | } |
| 192 | for _, dep := range m.modules[name].deps { |
| 193 | // stop processing this module if one of its dependencies has |
| 194 | // not been added to the result yet. |
| 195 | if !uniq[dep] { |
| 196 | continue OUTER |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // if all of the module's dependencies have been added to the result slice, |
| 201 | // then we can safely add this module to the result slice as well. |
| 202 | uniq[name] = true |
| 203 | result = append(result, name) |
| 204 | } |
| 205 | } |
| 206 | return result |
| 207 | } |
| 208 | |
| 209 | // find modules in the supplied list, that depend on mod |
| 210 | func (m *Manager) findInverseDependencies(mod string, mods []string) []string { |