Skip to content

Commit c0b9d80

Browse files
committed
fixup
1 parent f36ac1a commit c0b9d80

File tree

8 files changed

+67
-65
lines changed

8 files changed

+67
-65
lines changed

Sources/PackageGraph/PinsStore.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public final class PinsStore {
5151
/// - Parameters:
5252
/// - pinsFile: Path to the pins file.
5353
/// - fileSystem: The filesystem to manage the pin file on.
54-
public init(pinsFile: AbsolutePath, fileSystem: FileSystem, mirrors: DependencyMirrors) throws {
55-
self.storage = .init(path: pinsFile, fileSystem: fileSystem)
54+
public init(pinsFile: AbsolutePath, workingDirectory: AbsolutePath, fileSystem: FileSystem, mirrors: DependencyMirrors) throws {
55+
self.storage = .init(path: pinsFile, workingDirectory: workingDirectory, fileSystem: fileSystem)
5656
self.mirrors = mirrors
5757

5858
do {
@@ -103,12 +103,14 @@ public final class PinsStore {
103103

104104
fileprivate struct PinsStorage {
105105
private let path: AbsolutePath
106+
private let lockFilePath: AbsolutePath
106107
private let fileSystem: FileSystem
107108
private let encoder = JSONEncoder.makeWithDefaults()
108109
private let decoder = JSONDecoder.makeWithDefaults()
109110

110-
init(path: AbsolutePath, fileSystem: FileSystem) {
111+
init(path: AbsolutePath, workingDirectory: AbsolutePath, fileSystem: FileSystem) {
111112
self.path = path
113+
self.lockFilePath = workingDirectory.appending(component: path.basename)
112114
self.fileSystem = fileSystem
113115
}
114116

@@ -117,8 +119,7 @@ fileprivate struct PinsStorage {
117119
return [:]
118120
}
119121

120-
// 👀 do we want a lock file here? safer but pretty noisy
121-
//return try self.fileSystem.withLock(on: self.path, type: .shared) {
122+
return try self.fileSystem.withLock(on: self.lockFilePath, type: .shared) {
122123
let version = try self.decoder.decode(path: self.path, fileSystem: self.fileSystem, as: Version.self)
123124
switch version.version {
124125
case 1:
@@ -132,15 +133,14 @@ fileprivate struct PinsStorage {
132133
default:
133134
throw InternalError("unknown RepositoryManager version: \(version)")
134135
}
135-
//}
136+
}
136137
}
137138

138139
func save(pins: PinsStore.PinsMap, mirrors: DependencyMirrors, removeIfEmpty: Bool) throws {
139140
if !self.fileSystem.exists(self.path.parentDirectory) {
140141
try self.fileSystem.createDirectory(self.path.parentDirectory)
141142
}
142-
// 👀 do we want a lock file here? safer but pretty noisy
143-
//try self.fileSystem.withLock(on: self.path, type: .exclusive) {
143+
try self.fileSystem.withLock(on: self.lockFilePath, type: .exclusive) {
144144
// Remove the pins file if there are zero pins to save.
145145
//
146146
// This can happen if all dependencies are path-based or edited
@@ -153,17 +153,16 @@ fileprivate struct PinsStorage {
153153
let container = V1(pins: pins, mirrors: mirrors)
154154
let data = try self.encoder.encode(container)
155155
try self.fileSystem.writeFileContents(self.path, data: data)
156-
//}
156+
}
157157
}
158158

159159
func reset() throws {
160160
if !self.fileSystem.exists(self.path.parentDirectory) {
161161
return
162162
}
163-
// 👀 do we want a lock file here? safer but pretty noisy
164-
//try self.fileSystem.withLock(on: self.path, type: .exclusive) {
163+
try self.fileSystem.withLock(on: self.lockFilePath, type: .exclusive) {
165164
try self.fileSystem.removeFileTree(self.path)
166-
//}
165+
}
167166
}
168167

169168
// version reader

Sources/SourceControl/RepositoryManager.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public class RepositoryManager {
9898
self.repositories = .init(try self.storage.load(manager: self))
9999
} catch {
100100
self.repositories = .init()
101-
// 👀 delete the file okay?
102101
try? self.storage.reset()
103102
// FIXME: We should emit a warning here using the diagnostic engine.
104103
TSCBasic.stderrStream.write("warning: unable to restore checkouts state: \(error)")

Sources/Workspace/Workspace.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,12 @@ public class Workspace {
332332
)
333333

334334
self.pinsStore = LoadableResult {
335-
try PinsStore(pinsFile: location.resolvedVersionsFile, fileSystem: fileSystem, mirrors: mirrors)
335+
try PinsStore(
336+
pinsFile: location.resolvedVersionsFile,
337+
workingDirectory: location.workingDirectory,
338+
fileSystem: fileSystem,
339+
mirrors: mirrors
340+
)
336341
}
337342

338343
self.additionalFileRules = additionalFileRules
@@ -724,7 +729,7 @@ extension Workspace {
724729
// the pins for the input packages so only those packages are updated.
725730
pinsMap = pinsStore.pinsMap.filter{ !packages.contains($0.value.packageRef.name) }
726731
}
727-
732+
728733
// Resolve the dependencies.
729734
let resolver = try self.createResolver(pinsMap: pinsMap)
730735
self.activeResolver = resolver
@@ -921,7 +926,7 @@ extension Workspace {
921926
})
922927
}
923928
}
924-
929+
925930
public func loadRootPackage(
926931
at path: AbsolutePath,
927932
diagnostics: DiagnosticsEngine,
@@ -2001,7 +2006,7 @@ extension Workspace {
20012006
for pin in pinsStore.pins {
20022007
containerProvider.getContainer(for: pin.packageRef, skipUpdate: true, on: .sharedConcurrent, completion: { _ in })
20032008
}
2004-
2009+
20052010
// Compute the pins that we need to actually clone.
20062011
//
20072012
// We require cloning if there is no checkout or if the checkout doesn't

Sources/Workspace/WorkspaceState.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public final class WorkspaceState {
4848
} catch {
4949
self.dependencies = ManagedDependencies()
5050
self.artifacts = ManagedArtifacts()
51-
// 👀 delete the file okay?
5251
try? self.storage.reset()
5352
// FIXME: We should emit a warning here using the diagnostic engine.
5453
TSCBasic.stderrStream.write("warning: unable to restore workspace state: \(error)")

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ final class PackageToolTests: XCTestCase {
157157
}
158158

159159
func testDescribe() throws {
160-
160+
161161
fixture(name: "Miscellaneous/ExeTest") { prefix in
162162
// Generate the JSON description.
163163
let jsonResult = try SwiftPMProduct.SwiftPackage.executeProcess(["describe", "--type=json"], packagePath: prefix)
@@ -177,7 +177,7 @@ final class PackageToolTests: XCTestCase {
177177
let jsonResult = try SwiftPMProduct.SwiftPackage.executeProcess(["describe", "--type=json"], packagePath: prefix)
178178
let jsonOutput = try jsonResult.utf8Output()
179179
let json = try JSON(bytes: ByteString(encodingAsUTF8: jsonOutput))
180-
180+
181181
// Check that the JSON description contains what we expect it to.
182182
XCTAssertEqual(json["name"]?.string, "SwiftCMixed")
183183
XCTAssertEqual(json["path"]?.string?.hasPrefix("/"), true)
@@ -213,7 +213,7 @@ final class PackageToolTests: XCTestCase {
213213
chunks.append(line + "\n")
214214
}
215215
}.filter{ !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
216-
216+
217217
// Check that the text description contains what we expect it to.
218218
// FIXME: This is a bit inelegant, but any errors are easy to reason about.
219219
let textChunk0 = try XCTUnwrap(textChunks[0])
@@ -270,7 +270,7 @@ final class PackageToolTests: XCTestCase {
270270
}
271271

272272
}
273-
273+
274274
func testDescribePackageUsingPlugins() throws {
275275
fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { prefix in
276276
// Generate the JSON description.
@@ -343,14 +343,14 @@ final class PackageToolTests: XCTestCase {
343343
func testShowDependencies_dotFormat_sr12016() throws {
344344
// Confirm that SR-12016 is resolved.
345345
// See https://bugs.swift.org/browse/SR-12016
346-
346+
347347
let fileSystem = InMemoryFileSystem(emptyFiles: [
348348
"/PackageA/Sources/TargetA/main.swift",
349349
"/PackageB/Sources/TargetB/B.swift",
350350
"/PackageC/Sources/TargetC/C.swift",
351351
"/PackageD/Sources/TargetD/D.swift",
352352
])
353-
353+
354354
let manifestA = Manifest.createManifest(
355355
name: "PackageA",
356356
path: "/PackageA",
@@ -368,7 +368,7 @@ final class PackageToolTests: XCTestCase {
368368
try .init(name: "TargetA", dependencies: ["PackageB", "PackageC"])
369369
]
370370
)
371-
371+
372372
let manifestB = Manifest.createManifest(
373373
name: "PackageB",
374374
path: "/PackageB",
@@ -386,7 +386,7 @@ final class PackageToolTests: XCTestCase {
386386
try .init(name: "TargetB", dependencies: ["PackageC", "PackageD"])
387387
]
388388
)
389-
389+
390390
let manifestC = Manifest.createManifest(
391391
name: "PackageC",
392392
path: "/PackageC",
@@ -403,7 +403,7 @@ final class PackageToolTests: XCTestCase {
403403
try .init(name: "TargetC", dependencies: ["PackageD"])
404404
]
405405
)
406-
406+
407407
let manifestD = Manifest.createManifest(
408408
name: "PackageD",
409409
path: "/PackageD",
@@ -417,25 +417,25 @@ final class PackageToolTests: XCTestCase {
417417
try .init(name: "TargetD")
418418
]
419419
)
420-
420+
421421
let diagnostics = DiagnosticsEngine()
422422
let graph = try loadPackageGraph(fs: fileSystem,
423423
diagnostics: diagnostics,
424424
manifests: [manifestA, manifestB, manifestC, manifestD])
425425
XCTAssertNoDiagnostics(diagnostics)
426-
426+
427427
let output = BufferedOutputByteStream()
428428
dumpDependenciesOf(rootPackage: graph.rootPackages[0], mode: .dot, on: output)
429429
let dotFormat = output.bytes.description
430-
430+
431431
var alreadyPutOut: Set<Substring> = []
432432
for line in dotFormat.split(whereSeparator: { $0.isNewline }) {
433433
if alreadyPutOut.contains(line) {
434434
XCTFail("Same line was already put out: \(line)")
435435
}
436436
alreadyPutOut.insert(line)
437437
}
438-
438+
439439
let expectedLines: [Substring] = [
440440
#""/PackageA" [label="packagea\n/PackageA\nunspecified"]"#,
441441
#""/PackageB" [label="packageb\n/PackageB\nunspecified"]"#,
@@ -496,7 +496,7 @@ final class PackageToolTests: XCTestCase {
496496

497497
let resultPath = root.appending(component: "result.json")
498498
_ = try execute(["show-dependencies", "--format", "json", "--output-path", resultPath.pathString ], packagePath: root)
499-
499+
500500
XCTAssert(fs.exists(resultPath))
501501
let jsonOutput = try fs.readFileContents(resultPath)
502502
let json = try JSON(bytes: jsonOutput)
@@ -722,7 +722,7 @@ final class PackageToolTests: XCTestCase {
722722
// Try to pin bar at a branch.
723723
do {
724724
try execute("resolve", "bar", "--branch", "YOLO")
725-
let pinsStore = try PinsStore(pinsFile: pinsFile, fileSystem: localFileSystem, mirrors: .init())
725+
let pinsStore = try PinsStore(pinsFile: pinsFile, workingDirectory: prefix, fileSystem: localFileSystem, mirrors: .init())
726726
let state = CheckoutState.branch(name: "YOLO", revision: yoloRevision)
727727
let identity = PackageIdentity(path: barPath)
728728
XCTAssertEqual(pinsStore.pinsMap[identity]?.state, state)
@@ -731,7 +731,7 @@ final class PackageToolTests: XCTestCase {
731731
// Try to pin bar at a revision.
732732
do {
733733
try execute("resolve", "bar", "--revision", yoloRevision.identifier)
734-
let pinsStore = try PinsStore(pinsFile: pinsFile, fileSystem: localFileSystem, mirrors: .init())
734+
let pinsStore = try PinsStore(pinsFile: pinsFile, workingDirectory: prefix, fileSystem: localFileSystem, mirrors: .init())
735735
let state = CheckoutState.revision(yoloRevision)
736736
let identity = PackageIdentity(path: barPath)
737737
XCTAssertEqual(pinsStore.pinsMap[identity]?.state, state)
@@ -772,7 +772,7 @@ final class PackageToolTests: XCTestCase {
772772

773773
// Test pins file.
774774
do {
775-
let pinsStore = try PinsStore(pinsFile: pinsFile, fileSystem: localFileSystem, mirrors: .init())
775+
let pinsStore = try PinsStore(pinsFile: pinsFile, workingDirectory: prefix, fileSystem: localFileSystem, mirrors: .init())
776776
XCTAssertEqual(pinsStore.pins.map{$0}.count, 2)
777777
for pkg in ["bar", "baz"] {
778778
let path = try SwiftPMProduct.packagePath(for: pkg, packageRoot: fooPath)
@@ -791,7 +791,7 @@ final class PackageToolTests: XCTestCase {
791791
// Try to pin bar.
792792
do {
793793
try execute("resolve", "bar")
794-
let pinsStore = try PinsStore(pinsFile: pinsFile, fileSystem: localFileSystem, mirrors: .init())
794+
let pinsStore = try PinsStore(pinsFile: pinsFile, workingDirectory: prefix, fileSystem: localFileSystem, mirrors: .init())
795795
let identity = PackageIdentity(path: barPath)
796796
XCTAssertEqual(pinsStore.pinsMap[identity]?.state.version, "1.2.3")
797797
}
@@ -815,7 +815,7 @@ final class PackageToolTests: XCTestCase {
815815
// We should be able to revert to a older version.
816816
do {
817817
try execute("resolve", "bar", "--version", "1.2.3")
818-
let pinsStore = try PinsStore(pinsFile: pinsFile, fileSystem: localFileSystem, mirrors: .init())
818+
let pinsStore = try PinsStore(pinsFile: pinsFile, workingDirectory: prefix, fileSystem: localFileSystem, mirrors: .init())
819819
let identity = PackageIdentity(path: barPath)
820820
XCTAssertEqual(pinsStore.pinsMap[identity]?.state.version, "1.2.3")
821821
try checkBar(5)
@@ -980,7 +980,7 @@ final class PackageToolTests: XCTestCase {
980980
}
981981
}
982982
}
983-
983+
984984
func testPackageLoadingCommandPathResilience() throws {
985985
#if os(macOS)
986986
fixture(name: "ValidLayouts/SingleModule") { prefix in
@@ -998,13 +998,13 @@ final class PackageToolTests: XCTestCase {
998998
})
999999
try localFileSystem.chmod(.executable, path: fakeCmdPath)
10001000
}
1001-
1001+
10021002
// Invoke `swift-package`, passing in the overriding `PATH` environment variable.
10031003
let packageRoot = prefix.appending(component: "Library")
10041004
let patchedPATH = fakeBinDir.pathString + ":" + ProcessInfo.processInfo.environment["PATH"]!
10051005
let result = try SwiftPMProduct.SwiftPackage.executeProcess(["dump-package"], packagePath: packageRoot, env: ["PATH": patchedPATH])
10061006
let textOutput = try result.utf8Output() + result.utf8stderrOutput()
1007-
1007+
10081008
// Check that the wrong tools weren't invoked. We can't just check the exit code because of fallbacks.
10091009
XCTAssertNoMatch(textOutput, .contains("wrong xcrun invoked"))
10101010
XCTAssertNoMatch(textOutput, .contains("wrong sandbox-exec invoked"))

Tests/PackageGraphTests/PackageGraphTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ class PackageGraphTests: XCTestCase {
601601
result.check(diagnostic: "product 'Foo' is declared in the same package 'foo' and can't be used as a dependency for target 'FooTests'.", behavior: .error, location: "'Foo' /Foo")
602602
}
603603
}
604-
604+
605605
func testExecutableTargetDependency() throws {
606606
let fs = InMemoryFileSystem(emptyFiles:
607607
"/XYZ/Sources/XYZ/main.swift",
@@ -624,7 +624,7 @@ class PackageGraphTests: XCTestCase {
624624
)
625625
DiagnosticsEngineTester(diagnostics) { _ in }
626626
}
627-
627+
628628
func testSameProductAndTargetNames() throws {
629629
let fs = InMemoryFileSystem(emptyFiles:
630630
"/Foo/Sources/Foo/src.swift",
@@ -1308,9 +1308,9 @@ class PackageGraphTests: XCTestCase {
13081308
"""
13091309

13101310
let fs = InMemoryFileSystem(files: ["/pins": ByteString(encodingAsUTF8: json)])
1311-
1311+
13121312
XCTAssertThrows(StringError("Package.resolved file is corrupted or malformed; fix or delete the file to continue: duplicated entry for package \"Yams\""), {
1313-
_ = try PinsStore(pinsFile: AbsolutePath("/pins"), fileSystem: fs, mirrors: .init())
1313+
_ = try PinsStore(pinsFile: AbsolutePath("/pins"), workingDirectory: .root, fileSystem: fs, mirrors: .init())
13141314
})
13151315
}
13161316

0 commit comments

Comments
 (0)