Skip to content

Commit e0c4edf

Browse files
authored
Migrate FileHandler.resolveSymlink to FileSystem (tuist#6825)
* Migrate FileHandler.resolveSymlink to FileSystem * Revert to using /var instead of /private/var in acceptance tests * Fix RunAcceptanceTestCommandLineToolBasic test
1 parent a6922e9 commit e0c4edf

8 files changed

Lines changed: 24 additions & 26 deletions

File tree

Sources/TuistAcceptanceTesting/TuistAcceptanceTestCase.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ open class TuistAcceptanceTestCase: XCTestCase {
7070
.appending(component: "fixtures")
7171

7272
fixturePath = fixtureTemporaryDirectory.path.appending(component: fixture.path)
73-
if fixturePath.components[1] == "var" {
74-
// `resolveSymlinks` doesn't seem to properly resolve /var to /private/var when running the fixture in a temporary
75-
// directory.
76-
// The project needs to be reference by its full absolute path without symlinks.
77-
fixturePath = try AbsolutePath(validating: "/private")
78-
.appending(components: Array(fixturePath.components.dropFirst()))
79-
}
8073

8174
try FileHandler.shared.copy(
8275
from: fixturesPath.appending(component: fixture.path),

Sources/TuistKit/ProjectEditor/ProjectEditor.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import FileSystem
12
import Foundation
23
import Mockable
34
import Path
@@ -216,18 +217,24 @@ final class ProjectEditor: ProjectEditing {
216217
plugins: Plugins,
217218
onlyCurrentDirectory: Bool
218219
) async throws -> [EditablePluginManifest] {
219-
let loadedEditablePluginManifests = try plugins.projectDescriptionHelpers
220+
let loadedEditablePluginManifests = plugins.projectDescriptionHelpers
220221
.filter { $0.location == .local }
221-
.map { EditablePluginManifest(name: $0.name, path: try FileHandler.shared.resolveSymlinks($0.path.parentDirectory)) }
222+
.map {
223+
EditablePluginManifest(
224+
name: $0.name,
225+
path: $0.path.parentDirectory
226+
)
227+
}
222228

223229
let localEditablePluginManifests = try await manifestFilesLocator.locatePluginManifests(
224230
at: path,
225231
excluding: excluding,
226232
onlyCurrentDirectory: onlyCurrentDirectory
227-
).map {
233+
)
234+
.map {
228235
EditablePluginManifest(
229236
name: $0.parentDirectory.basename,
230-
path: try FileHandler.shared.resolveSymlinks($0.parentDirectory)
237+
path: $0.parentDirectory
231238
)
232239
}
233240

Sources/TuistLoader/Loaders/SwiftPackageManagerGraphLoader.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ public final class SwiftPackageManagerGraphLoader: SwiftPackageManagerGraphLoadi
115115
guard let path = dependency.packageRef.path ?? dependency.packageRef.location else {
116116
throw SwiftPackageManagerGraphGeneratorError.missingPathInLocalSwiftPackage(name)
117117
}
118-
packageFolder = try AbsolutePath(validating: path)
118+
// There's a bug in the `relative` implementation that produces the wrong path when using a symbolic link.
119+
// This leads to nonexisting path in the `ModuleMapMapper` that relies on that method.
120+
// To get around this, we're aligning paths from `workspace-state.json` with the /var temporary directory.
121+
packageFolder = try AbsolutePath(
122+
validating: path.replacingOccurrences(of: "/private/var", with: "/var")
123+
)
119124
case "registry":
120125
let registryFolder = path.appending(try RelativePath(validating: "registry/downloads"))
121126
packageFolder = registryFolder.appending(try RelativePath(validating: dependency.subpath))

Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,8 @@ extension ProjectDescription.ResourceFileElements {
870870
{
871871
let absolutePathGlob = resourceAbsolutePath.extension != nil ? resourceAbsolutePath : resourceAbsolutePath
872872
.appending(component: "**")
873-
if try excludedPaths
874-
.contains(where: { try FileHandler.shared.resolveSymlinks(absolutePathGlob).isDescendantOfOrEqual(to: $0) })
873+
if excludedPaths
874+
.contains(where: { absolutePathGlob.isDescendantOfOrEqual(to: $0) })
875875
{
876876
return nil
877877
}
@@ -927,7 +927,7 @@ extension ProjectDescription.ResourceFileElements {
927927
}
928928
}
929929
)
930-
resourceFileElements += try defaultResourcePaths(from: path) { candidateURL in
930+
resourceFileElements += try await defaultResourcePaths(from: path) { candidateURL in
931931
let candidatePath = AbsolutePath(stringLiteral: candidateURL.path)
932932
let candidateNotInExcludedDirectory = excludedPaths.allSatisfy { !$0.isAncestorOfOrEqual(to: candidatePath) }
933933
return candidateNotInExcludedDirectory

Sources/TuistSupport/Utils/FileHandler.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public protocol FileHandling: AnyObject {
8686
func urlSafeBase64MD5(path: Path.AbsolutePath) throws -> String
8787
func fileSize(path: Path.AbsolutePath) throws -> UInt64
8888
func changeExtension(path: Path.AbsolutePath, to newExtension: String) throws -> Path.AbsolutePath
89-
func resolveSymlinks(_ path: Path.AbsolutePath) throws -> Path.AbsolutePath
9089
func fileAttributes(at path: Path.AbsolutePath) throws -> [FileAttributeKey: Any]
9190
func filesAndDirectoriesContained(in path: Path.AbsolutePath) throws -> [Path.AbsolutePath]?
9291
func zipItem(at sourcePath: Path.AbsolutePath, to destinationPath: Path.AbsolutePath) throws
@@ -353,10 +352,6 @@ public class FileHandler: FileHandling {
353352
try fileManager.createSymbolicLink(atPath: path.pathString, withDestinationPath: destination.pathString)
354353
}
355354

356-
public func resolveSymlinks(_ path: Path.AbsolutePath) throws -> Path.AbsolutePath {
357-
try .init(validating: TSCBasic.resolveSymlinks(.init(validating: path.pathString)).pathString)
358-
}
359-
360355
public func fileAttributes(at path: Path.AbsolutePath) throws -> [FileAttributeKey: Any] {
361356
try fileManager.attributesOfItem(atPath: path.pathString)
362357
}

Tests/TuistGeneratorTests/Generator/WorkspaceStructureGeneratorTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,6 @@ final class WorkspaceStructureGeneratorTests: XCTestCase {
405405
[]
406406
}
407407

408-
func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
409-
path
410-
}
411-
412408
func fileAttributes(at _: AbsolutePath) throws -> [FileAttributeKey: Any] {
413409
[:]
414410
}

Tests/TuistKitAcceptanceTests/RunAcceptanceTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import XCTest
88
final class RunAcceptanceTestCommandLineToolBasic: TuistAcceptanceTestCase {
99
func test_command_line_tool_basic() async throws {
1010
try await setUpFixture(.commandLineToolBasic)
11-
fixturePath = try AbsolutePath(validating: "/")
12-
.appending(components: Array(fixturePath.components.dropFirst(2)))
1311
try await run(InstallCommand.self)
1412
try await run(RunCommand.self, "CommandLineTool")
1513
}

Tests/TuistKitTests/ProjectEditor/ProjectEditorTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ final class ProjectEditorTests: TuistUnitTestCase {
240240
directory.appending(components: "C", "Plugin.swift"),
241241
directory.appending(components: "D", "Plugin.swift"),
242242
]
243+
for pluginManifest in pluginManifests {
244+
try await fileSystem.makeDirectory(at: pluginManifest.parentDirectory)
245+
try await fileSystem.touch(pluginManifest)
246+
}
243247
let tuistPath = try AbsolutePath(validating: ProcessInfo.processInfo.arguments.first!)
244248

245249
// When

0 commit comments

Comments
 (0)