Improve list-targets by sorting using topological order (#2383)
Co-authored-by: Alfredo Delli Bovi <alfredo.dellibovi@team.bundle.com>
This commit is contained in:
parent
d1cd62f0a7
commit
a8ab5c6bcc
|
@ -17,6 +17,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
|
|||
|
||||
### Changed
|
||||
|
||||
- Improve `tuist migration list-targets` by sorting using topological order [#2383](https://github.com/tuist/tuist/pull/2383) by [@adellibovi](https://github.com/adellibovi).
|
||||
- Use project generated for automation and always leverage `XXX-Scheme` [#2057](https://github.com/tuist/tuist/pull/2057) by [@fortmarek](https://github.com/fortmarek)
|
||||
- Improve the cache warm command significantly (around 20-45 seconds per framework) by using `XcodeProjectPathHasher` instead of `CacheBuildPhaseProjectMapper` [#2356](https://github.com/tuist/tuist/pull/2318) by [@natanrolnik](https://github.com/natanrolnik).
|
||||
- Improve performance of project generation by removing unneeded Glob directory cache [#2318](https://github.com/tuist/tuist/pull/2318) by [@adellibovi](https://github.com/adellibovi).
|
||||
|
|
|
@ -42,7 +42,8 @@ public protocol TargetsExtracting {
|
|||
|
||||
public struct TargetDependencyCount: Encodable {
|
||||
public let targetName: String
|
||||
public let dependenciesCount: Int
|
||||
public let targetDependenciesNames: [String]
|
||||
public let linkedFrameworksCount: Int
|
||||
}
|
||||
|
||||
public final class TargetsExtractor: TargetsExtracting {
|
||||
|
@ -63,22 +64,12 @@ public final class TargetsExtractor: TargetsExtracting {
|
|||
}
|
||||
|
||||
private func sortTargetsByDependenciesCount(_ targets: [PBXTarget]) throws -> [TargetDependencyCount] {
|
||||
let sortedTargets = try targets.sorted { lTarget, rTarget -> Bool in
|
||||
let lCount = try countDependencies(of: lTarget)
|
||||
let rCount = try countDependencies(of: rTarget)
|
||||
if lCount == rCount {
|
||||
return lTarget.name < rTarget.name
|
||||
}
|
||||
return lCount < rCount
|
||||
}
|
||||
return try sortedTargets.map { TargetDependencyCount(targetName: $0.name, dependenciesCount: try countDependencies(of: $0)) }
|
||||
}
|
||||
|
||||
private func countDependencies(of target: PBXTarget) throws -> Int {
|
||||
var count = target.dependencies.count
|
||||
if let frameworkFiles = try target.frameworksBuildPhase()?.files {
|
||||
count += frameworkFiles.count
|
||||
}
|
||||
return count
|
||||
try topologicalSort(targets, successors: { $0.dependencies.compactMap(\.target) })
|
||||
.reversed()
|
||||
.map { TargetDependencyCount(
|
||||
targetName: $0.name,
|
||||
targetDependenciesNames: $0.dependencies.compactMap { $0.target?.name },
|
||||
linkedFrameworksCount: try $0.frameworksBuildPhase()?.files?.count ?? 0
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,10 +80,10 @@ tuist migration check-empty-settings -p Project.xcodeproj -t MyApp
|
|||
]}
|
||||
/>
|
||||
|
||||
## List targets sorted by dependencies
|
||||
## List targets sorted by topological order
|
||||
|
||||
Migration of big Xcode projects to Tuist can happen iteratively, one target at a time. It makes sense to start from the target with the lowest number of dependencies.
|
||||
To help with that, Tuist includes a command that lists the targets of a project sorted by number dependencies ascending. The count only includes dependencies that are declared in build phases.
|
||||
Migration of big Xcode projects to Tuist can happen iteratively, one target at a time.
|
||||
To help with that, Tuist includes a command that lists the targets of a project sorted by topological order, suggesting which target to resolve first.
|
||||
|
||||
```bash
|
||||
tuist migration list-targets -p Project.xcodeproj
|
||||
|
|
Loading…
Reference in New Issue