Skip to content

Commit 812fa45

Browse files
authored
Expose computeTestTargetsForExecutableTargets via SPI (#7455)
Bringing back `computeTestTargetsForExecutableTargets` on `ModulesGraph` via `@_spi(SwiftPMInternal)`.
1 parent 73769de commit 812fa45

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

Sources/PackageGraph/ModulesGraph.swift

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -23,13 +23,31 @@ enum PackageGraphError: Swift.Error {
2323
case cycleDetected((path: [Manifest], cycle: [Manifest]))
2424

2525
/// The product dependency not found.
26-
case productDependencyNotFound(package: String, targetName: String, dependencyProductName: String, dependencyPackageName: String?, dependencyProductInDecl: Bool, similarProductName: String?, packageContainingSimilarProduct: String?)
26+
case productDependencyNotFound(
27+
package: String,
28+
targetName: String,
29+
dependencyProductName: String,
30+
dependencyPackageName: String?,
31+
dependencyProductInDecl: Bool,
32+
similarProductName: String?,
33+
packageContainingSimilarProduct: String?
34+
)
2735

2836
/// The package dependency already satisfied by a different dependency package
29-
case dependencyAlreadySatisfiedByIdentifier(package: String, dependencyLocation: String, otherDependencyURL: String, identity: PackageIdentity)
37+
case dependencyAlreadySatisfiedByIdentifier(
38+
package: String,
39+
dependencyLocation: String,
40+
otherDependencyURL: String,
41+
identity: PackageIdentity
42+
)
3043

3144
/// The package dependency already satisfied by a different dependency package
32-
case dependencyAlreadySatisfiedByName(package: String, dependencyLocation: String, otherDependencyURL: String, name: String)
45+
case dependencyAlreadySatisfiedByName(
46+
package: String,
47+
dependencyLocation: String,
48+
otherDependencyURL: String,
49+
name: String
50+
)
3351

3452
/// The product dependency was found but the package name was not referenced correctly (tools version > 5.2).
3553
case productDependencyMissingPackage(
@@ -38,15 +56,23 @@ enum PackageGraphError: Swift.Error {
3856
packageIdentifier: String
3957
)
4058
/// Dependency between a plugin and a dependent target/product of a given type is unsupported
41-
case unsupportedPluginDependency(targetName: String, dependencyName: String, dependencyType: String, dependencyPackage: String?)
59+
case unsupportedPluginDependency(
60+
targetName: String,
61+
dependencyName: String,
62+
dependencyType: String,
63+
dependencyPackage: String?
64+
)
65+
4266
/// A product was found in multiple packages.
4367
case duplicateProduct(product: String, packages: [Package])
4468

4569
/// Duplicate aliases for a target found in a product.
46-
case multipleModuleAliases(target: String,
47-
product: String,
48-
package: String,
49-
aliases: [String])
70+
case multipleModuleAliases(
71+
target: String,
72+
product: String,
73+
package: String,
74+
aliases: [String]
75+
)
5076
}
5177

5278
@available(*,
@@ -187,7 +213,8 @@ public struct ModulesGraph {
187213
}
188214

189215
/// Computes a map from each executable target in any of the root packages to the corresponding test targets.
190-
func computeTestTargetsForExecutableTargets() throws -> [ResolvedTarget.ID: [ResolvedTarget]] {
216+
@_spi(SwiftPMInternal)
217+
public func computeTestTargetsForExecutableTargets() throws -> [ResolvedTarget.ID: [ResolvedTarget]] {
191218
var result = [ResolvedTarget.ID: [ResolvedTarget]]()
192219

193220
let rootTargets = IdentifiableSet(rootPackages.flatMap { $0.targets })

Tests/FunctionalTests/PluginTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -11,6 +11,8 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Basics
14+
15+
@_spi(SwiftPMInternal)
1416
@testable import PackageGraph
1517
import PackageLoading
1618
import PackageModel
@@ -19,8 +21,7 @@ import SPMTestSupport
1921
import Workspace
2022
import XCTest
2123

22-
class PluginTests: XCTestCase {
23-
24+
final class PluginTests: XCTestCase {
2425
func testUseOfBuildToolPluginTargetByExecutableInSamePackage() throws {
2526
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
2627
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

0 commit comments

Comments
 (0)