From e77a4355261063b677c56fce137673e2cfadbfb2 Mon Sep 17 00:00:00 2001 From: Sergey Erokhin Date: Mon, 11 Aug 2025 14:39:05 +0300 Subject: [PATCH] Fix infinity loop --- Sources/ProjectDrivers/XcodeProjectDriver.swift | 9 ++++++--- Sources/XcodeSupport/XcodeProject.swift | 10 +++++----- Sources/XcodeSupport/XcodeProjectSetupGuide.swift | 2 ++ Sources/XcodeSupport/XcodeWorkspace.swift | 5 ++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Sources/ProjectDrivers/XcodeProjectDriver.swift b/Sources/ProjectDrivers/XcodeProjectDriver.swift index c185e4c26..918fbc26a 100644 --- a/Sources/ProjectDrivers/XcodeProjectDriver.swift +++ b/Sources/ProjectDrivers/XcodeProjectDriver.swift @@ -34,8 +34,9 @@ try xcodebuild.ensureConfigured() - let project: XcodeProjectlike = if projectPath.extension == "xcworkspace" { - try XcodeWorkspace( + let project: XcodeProjectlike + if projectPath.extension == "xcworkspace" { + project = try XcodeWorkspace( path: .makeAbsolute(projectPath), xcodebuild: xcodebuild, configuration: configuration, @@ -43,8 +44,10 @@ shell: shell ) } else { - try XcodeProject( + var loadedProjectPaths: Set = [] + project = try XcodeProject( path: .makeAbsolute(projectPath), + loadedProjectPaths: &loadedProjectPaths, xcodebuild: xcodebuild, shell: shell, logger: logger diff --git a/Sources/XcodeSupport/XcodeProject.swift b/Sources/XcodeSupport/XcodeProject.swift index 57c374f65..52e7490a0 100644 --- a/Sources/XcodeSupport/XcodeProject.swift +++ b/Sources/XcodeSupport/XcodeProject.swift @@ -17,7 +17,7 @@ public final class XcodeProject: XcodeProjectlike { convenience init?( path: FilePath, - loadedProjectPaths: Set = [], + loadedProjectPaths: inout Set, referencedBy refPath: FilePath, shell: Shell, @@ -31,7 +31,7 @@ public final class XcodeProject: XcodeProjectlike { let xcodebuild = Xcodebuild(shell: shell, logger: logger) try self.init( path: path, - loadedProjectPaths: loadedProjectPaths, + loadedProjectPaths: &loadedProjectPaths, xcodebuild: xcodebuild, shell: shell, logger: logger @@ -40,7 +40,7 @@ public final class XcodeProject: XcodeProjectlike { public required init( path: FilePath, - loadedProjectPaths: Set = [], + loadedProjectPaths: inout Set, xcodebuild: Xcodebuild, shell: Shell, logger: Logger @@ -59,7 +59,7 @@ public final class XcodeProject: XcodeProjectlike { } var subProjects: [XcodeProject] = [] - let loadedProjectPaths = loadedProjectPaths.union([path]) + loadedProjectPaths.insert(path) // Don't search for sub projects within CocoaPods. if !path.components.contains("Pods.xcodeproj") { @@ -74,7 +74,7 @@ public final class XcodeProject: XcodeProjectlike { return try XcodeProject( path: projectPath, - loadedProjectPaths: loadedProjectPaths, + loadedProjectPaths: &loadedProjectPaths, referencedBy: path, shell: shell, logger: logger diff --git a/Sources/XcodeSupport/XcodeProjectSetupGuide.swift b/Sources/XcodeSupport/XcodeProjectSetupGuide.swift index 2a6de62ae..6ad95589c 100644 --- a/Sources/XcodeSupport/XcodeProjectSetupGuide.swift +++ b/Sources/XcodeSupport/XcodeProjectSetupGuide.swift @@ -68,8 +68,10 @@ public final class XcodeProjectSetupGuide: SetupGuideHelpers, SetupGuide { shell: shell ) } else if let projectPath = identifyProject() { + var loadedProjectPaths: Set = [] project = try XcodeProject( path: projectPath, + loadedProjectPaths: &loadedProjectPaths, xcodebuild: xcodebuild, shell: shell, logger: logger diff --git a/Sources/XcodeSupport/XcodeWorkspace.swift b/Sources/XcodeSupport/XcodeWorkspace.swift index b6faea57c..d4f6dd11f 100644 --- a/Sources/XcodeSupport/XcodeWorkspace.swift +++ b/Sources/XcodeSupport/XcodeWorkspace.swift @@ -31,7 +31,10 @@ public final class XcodeWorkspace: XcodeProjectlike { } let projectPaths = collectProjectPaths(in: xcworkspace.data.children) - let projects = try projectPaths.compactMapSet { try XcodeProject(path: sourceRoot.pushing($0), referencedBy: self.path, shell: shell, logger: logger) } + var loadedProjectPaths: Set = [] + let projects = try projectPaths.compactMapSet { + try XcodeProject(path: sourceRoot.pushing($0), loadedProjectPaths: &loadedProjectPaths, referencedBy: self.path, shell: shell, logger: logger) + } targets = projects.reduce(into: .init()) { result, project in result.formUnion(project.targets)