Skip to content

Commit

Permalink
Remove the GitStatus plugin.
Browse files Browse the repository at this point in the history
A recent PR on Swift Package Manager (apple/swift-package-manager#7202) added a `gitInformation` property to the package manifest's `Context` global. This property contains exactly the information we need from the GitStatus plugin. Let's remove it, then!

Adopting the `gitInformation` property requires that we drop remaining support for Swift 5.10. We will continue to minimally support it in a separate Package.swift file (where we simply won't have git repo information at build time.) This PR does not strip out other 5.10 support code such as `XCTestScaffold`.

Resolves rdar://121529847.
  • Loading branch information
grynspan committed Jan 24, 2024
1 parent 2171dce commit f2c6e47
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 181 deletions.
32 changes: 15 additions & 17 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 5.10

//
// This source file is part of the Swift.org open source project
Expand Down Expand Up @@ -43,8 +43,8 @@ let package = Package(
"TestingInternals",
"TestingMacros",
],
swiftSettings: .packageSettings,
plugins: ["GitStatusPlugin"]
cxxSettings: .packageSettings,
swiftSettings: .packageSettings
),
.testTarget(
name: "TestingTests",
Expand Down Expand Up @@ -79,20 +79,8 @@ let package = Package(
// "Support" targets: These contain C family code and are used exclusively
// by other targets above, not directly included in product libraries.
.target(
name: "TestingInternals"
),

.plugin(
name: "GitStatusPlugin",
capability: .buildTool,
dependencies: ["GitStatus"]
),
.executableTarget(
name: "GitStatus",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
]
name: "TestingInternals",
cxxSettings: .packageSettings
),

// Cross-module overlays (unsupported)
Expand Down Expand Up @@ -148,3 +136,13 @@ extension Array where Element == PackageDescription.SwiftSetting {
]
}
}

extension Array where Element == PackageDescription.CXXSetting {
/// Settings intended to be applied to every C++ target in this package.
/// Analogous to project-level build settings in an Xcode project.
static var packageSettings: Self {
[
.define("_SWT_TESTING_LIBRARY_VERSION", to: #""unknown (Swift 5.10 toolchain)""#),
]
}
}
160 changes: 160 additions & 0 deletions Package@swift-5.11.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// swift-tools-version: 5.11

//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

import PackageDescription
import CompilerPluginSupport

let package = Package(
name: "swift-testing",

platforms: [
.macOS(.v10_15),
.iOS(.v13),
.watchOS(.v6),
.tvOS(.v13),
.macCatalyst(.v13),
.visionOS(.v1),
],

products: [
.library(
name: "Testing",
targets: ["Testing"]
),
],

dependencies: [
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
],

targets: [
.target(
name: "Testing",
dependencies: [
"TestingInternals",
"TestingMacros",
],
cxxSettings: .packageSettings,
swiftSettings: .packageSettings
),
.testTarget(
name: "TestingTests",
dependencies: [
"Testing",
"_Testing_Foundation",
],
swiftSettings: .packageSettings
),

.macro(
name: "TestingMacros",
dependencies: [
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
swiftSettings: .packageSettings + [
// The only target which needs the ability to import this macro
// implementation target's module is its unit test target. Users of the
// macros this target implements use them via their declarations in the
// Testing module. This target's module is never distributed to users,
// but as an additional guard against accidental misuse, this specifies
// the unit test target as the only allowable client.
.unsafeFlags(["-Xfrontend", "-allowable-client", "-Xfrontend", "TestingMacrosTests"]),
]
),

// "Support" targets: These contain C family code and are used exclusively
// by other targets above, not directly included in product libraries.
.target(
name: "TestingInternals",
cxxSettings: .packageSettings
),

// Cross-module overlays (unsupported)
.target(
name: "_Testing_Foundation",
dependencies: [
"Testing",
],
swiftSettings: .packageSettings
),
],

cxxLanguageStandard: .cxx20
)

// BUG: swift-package-manager-#6367
#if !os(Windows)
package.targets.append(contentsOf: [
.testTarget(
name: "TestingMacrosTests",
dependencies: [
"Testing",
"TestingMacros",
],
swiftSettings: .packageSettings
)
])
#endif

extension Array where Element == PackageDescription.SwiftSetting {
/// Settings intended to be applied to every Swift target in this package.
/// Analogous to project-level build settings in an Xcode project.
static var packageSettings: Self {
[
.unsafeFlags([
"-require-explicit-sendable",

"-Xfrontend", "-define-availability", "-Xfrontend", "_mangledTypeNameAPI:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0",
"-Xfrontend", "-define-availability", "-Xfrontend", "_backtraceAsyncAPI:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0",
"-Xfrontend", "-define-availability", "-Xfrontend", "_clockAPI:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0",
"-Xfrontend", "-define-availability", "-Xfrontend", "_regexAPI:macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0",
"-Xfrontend", "-define-availability", "-Xfrontend", "_swiftVersionAPI:macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0",

"-Xfrontend", "-define-availability", "-Xfrontend", "_distantFuture:macOS 99.0, iOS 99.0, watchOS 99.0, tvOS 99.0",
]),
.enableExperimentalFeature("StrictConcurrency"),
.enableUpcomingFeature("ExistentialAny"),

.enableExperimentalFeature("AccessLevelOnImport"),
.enableUpcomingFeature("InternalImportsByDefault"),

.define("SWT_TARGET_OS_APPLE", .when(platforms: [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS])),
]
}
}

extension Array where Element == PackageDescription.CXXSetting {
/// Settings intended to be applied to every C++ target in this package.
/// Analogous to project-level build settings in an Xcode project.
static var packageSettings: Self {
var result = Self()

// Capture the testing library's version as a C++ string constant.
if let git = Context.gitInformation {
let testingLibraryVersion = if let tag = git.currentTag {
tag
} else if git.hasUncommittedChanges {
"\(git.currentCommit) (modified)"
} else {
git.currentCommit
}
result.append(.define("_SWT_TESTING_LIBRARY_VERSION", to: #""\#(testingLibraryVersion)""#))
}

return result
}
}
33 changes: 0 additions & 33 deletions Plugins/GitStatusPlugin/GitStatusPlugin.swift

This file was deleted.

120 changes: 0 additions & 120 deletions Sources/GitStatus/main.swift

This file was deleted.

12 changes: 1 addition & 11 deletions Sources/Testing/Support/Versions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,8 @@ let simulatorVersion: String = {
/// ``XCTestScaffold`` or an event writer.
///
/// This value is not part of the public interface of the testing library.
///
/// - Bug: Build plugins do not currently run on Windows.
/// ([swift-package-manager-#6851](https://github.com/apple/swift-package-manager/issues/6851))
var testingLibraryVersion: String {
#if os(Windows)
"unknown"
#else
// The variable `_testingLibraryVersion` is generated at compile-time by the
// GitStatus plugin. If the plugin was unable to gather tag or commit
// information from Git, it produces a nil value.
_testingLibraryVersion ?? "unknown"
#endif
SWT_TESTING_LIBRARY_VERSION
}

/// A human-readable string describing the Swift Standard Library's version.
Expand Down

0 comments on commit f2c6e47

Please sign in to comment.