Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ extension ElementCreator {
includeSelf: Bool
) -> [BazelPath] {
return callable(
/*node:*/ node,
/*bazelPath:*/ bazelPath,
/*includeSelf:*/ includeSelf
/* node: */ node,
/* bazelPath: */ bazelPath,
/* includeSelf: */ includeSelf
)
}
}
Expand All @@ -46,7 +46,7 @@ extension ElementCreator.CollectBazelPaths {
switch node {
case .file:
return includeSelf ? [bazelPath] : []
case .group(_, let children):
case let .group(_, children):
var bazelPaths = children.flatMap { node in
return handleChildNode(node, parentBazelPath: bazelPath)
}
Expand All @@ -57,6 +57,8 @@ extension ElementCreator.CollectBazelPaths {
case .generatedFiles:
// Impossible to have generated files under localized or model files
fatalError()
case .buildableFolder:
return includeSelf ? [bazelPath] : []
}
}

Expand All @@ -65,13 +67,13 @@ extension ElementCreator.CollectBazelPaths {
parentBazelPath: BazelPath
) -> [BazelPath] {
switch node {
case .file(let name):
case let .file(name):
let bazelPath = BazelPath(
parent: parentBazelPath,
path: name
)
return [bazelPath]
case .group(let name, let children):
case let .group(name, children):
let bazelPath = BazelPath(
parent: parentBazelPath,
path: name
Expand All @@ -84,6 +86,8 @@ extension ElementCreator.CollectBazelPaths {
case .generatedFiles:
// Impossible to have generated files under localized or model files
fatalError()
case let .buildableFolder(path):
return [path]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ extension ElementCreator {
parentBazelPathType: BazelPathType
) -> GroupChild {
return callable(
/*node:*/ node,
/*parentBazelPath:*/ parentBazelPath,
/*parentBazelPathType:*/ parentBazelPathType,
/*createFile:*/ createFile,
/*createGroup:*/ createGroup,
/*createGroupChild:*/ self,
/*createInlineBazelGeneratedFiles:*/
/* node: */ node,
/* parentBazelPath: */ parentBazelPath,
/* parentBazelPathType: */ parentBazelPathType,
/* createFile: */ createFile,
/* createGroup: */ createGroup,
/* createGroupChild: */ self,
/* createInlineBazelGeneratedFiles: */
createInlineBazelGeneratedFiles,
/*createLocalizedFiles:*/ createLocalizedFiles,
/*createVersionGroup:*/ createVersionGroup
/* createLocalizedFiles: */ createLocalizedFiles,
/* createVersionGroup: */ createVersionGroup
)
}
}
Expand Down Expand Up @@ -82,7 +82,38 @@ extension ElementCreator.CreateGroupChild {
createVersionGroup: ElementCreator.CreateVersionGroup
) -> GroupChild {
switch node {
case .group(let name, let children):
case let .buildableFolder(path):
let name = path.path.lastPathComponent
let object = Object(
identifier: Identifiers.FilesAndGroups
.synchronizedRootGroup(path.path, name: name),
content: #"""
{
isa = PBXFileSystemSynchronizedRootGroup;
explicitFileTypes = {};
explicitFolders = (
);
path = \#(name.pbxProjEscaped);
sourceTree = "<group>";
}
"""#
)
let element = Element(
name: name,
object: object,
sortOrder: .groupLike
)
return .elementAndChildren(
.init(
element: element,
transitiveObjects: [object],
bazelPathAndIdentifiers: [],
knownRegions: [],
resolvedRepositories: []
)
)

case let .group(name, children):
let (basenameWithoutExt, ext) = name.splitExtension()
switch ext {
case "lproj":
Expand Down Expand Up @@ -130,7 +161,7 @@ extension ElementCreator.CreateGroupChild {
)
}

case .file(let name):
case let .file(name):
return .elementAndChildren(
createFile(
name: name,
Expand All @@ -143,7 +174,7 @@ extension ElementCreator.CreateGroupChild {
)
)

case .generatedFiles(let generatedFiles):
case let .generatedFiles(generatedFiles):
return .elementAndChildren(
createInlineBazelGeneratedFiles(
for: generatedFiles,
Expand All @@ -154,6 +185,12 @@ extension ElementCreator.CreateGroupChild {
}
}

private extension String {
var lastPathComponent: String {
return split(separator: "/").last.map(String.init) ?? self
}
}

struct Element: Equatable {
enum SortOrder: Comparable {
case groupLike
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ extension ElementCreator {
for pathTree: [PathTreeNode]
) -> GroupChildElements {
return callable(
/*pathTree:*/ pathTree,
/*includeCompileStub:*/ includeCompileStub,
/*installPath:*/ installPath,
/*workspace:*/ workspace,
/*createExternalRepositoriesGroup:*/
/* pathTree: */ pathTree,
/* includeCompileStub: */ includeCompileStub,
/* installPath: */ installPath,
/* workspace: */ workspace,
/* createExternalRepositoriesGroup: */
createExternalRepositoriesGroup,
/*createGroupChild:*/ createGroupChild,
/*createGroupChildElements:*/ createGroupChildElements,
/*createInternalGroup:*/ createInternalGroup
/* createGroupChild: */ createGroupChild,
/* createGroupChildElements: */ createGroupChildElements,
/* createInternalGroup: */ createInternalGroup
)
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ extension ElementCreator.CreateRootElements {
var groupChildren: [GroupChild] = []
for node in pathTree {
switch node {
case .group(let name, let children):
case let .group(name, children):
switch name {
case "external":
groupChildren.append(
Expand Down Expand Up @@ -120,7 +120,7 @@ extension ElementCreator.CreateRootElements {
)
}

case .file, .generatedFiles:
case .file, .generatedFiles, .buildableFolder:
groupChildren.append(
createGroupChild(
for: node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ struct ElementCreator {
arguments.executionRootFile
)

let createRootElements = environment.createCreateRootElements(
let createRootElements = try environment.createCreateRootElements(
executionRoot: executionRoot,
externalDir: try environment.externalDir(
externalDir: environment.externalDir(
executionRoot: executionRoot
),
includeCompileStub: compileStubNeeded,
installPath: arguments.installPath,
selectedModelVersions:
try environment.readSelectedModelVersionsFile(
environment.readSelectedModelVersionsFile(
arguments.selectedModelVersionsFile
),
workspace: arguments.workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import PBXProj
extension Generator {
static func calculatePathTree(
paths: [BazelPath],
generatedPaths: [GeneratedPath]
generatedPaths: [GeneratedPath],
buildableFolders: [BazelPath] = []
) -> [PathTreeNode] {
/// `[package: [config: [path]]`
// `[package: [config: [path]]`
var generatedPathsByPackageAndConfig:
[BazelPath: [String: [BazelPath]]] = [:]
for generatedPath in generatedPaths {
Expand Down Expand Up @@ -51,14 +52,14 @@ extension Generator {
(
package,
.multipleConfigs(
pathsByConfig.sorted { $0.key < $1.key }.map({ config, paths in
pathsByConfig.sorted { $0.key < $1.key }.map { config, paths in
return .init(
name: config,
path: "\(config)/\(packageBin)",
children:
calculateRootedPathTree(paths: paths)
)
})
}
)
)
)
Expand All @@ -67,17 +68,19 @@ extension Generator {

return calculateRootedPathTree(
paths: paths,
generatedFiles: generatedFiles
generatedFiles: generatedFiles,
buildableFolders: buildableFolders
)
}

private static func calculateRootedPathTree(
paths: [BazelPath],
generatedFiles: [
(package: BazelPath, generatedFiles: PathTreeNode.GeneratedFiles)
] = []
] = [],
buildableFolders: [BazelPath] = []
) -> [PathTreeNode] {
guard !paths.isEmpty else {
guard !paths.isEmpty || !generatedFiles.isEmpty || !buildableFolders.isEmpty else {
return []
}

Expand All @@ -87,14 +90,14 @@ extension Generator {
nodesByComponentCount[components.count, default: []]
.append(
PathTreeNodeToVisit(
components: components,
kind: .file
)
components: components,
kind: .file
)
)
}

for (`package`, generatedFiles) in generatedFiles {
var components = `package`.path.split(separator: "/")
for (package, generatedFiles) in generatedFiles {
var components = package.path.split(separator: "/")
components.append("")
nodesByComponentCount[components.count, default: []]
.append(
Expand All @@ -105,7 +108,21 @@ extension Generator {
)
}

for componentCount in (1...nodesByComponentCount.keys.max()!)
for buildableFolder in buildableFolders {
let components = buildableFolder.path.split(separator: "/")
guard !components.isEmpty else {
continue
}
nodesByComponentCount[components.count, default: []]
.append(
PathTreeNodeToVisit(
components: components,
kind: .buildableFolder(buildableFolder)
)
)
}

for componentCount in (1 ... nodesByComponentCount.keys.max()!)
.reversed()
{
let nodesToVisit = nodesByComponentCount
Expand Down Expand Up @@ -154,13 +171,15 @@ extension Generator {
switch nodeToVisit.kind {
case .file:
node = .file(String(nodeToVisit.components.last!))
case .group(let children):
case let .group(children):
node = .group(
name: String(nodeToVisit.components.last!),
children: children
)
case .generatedFiles(let generatedFiles):
case let .generatedFiles(generatedFiles):
node = .generatedFiles(generatedFiles)
case let .buildableFolder(buildableFolder):
node = .buildableFolder(buildableFolder)
}
collectedChildren.append(node)
}
Expand Down Expand Up @@ -203,19 +222,22 @@ enum PathTreeNode: Equatable {
case file(String)
case group(name: String, children: [PathTreeNode])
case generatedFiles(GeneratedFiles)
case buildableFolder(BazelPath)
}

extension PathTreeNode {
var nameForSpecialGroupChild: String {
switch self {
case .file(let name):
case let .file(name):
return name
case .group(let name, _):
case let .group(name, _):
return name
case .generatedFiles:
// This is only called from `CreateVerisonGroup` and
// `CreateLocalizedFiles` where this case can't be hit
fatalError()
case let .buildableFolder(path):
return path.path.lastPathComponent
}
}
}
Expand All @@ -225,6 +247,7 @@ private class PathTreeNodeToVisit {
case file
case group(children: [PathTreeNode])
case generatedFiles(PathTreeNode.GeneratedFiles)
case buildableFolder(BazelPath)
}

let components: [String.SubSequence]
Expand All @@ -238,3 +261,9 @@ private class PathTreeNodeToVisit {
self.kind = kind
}
}

private extension String {
var lastPathComponent: String {
return split(separator: "/").last.map(String.init) ?? self
}
}
Loading