sort Projects and Frameworks groups at the end

This commit is contained in:
Yonas Kolb 2018-07-23 21:57:17 +10:00
parent aca6f9d633
commit 2be5aabaff
3 changed files with 32 additions and 10 deletions

View File

@ -16,7 +16,7 @@ public class PBXProjGenerator {
var targetAggregateObjects: [String: ObjectReference<PBXAggregateTarget>] = [:]
var targetBuildFiles: [String: ObjectReference<PBXBuildFile>] = [:]
var targetFileReferences: [String: String] = [:]
var topLevelGroups: Set<String> = []
var carthageFrameworksByPlatform: [String: Set<String>] = [:]
var frameworkFiles: [String] = []
@ -80,6 +80,8 @@ public class PBXProjGenerator {
)
)
var derivedGroups: [ObjectReference<PBXGroup>] = []
let mainGroup = createObject(
id: "Project",
PBXGroup(
@ -161,7 +163,7 @@ public class PBXProjGenerator {
name: "Products"
)
)
topLevelGroups.insert(productGroup.reference)
derivedGroups.append(productGroup)
if !carthageFrameworksByPlatform.isEmpty {
var platforms: [PBXGroup] = []
@ -199,15 +201,16 @@ public class PBXProjGenerator {
name: "Frameworks"
)
)
topLevelGroups.insert(group.reference)
derivedGroups.append(group)
}
for rootGroup in sourceGenerator.rootGroups {
topLevelGroups.insert(rootGroup)
}
mainGroup.object.children = Array(topLevelGroups)
mainGroup.object.children = Array(sourceGenerator.rootGroups)
sortGroups(group: mainGroup)
// add derived groups at the end
derivedGroups.forEach(sortGroups)
mainGroup.object.children += derivedGroups
.sorted { $0.object.nameOrPath.localizedStandardCompare($1.object.nameOrPath) == .orderedAscending }
.map { $0.reference }
let projectAttributes: [String: Any] = ["LastUpgradeCheck": project.xcodeVersion]
.merged(project.attributes)

View File

@ -559,10 +559,8 @@
G_8340618952527 /* Configs */,
G_3234630030493 /* FileGroup */,
G_4661500274312 /* Framework */,
G_1952740716080 /* Frameworks */,
G_8268950006174 /* iMessage */,
G_1646573205915 /* iMessage MessagesExtension */,
G_8620238527590 /* Products */,
G_7189434949822 /* Resources */,
G_6651250437419 /* StandaloneFiles */,
G_3997550084026 /* StaticLibrary_ObjC */,
@ -571,6 +569,8 @@
FR_232605427418 /* Mintfile */,
FR_257073931060 /* ResourceFolder */,
FR_775316160345 /* SomeFile */,
G_1952740716080 /* Frameworks */,
G_8620238527590 /* Products */,
);
indentWidth = 2;
sourceTree = "<group>";

View File

@ -459,6 +459,25 @@ class SourceGeneratorTests: XCTestCase {
try expect(sourcesBuildPhase.files.count) == 1
}
$0.it("derived directories are sorted last") {
let directories = """
A:
- file.swift
P:
- file.swift
S:
- file.swift
"""
try createDirectories(directories)
let target = Target(name: "Test", type: .application, platform: .iOS, sources: ["A", "P", "S"], dependencies: [Dependency(type: .carthage, reference: "Alamofire")])
let project = Project(basePath: directoryPath, name: "Test", targets: [target])
let pbxProj = try project.generatePbxProj()
let groups = try pbxProj.getMainGroup().children.compactMap { pbxProj.objects.getFileElement(reference: $0)?.nameOrPath }
try expect(groups) == ["A", "P", "S", "Frameworks", "Products"]
}
}
}
}