Skip to content

Commit 6ff5cbd

Browse files
authored
Rename PackageGraph type to ModulesGraph (#7363)
We have to operate on two different graphs in the `PackageGraph` module: 1. A graph of packages in PubGrub package resolution code; 2. A graph of resolved products and modules that belong to those products. Currently the second graph is misleadingly called `PackageGraph`, although that name is much more suitable for the first graph. This naming is confusing and unfortunate, and can be especially misleading for first-time contributors. We should better document the SwiftPM resolution and build pipeline in the future, but cleaning up naming is the first step. I'm keeping old names as deprecated overloads or typealiases to make migration easier for SwiftPM clients. This renaming has no impact on any public stable modules like `PackageDescription`. In the short term we should also split the `PackageGraph` module into `PubGrub` and `ModulesGraph` modules, but for now I'm renaming a single type to keep the PR manageable.
1 parent d7878b0 commit 6ff5cbd

33 files changed

+288
-244
lines changed

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Basics
1414
import PackageLoading
1515
import PackageModel
16-
import struct PackageGraph.PackageGraph
16+
import struct PackageGraph.ModulesGraph
1717
import struct PackageGraph.ResolvedTarget
1818
import struct SPMBuildCore.BuildParameters
1919
import struct SPMBuildCore.BuildToolPluginInvocationResult
@@ -134,7 +134,7 @@ public final class ClangTargetBuildDescription {
134134
if toolsVersion >= .v5_9 {
135135
self.buildToolPluginInvocationResults = buildToolPluginInvocationResults
136136

137-
(self.pluginDerivedSources, self.pluginDerivedResources) = PackageGraph.computePluginGeneratedFiles(
137+
(self.pluginDerivedSources, self.pluginDerivedResources) = ModulesGraph.computePluginGeneratedFiles(
138138
target: target,
139139
toolsVersion: toolsVersion,
140140
additionalFileRules: additionalFileRules,

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public final class SwiftTargetBuildDescription {
287287
self.fileSystem = fileSystem
288288
self.observabilityScope = observabilityScope
289289

290-
(self.pluginDerivedSources, self.pluginDerivedResources) = PackageGraph.computePluginGeneratedFiles(
290+
(self.pluginDerivedSources, self.pluginDerivedResources) = ModulesGraph.computePluginGeneratedFiles(
291291
target: target,
292292
toolsVersion: toolsVersion,
293293
additionalFileRules: additionalFileRules,

Sources/Build/BuildOperation.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
4747
let toolsBuildParameters: BuildParameters
4848

4949
/// The closure for loading the package graph.
50-
let packageGraphLoader: () throws -> PackageGraph
50+
let packageGraphLoader: () throws -> ModulesGraph
5151

5252
/// the plugin configuration for build plugins
5353
let pluginConfiguration: PluginConfiguration?
@@ -78,7 +78,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
7878
private let buildDescription = ThreadSafeBox<BuildDescription>()
7979

8080
/// The loaded package graph.
81-
private let packageGraph = ThreadSafeBox<PackageGraph>()
81+
private let packageGraph = ThreadSafeBox<ModulesGraph>()
8282

8383
/// The output stream for the build delegate.
8484
private let outputStream: OutputByteStream
@@ -112,7 +112,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
112112
productsBuildParameters: BuildParameters,
113113
toolsBuildParameters: BuildParameters,
114114
cacheBuildManifest: Bool,
115-
packageGraphLoader: @escaping () throws -> PackageGraph,
115+
packageGraphLoader: @escaping () throws -> ModulesGraph,
116116
pluginConfiguration: PluginConfiguration? = .none,
117117
additionalFileRules: [FileRuleDescription],
118118
pkgConfigDirectories: [AbsolutePath],
@@ -145,7 +145,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
145145
self.observabilityScope = observabilityScope.makeChildScope(description: "Build Operation")
146146
}
147147

148-
public func getPackageGraph() throws -> PackageGraph {
148+
public func getPackageGraph() throws -> ModulesGraph {
149149
try self.packageGraph.memoize {
150150
try self.packageGraphLoader()
151151
}
@@ -877,7 +877,7 @@ extension BuildDescription {
877877
}
878878

879879
extension BuildSubset {
880-
func recursiveDependencies(for graph: PackageGraph, observabilityScope: ObservabilityScope) throws -> [ResolvedTarget]? {
880+
func recursiveDependencies(for graph: ModulesGraph, observabilityScope: ObservabilityScope) throws -> [ResolvedTarget]? {
881881
switch self {
882882
case .allIncludingTests:
883883
return Array(graph.reachableTargets)
@@ -899,7 +899,7 @@ extension BuildSubset {
899899
}
900900

901901
/// Returns the name of the llbuild target that corresponds to the build subset.
902-
func llbuildTargetName(for graph: PackageGraph, config: String, observabilityScope: ObservabilityScope)
902+
func llbuildTargetName(for graph: ModulesGraph, config: String, observabilityScope: ObservabilityScope)
903903
-> String?
904904
{
905905
switch self {

Sources/Build/BuildPlan/BuildPlan+Test.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import struct Basics.InternalError
1515
import struct Basics.AbsolutePath
1616
import struct LLBuildManifest.TestDiscoveryTool
1717
import struct LLBuildManifest.TestEntryPointTool
18-
import struct PackageGraph.PackageGraph
18+
import struct PackageGraph.ModulesGraph
1919
import struct PackageGraph.ResolvedProduct
2020
import struct PackageGraph.ResolvedTarget
2121
import struct PackageModel.Sources
@@ -27,7 +27,7 @@ import protocol TSCBasic.FileSystem
2727
extension BuildPlan {
2828
static func makeDerivedTestTargets(
2929
_ buildParameters: BuildParameters,
30-
_ graph: PackageGraph,
30+
_ graph: ModulesGraph,
3131
_ disableSandbox: Bool,
3232
_ fileSystem: FileSystem,
3333
_ observabilityScope: ObservabilityScope

Sources/Build/BuildPlan/BuildPlan.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
196196
}
197197

198198
/// The package graph.
199-
public let graph: PackageGraph
199+
public let graph: ModulesGraph
200200

201201
/// The target build description map.
202202
public let targetMap: [ResolvedTarget.ID: TargetBuildDescription]
@@ -249,7 +249,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
249249
@available(*, deprecated, renamed: "init(productsBuildParameters:toolsBuildParameters:graph:)")
250250
public convenience init(
251251
buildParameters: BuildParameters,
252-
graph: PackageGraph,
252+
graph: ModulesGraph,
253253
additionalFileRules: [FileRuleDescription] = [],
254254
buildToolPluginInvocationResults: [ResolvedTarget.ID: [BuildToolPluginInvocationResult]] = [:],
255255
prebuildCommandResults: [ResolvedTarget.ID: [PrebuildCommandResult]] = [:],
@@ -272,7 +272,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
272272
public init(
273273
productsBuildParameters: BuildParameters,
274274
toolsBuildParameters: BuildParameters,
275-
graph: PackageGraph,
275+
graph: ModulesGraph,
276276
additionalFileRules: [FileRuleDescription] = [],
277277
buildToolPluginInvocationResults: [ResolvedTarget.ID: [BuildToolPluginInvocationResult]] = [:],
278278
prebuildCommandResults: [ResolvedTarget.ID: [PrebuildCommandResult]] = [:],

Sources/Commands/PackageTools/APIDiff.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ struct APIDiff: SwiftCommand {
160160
}
161161
}
162162

163-
private func determineModulesToDiff(packageGraph: PackageGraph, observabilityScope: ObservabilityScope) throws -> Set<String> {
163+
private func determineModulesToDiff(packageGraph: ModulesGraph, observabilityScope: ObservabilityScope) throws -> Set<String> {
164164
var modulesToDiff: Set<String> = []
165165
if products.isEmpty && targets.isEmpty {
166166
modulesToDiff.formUnion(packageGraph.apiDigesterModules)

Sources/Commands/PackageTools/PluginCommand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ struct PluginCommand: SwiftCommand {
211211
static func run(
212212
plugin: PluginTarget,
213213
package: ResolvedPackage,
214-
packageGraph: PackageGraph,
214+
packageGraph: ModulesGraph,
215215
options: PluginOptions,
216216
arguments: [String],
217217
swiftTool: SwiftTool
@@ -369,7 +369,7 @@ struct PluginCommand: SwiftCommand {
369369
// TODO: We should also emit a final line of output regarding the result.
370370
}
371371

372-
static func availableCommandPlugins(in graph: PackageGraph, limitedTo packageIdentity: String?) -> [PluginTarget] {
372+
static func availableCommandPlugins(in graph: ModulesGraph, limitedTo packageIdentity: String?) -> [PluginTarget] {
373373
// All targets from plugin products of direct dependencies are "available".
374374
let directDependencyPackages = graph.rootPackages.flatMap { $0.dependencies }.filter { $0.matching(identity: packageIdentity) }
375375
let directDependencyPluginTargets = directDependencyPackages.flatMap { $0.products.filter { $0.type == .plugin } }.flatMap { $0.targets }
@@ -383,7 +383,7 @@ struct PluginCommand: SwiftCommand {
383383
}
384384
}
385385

386-
static func findPlugins(matching verb: String, in graph: PackageGraph, limitedTo packageIdentity: String?) -> [PluginTarget] {
386+
static func findPlugins(matching verb: String, in graph: ModulesGraph, limitedTo packageIdentity: String?) -> [PluginTarget] {
387387
// Find and return the command plugins that match the command.
388388
Self.availableCommandPlugins(in: graph, limitedTo: packageIdentity).filter {
389389
// Filter out any non-command plugins and any whose verb is different.

Sources/Commands/SwiftRunTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public struct SwiftRunTool: SwiftCommand {
216216
}
217217

218218
/// Returns the path to the correct executable based on options.
219-
private func findProductName(in graph: PackageGraph) throws -> String {
219+
private func findProductName(in graph: ModulesGraph) throws -> String {
220220
if let executable = options.executable {
221221
let executableExists = graph.allProducts.contains { ($0.type == .executable || $0.type == .snippet) && $0.name == executable }
222222
guard executableExists else {

Sources/Commands/Utilities/APIDigester.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ extension BuildParameters {
310310
}
311311
}
312312

313-
extension PackageGraph {
313+
extension ModulesGraph {
314314
/// The list of modules that should be used as an input to the API digester.
315315
var apiDigesterModules: [String] {
316316
self.rootPackages

Sources/CoreCommands/BuildSystemSupport.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import XCBuildSupport
1818
#endif
1919

2020
import class Basics.ObservabilityScope
21-
import struct PackageGraph.PackageGraph
21+
import struct PackageGraph.ModulesGraph
2222
import struct PackageLoading.FileRuleDescription
2323
import protocol TSCBasic.OutputByteStream
2424

@@ -30,7 +30,7 @@ private struct NativeBuildSystemFactory: BuildSystemFactory {
3030
cacheBuildManifest: Bool,
3131
productsBuildParameters: BuildParameters?,
3232
toolsBuildParameters: BuildParameters?,
33-
packageGraphLoader: (() throws -> PackageGraph)?,
33+
packageGraphLoader: (() throws -> ModulesGraph)?,
3434
outputStream: OutputByteStream?,
3535
logLevel: Diagnostic.Severity?,
3636
observabilityScope: ObservabilityScope?
@@ -72,7 +72,7 @@ private struct XcodeBuildSystemFactory: BuildSystemFactory {
7272
cacheBuildManifest: Bool,
7373
productsBuildParameters: BuildParameters?,
7474
toolsBuildParameters: BuildParameters?,
75-
packageGraphLoader: (() throws -> PackageGraph)?,
75+
packageGraphLoader: (() throws -> ModulesGraph)?,
7676
outputStream: OutputByteStream?,
7777
logLevel: Diagnostic.Severity?,
7878
observabilityScope: ObservabilityScope?

0 commit comments

Comments
 (0)