Skip to content

Commit 4291885

Browse files
committed
[Workspace] Add deprecation warning for v3 manifests
<rdar://problem/41792011> Emit deprecation notice if there is a v3 manifest in a package graph Emits a deprecation warning if there are v3 manifests in a package graph.
1 parent 684b24d commit 4291885

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

Sources/Workspace/Diagnostics.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,18 @@ public enum WorkspaceDiagnostics {
343343
self.duration = duration
344344
}
345345
}
346+
347+
public struct PD3DeprecatedDiagnostic: DiagnosticData {
348+
public static let id = DiagnosticID(
349+
type: PD3DeprecatedDiagnostic.self,
350+
name: "org.swift.diags.workspace.\(PD3DeprecatedDiagnostic.self)",
351+
defaultBehavior: .warning,
352+
description: {
353+
$0 <<< "PackageDescription API v3 is deprecated and will be removed in the future;"
354+
$0 <<< "used by package(s):" <<< { $0.manifests.joined(separator: ", ") }
355+
}
356+
)
357+
358+
let manifests: [String]
359+
}
346360
}

Sources/Workspace/Workspace.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,20 @@ extension Workspace {
543543

544544
// Perform dependency resolution, if required.
545545
let manifests = self._resolve(root: root, diagnostics: diagnostics)
546+
let externalManifests = manifests.allManifests()
547+
548+
// Emit deprecation warning for v3 manifests.
549+
let v3Manifests = (manifests.root.manifests + externalManifests).filter({ $0.manifestVersion == .v3 })
550+
if !v3Manifests.isEmpty {
551+
let warning = WorkspaceDiagnostics.PD3DeprecatedDiagnostic(
552+
manifests: v3Manifests.map({ $0.name }))
553+
diagnostics.emit(data: warning)
554+
}
546555

547556
// Load the graph.
548557
return PackageGraphLoader().load(
549558
root: manifests.root,
550-
externalManifests: manifests.allManifests(),
559+
externalManifests: externalManifests,
551560
diagnostics: diagnostics,
552561
fileSystem: fileSystem,
553562
shouldCreateMultipleTestProducts: createMultipleTestProducts

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ final class PackageToolTests: XCTestCase {
8383

8484
func testDescribe() throws {
8585
fixture(name: "CFamilyTargets/SwiftCMixed") { prefix in
86-
let output = try execute(["describe", "--type=json"], packagePath: prefix)
86+
let result = try SwiftPMProduct.SwiftPackage.executeProcess(["describe", "--type=json"], packagePath: prefix)
87+
let output = try result.utf8Output()
8788
let json = try JSON(bytes: ByteString(encodingAsUTF8: output))
8889

8990
XCTAssertEqual(json["name"]?.string, "SwiftCMixed")
@@ -126,19 +127,17 @@ final class PackageToolTests: XCTestCase {
126127
func testShowDependencies() throws {
127128
fixture(name: "DependencyResolution/External/Complex") { prefix in
128129
let packageRoot = prefix.appending(component: "app")
129-
let textOutput = try execute(["show-dependencies", "--format=text"], packagePath: packageRoot)
130+
let textOutput = try SwiftPMProduct.SwiftPackage.executeProcess(["show-dependencies", "--format=text"], packagePath: packageRoot).utf8Output()
130131
XCTAssert(textOutput.contains("[email protected]"))
131132

132-
// FIXME: We have to fetch first otherwise the fetching output is mingled with the JSON data.
133-
let jsonOutput = try execute(["show-dependencies", "--format=json"], packagePath: packageRoot)
134-
print("output = \(jsonOutput)")
133+
let jsonOutput = try SwiftPMProduct.SwiftPackage.executeProcess(["show-dependencies", "--format=json"], packagePath: packageRoot).utf8Output()
135134
let json = try JSON(bytes: ByteString(encodingAsUTF8: jsonOutput))
136135
guard case let .dictionary(contents) = json else { XCTFail("unexpected result"); return }
137136
guard case let .string(name)? = contents["name"] else { XCTFail("unexpected result"); return }
138137
XCTAssertEqual(name, "Dealer")
139138
guard case let .string(path)? = contents["path"] else { XCTFail("unexpected result"); return }
140139
XCTAssertEqual(resolveSymlinks(AbsolutePath(path)), resolveSymlinks(packageRoot))
141-
}
140+
}
142141
}
143142

144143
func testInitEmpty() throws {

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class MiscellaneousTestCase: XCTestCase {
3434
let output = try executeSwiftBuild(prefix.appending(component: "Bar"))
3535
XCTAssertTrue(output.contains("Resolving"))
3636
XCTAssertTrue(output.contains("at 1.2.3"))
37+
XCTAssertTrue(output.contains("warning: PackageDescription API v3 is deprecated and will be removed in the future; used by package(s): Bar, Foo"))
3738
}
3839
}
3940

0 commit comments

Comments
 (0)