From 1e0d950b8e5edfbdcbd3728cce5e56af70a2fd30 Mon Sep 17 00:00:00 2001 From: Anders Bertelrud Date: Mon, 27 Mar 2023 16:08:54 -0700 Subject: [PATCH] Add product types for the created build tool plugin and command plugin packages Most often these plugins are vended to other packages using products, so it makes sense to include this from the start. --- Sources/Workspace/InitPackage.swift | 9 +++++++++ Tests/WorkspaceTests/InitTests.swift | 2 ++ 2 files changed, 11 insertions(+) diff --git a/Sources/Workspace/InitPackage.swift b/Sources/Workspace/InitPackage.swift index 2786b9b6a98..313b8869324 100644 --- a/Sources/Workspace/InitPackage.swift +++ b/Sources/Workspace/InitPackage.swift @@ -216,6 +216,15 @@ public final class InitPackage { targets: ["\(pkgname)"]), ] """) + } else if packageType == .buildToolPlugin || packageType == .commandPlugin { + pkgParams.append(""" + products: [ + // Products define the executables and libraries a package produces, making them visible to other packages. + .plugin( + name: "\(pkgname)", + targets: ["\(pkgname)"]), + ] + """) } else if packageType == .macro { pkgParams.append(""" products: [ diff --git a/Tests/WorkspaceTests/InitTests.swift b/Tests/WorkspaceTests/InitTests.swift index 38a445f5594..d462bbf7961 100644 --- a/Tests/WorkspaceTests/InitTests.swift +++ b/Tests/WorkspaceTests/InitTests.swift @@ -168,6 +168,7 @@ class InitTests: XCTestCase { let manifest = path.appending("Package.swift") XCTAssertFileExists(manifest) let manifestContents: String = try localFileSystem.readFileContents(manifest) + XCTAssertMatch(manifestContents, .and(.contains(".plugin("), .contains("targets: [\"MyCommandPlugin\"]"))) XCTAssertMatch(manifestContents, .and(.contains(".plugin("), .contains("capability: .command(intent: .custom(verb"))) let source = path.appending("Plugins", "MyCommandPlugin", "plugin.swift") @@ -196,6 +197,7 @@ class InitTests: XCTestCase { let manifest = path.appending("Package.swift") XCTAssertFileExists(manifest) let manifestContents: String = try localFileSystem.readFileContents(manifest) + XCTAssertMatch(manifestContents, .and(.contains(".plugin("), .contains("targets: [\"MyBuildToolPlugin\"]"))) XCTAssertMatch(manifestContents, .and(.contains(".plugin("), .contains("capability: .buildTool()"))) let source = path.appending("Plugins", "MyBuildToolPlugin", "plugin.swift")