Skip to content

Commit

Permalink
fix ordering issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mackoj committed May 14, 2024
1 parent 208ab39 commit fd491a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Plugins/PackageGenerator/PackageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ struct PackageGenerator {

// Write Targets
if config.verbose { print("Generating Targets...") }
generateTargets(parsedPackages, outputFileHandle, config, packageDirectory)
var sortedParsedPackages = parsedPackages.sorted(by: \.name, order: <)
if config.pragmaMark {
sortedParsedPackages = parsedPackages.sorted(by: (\.fullPath, order: <), (\.name, order: <))
}
generateTargets(sortedParsedPackages, outputFileHandle, config, packageDirectory)
outputFileHandle.closeFile()
}

Expand Down
12 changes: 12 additions & 0 deletions Plugins/PackageGenerator/Sequence+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@ extension Sequence {
return order(a[keyPath: keyPath], b[keyPath: keyPath])
}
}
func sorted<T: Comparable>(by comparators: (keyPath: KeyPath<Element, T>, order: (T, T) -> Bool)...) -> [Element] {
return sorted { a, b in
for comparator in comparators {
if comparator.order(a[keyPath: comparator.keyPath], b[keyPath: comparator.keyPath]) {
return true
} else if comparator.order(b[keyPath: comparator.keyPath], a[keyPath: comparator.keyPath]) {
return false
}
}
return false
}
}
}

0 comments on commit fd491a0

Please sign in to comment.