Skip to content

Commit c1519f2

Browse files
committed
Install Swift Build resource bundles in /usr/share/pm
1 parent 1523ce0 commit c1519f2

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

Sources/CoreCommands/BuildSystemSupport.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ private struct SwiftBuildSystemFactory: BuildSystemFactory {
120120
explicitProduct: explicitProduct
121121
)
122122
},
123+
packageManagerResourcesDirectory: swiftCommandState.packageManagerResourcesDirectory,
123124
outputStream: outputStream ?? self.swiftCommandState.outputStream,
124125
logLevel: logLevel ?? self.swiftCommandState.logLevel,
125126
fileSystem: self.swiftCommandState.fileSystem,

Sources/CoreCommands/Options.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ public struct LocationOptions: ParsableArguments {
146146
completion: .directory
147147
)
148148
public var pkgConfigDirectories: [AbsolutePath] = []
149+
150+
@Option(
151+
help: .init("Specify alternate path to search for SwiftPM resources.", visibility: .hidden),
152+
completion: .directory
153+
)
154+
public var packageManagerResourcesDirectory: AbsolutePath?
149155

150156
@Flag(name: .customLong("ignore-lock"), help: .hidden)
151157
public var ignoreLock: Bool = false

Sources/CoreCommands/SwiftCommandState.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ public final class SwiftCommandState {
227227

228228
/// Path to the shared configuration directory
229229
public let sharedConfigurationDirectory: AbsolutePath
230+
231+
/// Path to the package manager's own resources directory.
232+
public let packageManagerResourcesDirectory: AbsolutePath?
230233

231234
/// Path to the cross-compilation Swift SDKs directory.
232235
public let sharedSwiftSDKsDirectory: AbsolutePath
@@ -371,6 +374,17 @@ public final class SwiftCommandState {
371374
warning: "`--experimental-swift-sdks-path` is deprecated and will be removed in a future version of SwiftPM. Use `--swift-sdks-path` instead."
372375
)
373376
}
377+
378+
if let packageManagerResourcesDirectory = options.locations.packageManagerResourcesDirectory {
379+
self.packageManagerResourcesDirectory = packageManagerResourcesDirectory
380+
} else if let cwd = localFileSystem.currentWorkingDirectory {
381+
self.packageManagerResourcesDirectory = try? AbsolutePath(validating: CommandLine.arguments[0], relativeTo: cwd)
382+
.parentDirectory.parentDirectory.appending(components: ["share", "pm"])
383+
} else {
384+
self.packageManagerResourcesDirectory = try? AbsolutePath(validating: CommandLine.arguments[0])
385+
.parentDirectory.parentDirectory.appending(components: ["share", "pm"])
386+
}
387+
374388
self.sharedSwiftSDKsDirectory = try fileSystem.getSharedSwiftSDKsDirectory(
375389
explicitDirectory: options.locations.swiftSDKsDirectory ?? options.locations.deprecatedSwiftSDKsDirectory
376390
)

Sources/SwiftBuildSupport/SwiftBuildSystem.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ struct SessionFailedError: Error {
4646
func withSession(
4747
service: SWBBuildService,
4848
name: String,
49+
packageManagerResourcesDirectory: Basics.AbsolutePath?,
4950
body: @escaping (
5051
_ session: SWBBuildServiceSession,
5152
_ diagnostics: [SwiftBuild.SwiftBuildMessage.DiagnosticInfo]
5253
) async throws -> Void
5354
) async throws {
54-
switch await service.createSession(name: name, cachePath: nil, inferiorProductsPath: nil, environment: nil) {
55+
switch await service.createSession(name: name, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil) {
5556
case (.success(let session), let diagnostics):
5657
do {
5758
try await body(session, diagnostics)
@@ -143,6 +144,7 @@ private final class PlanningOperationDelegate: SWBPlanningOperationDelegate, Sen
143144
public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
144145
private let buildParameters: BuildParameters
145146
private let packageGraphLoader: () async throws -> ModulesGraph
147+
private let packageManagerResourcesDirectory: Basics.AbsolutePath?
146148
private let logLevel: Basics.Diagnostic.Severity
147149
private var packageGraph: AsyncThrowingValueMemoizer<ModulesGraph> = .init()
148150
private var pifBuilder: AsyncThrowingValueMemoizer<PIFBuilder> = .init()
@@ -193,13 +195,15 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
193195
public init(
194196
buildParameters: BuildParameters,
195197
packageGraphLoader: @escaping () async throws -> ModulesGraph,
198+
packageManagerResourcesDirectory: Basics.AbsolutePath?,
196199
outputStream: OutputByteStream,
197200
logLevel: Basics.Diagnostic.Severity,
198201
fileSystem: FileSystem,
199202
observabilityScope: ObservabilityScope
200203
) throws {
201204
self.buildParameters = buildParameters
202205
self.packageGraphLoader = packageGraphLoader
206+
self.packageManagerResourcesDirectory = packageManagerResourcesDirectory
203207
self.outputStream = outputStream
204208
self.logLevel = logLevel
205209
self.fileSystem = fileSystem
@@ -241,7 +245,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
241245
)
242246

243247
do {
244-
try await withSession(service: service, name: buildParameters.pifManifest.pathString) { session, _ in
248+
try await withSession(service: service, name: buildParameters.pifManifest.pathString, packageManagerResourcesDirectory: packageManagerResourcesDirectory) { session, _ in
245249
// Load the workspace, and set the system information to the default
246250
do {
247251
try await session.loadWorkspace(containerPath: self.buildParameters.pifManifest.pathString)

Sources/swift-bootstrap/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ struct SwiftBootstrapBuildTool: AsyncParsableCommand {
362362
return try SwiftBuildSystem(
363363
buildParameters: buildParameters,
364364
packageGraphLoader: asyncUnsafePackageGraphLoader,
365+
packageManagerResourcesDirectory: nil,
365366
outputStream: TSCBasic.stdoutStream,
366367
logLevel: logLevel,
367368
fileSystem: self.fileSystem,

Utilities/bootstrap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ def install_swiftpm(prefix, args):
518518
dest = os.path.join(prefix, "lib", "swift", "pm", "PluginAPI")
519519
install_dylib(args, "PackagePlugin", dest, ["PackagePlugin"])
520520

521+
# Install resource bundles produced during the build.
522+
for file in os.listdir(args.bin_dir):
523+
if file.endswith('.bundle') or file.endswith('.resources'):
524+
install_binary(args, file, os.path.join(os.path.join(prefix, "share"), "pm"))
525+
521526

522527
# Helper function that installs a dynamic library and a set of modules to a particular directory.
523528
def install_dylib(args, library_name, install_dir, module_names):

0 commit comments

Comments
 (0)