mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
Added new group parameter to target sources, allowing to add them to a custom parent group (resolving #478)
This commit is contained in:
committed by
Romuald CARI
parent
538d1c6804
commit
15e615300e
@@ -143,6 +143,7 @@ class SourceGenerator {
|
||||
path: parentPath,
|
||||
mergingChildren: [fileReference],
|
||||
createIntermediateGroups: createIntermediateGroups,
|
||||
hasCustomParent: false,
|
||||
isBaseGroup: true
|
||||
)
|
||||
|
||||
@@ -270,7 +271,7 @@ class SourceGenerator {
|
||||
|
||||
/// Create a group or return an existing one at the path.
|
||||
/// Any merged children are added to a new group or merged into an existing one.
|
||||
private func getGroup(path: Path, name: String? = nil, mergingChildren children: [PBXFileElement], createIntermediateGroups: Bool, isBaseGroup: Bool) -> PBXGroup {
|
||||
private func getGroup(path: Path, name: String? = nil, mergingChildren children: [PBXFileElement], createIntermediateGroups: Bool, hasCustomParent: Bool, isBaseGroup: Bool) -> PBXGroup {
|
||||
let groupReference: PBXGroup
|
||||
|
||||
if let cachedGroup = groupsByPath[path] {
|
||||
@@ -293,10 +294,11 @@ class SourceGenerator {
|
||||
let isRootPath = (isBaseGroup && isOutOfBasePath) || path.parent() == project.basePath
|
||||
|
||||
// is a top level group in the project
|
||||
let isTopLevelGroup = (isBaseGroup && !createIntermediateGroups) || isRootPath
|
||||
let isTopLevelGroup = !hasCustomParent && ((isBaseGroup && !createIntermediateGroups) || isRootPath)
|
||||
|
||||
let groupName = name ?? path.lastComponent
|
||||
let groupPath = resolveGroupPath(path, isTopLevelGroup: isTopLevelGroup)
|
||||
|
||||
let groupPath = resolveGroupPath(path, isTopLevelGroup: hasCustomParent || isTopLevelGroup)
|
||||
|
||||
let group = PBXGroup(
|
||||
children: children,
|
||||
@@ -387,8 +389,16 @@ class SourceGenerator {
|
||||
}
|
||||
|
||||
/// creates all the source files and groups they belong to for a given targetSource
|
||||
private func getGroupSources(targetType: PBXProductType, targetSource: TargetSource, path: Path, isBaseGroup: Bool, excludePaths: Set<Path>, includePaths: Set<Path>)
|
||||
throws -> (sourceFiles: [SourceFile], groups: [PBXGroup]) {
|
||||
private func getGroupSources(
|
||||
targetType: PBXProductType,
|
||||
targetSource: TargetSource,
|
||||
path: Path,
|
||||
isBaseGroup: Bool,
|
||||
createIntermediateGroups: Bool,
|
||||
hasCustomParent: Bool,
|
||||
excludePaths: Set<Path>,
|
||||
includePaths: Set<Path>
|
||||
) throws -> (sourceFiles: [SourceFile], groups: [PBXGroup]) {
|
||||
|
||||
let children = try getSourceChildren(targetSource: targetSource, dirPath: path, excludePaths: excludePaths, includePaths: includePaths)
|
||||
|
||||
@@ -408,12 +418,17 @@ class SourceGenerator {
|
||||
var groups: [PBXGroup] = []
|
||||
|
||||
for path in directories {
|
||||
let subGroups = try getGroupSources(targetType: targetType,
|
||||
targetSource: targetSource,
|
||||
path: path,
|
||||
isBaseGroup: false,
|
||||
excludePaths: excludePaths,
|
||||
includePaths: includePaths)
|
||||
|
||||
let subGroups = try getGroupSources(
|
||||
targetType: targetType,
|
||||
targetSource: targetSource,
|
||||
path: path,
|
||||
isBaseGroup: false,
|
||||
createIntermediateGroups: createIntermediateGroups,
|
||||
hasCustomParent: false,
|
||||
excludePaths: excludePaths,
|
||||
includePaths: includePaths
|
||||
)
|
||||
|
||||
guard !subGroups.sourceFiles.isEmpty || project.options.generateEmptyDirectories else {
|
||||
continue
|
||||
@@ -499,12 +514,11 @@ class SourceGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
let createIntermediateGroups = targetSource.createIntermediateGroups ?? project.options.createIntermediateGroups
|
||||
|
||||
let group = getGroup(
|
||||
path: path,
|
||||
mergingChildren: groupChildren,
|
||||
createIntermediateGroups: createIntermediateGroups,
|
||||
hasCustomParent: hasCustomParent,
|
||||
isBaseGroup: isBaseGroup
|
||||
)
|
||||
if createIntermediateGroups {
|
||||
@@ -524,6 +538,10 @@ class SourceGenerator {
|
||||
let includePaths = getSourceMatches(targetSource: targetSource, patterns: targetSource.includes)
|
||||
|
||||
let type = targetSource.type ?? (path.isFile || path.extension != nil ? .file : .group)
|
||||
|
||||
let customParentGroups = (targetSource.group ?? "").split(separator: "/")
|
||||
let hasCustomParent = !customParentGroups.isEmpty
|
||||
|
||||
let createIntermediateGroups = targetSource.createIntermediateGroups ?? project.options.createIntermediateGroups
|
||||
|
||||
var sourceFiles: [SourceFile] = []
|
||||
@@ -540,7 +558,7 @@ class SourceGenerator {
|
||||
lastKnownFileType: "folder"
|
||||
)
|
||||
|
||||
if !createIntermediateGroups || path.parent() == project.basePath {
|
||||
if !(createIntermediateGroups || hasCustomParent) || path.parent() == project.basePath {
|
||||
rootGroups.insert(fileReference)
|
||||
}
|
||||
|
||||
@@ -566,7 +584,13 @@ class SourceGenerator {
|
||||
sourceReference = fileReference
|
||||
rootGroups.insert(fileReference)
|
||||
} else {
|
||||
let parentGroup = getGroup(path: parentPath, mergingChildren: [fileReference], createIntermediateGroups: createIntermediateGroups, isBaseGroup: true)
|
||||
let parentGroup = getGroup(
|
||||
path: parentPath,
|
||||
mergingChildren: [fileReference],
|
||||
createIntermediateGroups: createIntermediateGroups,
|
||||
hasCustomParent: hasCustomParent,
|
||||
isBaseGroup: true
|
||||
)
|
||||
sourcePath = parentPath
|
||||
sourceReference = parentGroup
|
||||
}
|
||||
@@ -577,12 +601,18 @@ class SourceGenerator {
|
||||
// This group is missing, so if's optional just return an empty array
|
||||
return []
|
||||
}
|
||||
let (groupSourceFiles, groups) = try getGroupSources(targetType: targetType,
|
||||
targetSource: targetSource,
|
||||
path: path,
|
||||
isBaseGroup: true,
|
||||
excludePaths: excludePaths,
|
||||
includePaths: includePaths)
|
||||
|
||||
let (groupSourceFiles, groups) = try getGroupSources(
|
||||
targetType: targetType,
|
||||
targetSource: targetSource,
|
||||
path: path,
|
||||
isBaseGroup: true,
|
||||
createIntermediateGroups: createIntermediateGroups,
|
||||
hasCustomParent: hasCustomParent,
|
||||
excludePaths: excludePaths,
|
||||
includePaths: includePaths
|
||||
)
|
||||
|
||||
let group = groups.first!
|
||||
if let name = targetSource.name {
|
||||
group.name = name
|
||||
@@ -592,13 +622,40 @@ class SourceGenerator {
|
||||
sourceReference = group
|
||||
}
|
||||
|
||||
if createIntermediateGroups {
|
||||
if hasCustomParent {
|
||||
createParentGroups(customParentGroups, for: sourceReference)
|
||||
} else if createIntermediateGroups {
|
||||
createIntermediaGroups(for: sourceReference, at: sourcePath)
|
||||
}
|
||||
|
||||
return sourceFiles
|
||||
}
|
||||
|
||||
private func createParentGroups(_ parentGroups: [String.SubSequence], for fileElement: PBXFileElement) {
|
||||
guard let parentName = parentGroups.last else {
|
||||
return
|
||||
}
|
||||
|
||||
let parentPath = project.basePath + Path(parentGroups.joined(separator: "/"))
|
||||
|
||||
let hasParentGroup = groupsByPath[parentPath] != nil
|
||||
let parentGroup = getGroup(
|
||||
path: parentPath,
|
||||
mergingChildren: [fileElement],
|
||||
createIntermediateGroups: false,
|
||||
hasCustomParent: false,
|
||||
isBaseGroup: false
|
||||
)
|
||||
|
||||
// As this path is a custom group, remove the path reference
|
||||
parentGroup.name = String(parentName)
|
||||
parentGroup.path = nil
|
||||
|
||||
if !hasParentGroup {
|
||||
createParentGroups(parentGroups.dropLast(), for: parentGroup)
|
||||
}
|
||||
}
|
||||
|
||||
// Add groups for all parents recursively
|
||||
private func createIntermediaGroups(for fileElement: PBXFileElement, at path: Path) {
|
||||
|
||||
@@ -609,7 +666,13 @@ class SourceGenerator {
|
||||
}
|
||||
|
||||
let hasParentGroup = groupsByPath[parentPath] != nil
|
||||
let parentGroup = getGroup(path: parentPath, mergingChildren: [fileElement], createIntermediateGroups: true, isBaseGroup: false)
|
||||
let parentGroup = getGroup(
|
||||
path: parentPath,
|
||||
mergingChildren: [fileElement],
|
||||
createIntermediateGroups: true,
|
||||
hasCustomParent: false,
|
||||
isBaseGroup: false
|
||||
)
|
||||
|
||||
if !hasParentGroup {
|
||||
createIntermediaGroups(for: parentGroup, at: parentPath)
|
||||
|
||||
Reference in New Issue
Block a user