Skip to content

Commit 9b9bed7

Browse files
authored
Improve diagnostic when automatic resolution is disabled (#3638)
- Show the exact path where we looked for a resolved file - Special case if there wasn't a file to begin with rdar://81172549
1 parent 579cc14 commit 9b9bed7

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,11 @@ extension Workspace {
18571857
)
18581858

18591859
if precomputationResult.isRequired {
1860-
diagnostics.emit(error: "cannot update Package.resolved file because automatic resolution is disabled")
1860+
if !fileSystem.exists(resolvedFile) {
1861+
diagnostics.emit(error: "a resolved file is required when automatic dependency resolution is disabled and should be placed at \(resolvedFile.pathString)")
1862+
} else {
1863+
diagnostics.emit(error: "an out-of-date resolved file was detected at \(resolvedFile.pathString), which is not allowed when automatic dependency resolution is disabled; please make sure to update the file to reflect the changes in dependencies")
1864+
}
18611865
}
18621866

18631867
try self.updateBinaryArtifacts(manifests: currentManifests, addedOrUpdatedPackages: [], diagnostics: diagnostics)

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3690,7 +3690,7 @@ final class WorkspaceTests: XCTestCase {
36903690
// Check force resolve. This should produce an error because the resolved file is out-of-date.
36913691
workspace.checkPackageGraphFailure(roots: ["Root"], forceResolvedVersions: true) { diagnostics in
36923692
DiagnosticsEngineTester(diagnostics) { result in
3693-
result.check(diagnostic: "cannot update Package.resolved file because automatic resolution is disabled", checkContains: true, behavior: .error)
3693+
result.check(diagnostic: "an out-of-date resolved file was detected at /tmp/ws/Package.resolved, which is not allowed when automatic dependency resolution is disabled; please make sure to update the file to reflect the changes in dependencies", checkContains: true, behavior: .error)
36943694
}
36953695
}
36963696
workspace.checkManagedDependencies { result in
@@ -3729,6 +3729,57 @@ final class WorkspaceTests: XCTestCase {
37293729
}
37303730
}
37313731

3732+
func testForceResolveWithNoResolvedFile() throws {
3733+
let sandbox = AbsolutePath("/tmp/ws/")
3734+
let fs = InMemoryFileSystem()
3735+
3736+
let workspace = try MockWorkspace(
3737+
sandbox: sandbox,
3738+
fs: fs,
3739+
roots: [
3740+
MockPackage(
3741+
name: "Root",
3742+
targets: [
3743+
MockTarget(name: "Root", dependencies: ["Foo", "Bar"]),
3744+
],
3745+
products: [],
3746+
dependencies: [
3747+
.git(name: "Foo", requirement: .upToNextMajor(from: "1.0.0")),
3748+
.git(name: "Bar", requirement: .upToNextMajor(from: "1.0.0")),
3749+
]
3750+
),
3751+
],
3752+
packages: [
3753+
MockPackage(
3754+
name: "Foo",
3755+
targets: [
3756+
MockTarget(name: "Foo"),
3757+
],
3758+
products: [
3759+
MockProduct(name: "Foo", targets: ["Foo"]),
3760+
],
3761+
versions: ["1.0.0", "1.2.0", "1.3.2"]
3762+
),
3763+
MockPackage(
3764+
name: "Bar",
3765+
targets: [
3766+
MockTarget(name: "Bar"),
3767+
],
3768+
products: [
3769+
MockProduct(name: "Bar", targets: ["Bar"]),
3770+
],
3771+
versions: ["1.0.0", "develop"]
3772+
),
3773+
]
3774+
)
3775+
3776+
workspace.checkPackageGraphFailure(roots: ["Root"], forceResolvedVersions: true) { diagnostics in
3777+
DiagnosticsEngineTester(diagnostics) { result in
3778+
result.check(diagnostic: "a resolved file is required when automatic dependency resolution is disabled and should be placed at /tmp/ws/Package.resolved", checkContains: true, behavior: .error)
3779+
}
3780+
}
3781+
}
3782+
37323783
func testForceResolveToResolvedVersionsLocalPackage() throws {
37333784
let sandbox = AbsolutePath("/tmp/ws/")
37343785
let fs = InMemoryFileSystem()

0 commit comments

Comments
 (0)