Skip to content

Add macros to 5.9 tools-version #6472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/CompilerPluginSupport/TargetExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@_spi(PackageDescriptionInternal) import PackageDescription

public extension Target {
@available(_PackageDescription, introduced: 999.0)
@available(_PackageDescription, introduced: 5.9)
static func macro(
name: String,
dependencies: [Dependency] = [],
Expand Down
3 changes: 1 addition & 2 deletions Sources/Workspace/InitPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ public final class InitPackage {
// Create a tools version with current version but with patch set to zero.
// We do this to avoid adding unnecessary constraints to patch versions, if
// the package really needs it, they should add it manually.
let version = packageType == .macro ? ToolsVersion.vNext
: InitPackage.newPackageToolsVersion.zeroedPatch
let version = InitPackage.newPackageToolsVersion.zeroedPatch

// Write the current tools version.
try ToolsVersionSpecificationWriter.rewriteSpecification(
Expand Down
40 changes: 40 additions & 0 deletions Tests/PackageLoadingTests/PD_5_9_LoadingTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Basics
import PackageLoading
import PackageModel
import SPMTestSupport
import XCTest

class PackageDescription5_9LoadingTests: PackageDescriptionLoadingTests {
override var toolsVersion: ToolsVersion {
.v5_9
}

func testMacroTargets() throws {
let content = """
import CompilerPluginSupport
import PackageDescription

let package = Package(name: "MyPackage",
targets: [
.macro(name: "MyMacro", swiftSettings: [.define("BEST")], linkerSettings: [.linkedLibrary("best")]),
]
)
"""

let observability = ObservabilitySystem.makeForTesting()
let (_, diagnostics) = try loadAndValidateManifest(content, observabilityScope: observability.topScope)
XCTAssertEqual(diagnostics.count, 0, "unexpected diagnostics: \(diagnostics)")
}
}
17 changes: 0 additions & 17 deletions Tests/PackageLoadingTests/PD_Next_LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,4 @@ class PackageDescriptionNextLoadingTests: PackageDescriptionLoadingTests {
}
}
}

func testMacroTargets() throws {
let content = """
import CompilerPluginSupport
import PackageDescription

let package = Package(name: "MyPackage",
targets: [
.macro(name: "MyMacro", swiftSettings: [.define("BEST")], linkerSettings: [.linkedLibrary("best")]),
]
)
"""

let observability = ObservabilitySystem.makeForTesting()
let (_, diagnostics) = try loadAndValidateManifest(content, observabilityScope: observability.topScope)
XCTAssertEqual(diagnostics.count, 0, "unexpected diagnostics: \(diagnostics)")
}
}