Skip to content

Commit 0193d5f

Browse files
authored
Reapply "Include Swift Build support in second stage bootstrap builds" (swiftlang#8373)
This reverts commit 6a2e45f. - Stop setting SWIFTPM_NO_SWBUILD_DEPENDENCY in the bootstrap script - Copy resource bundles required by Swift Build into the toolchain when installing There is one additional fix to the bootstrap script to allow overwriting directories when installing, to fix the incremental buildbot CI configuration.
1 parent 1122c3c commit 0193d5f

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

Sources/CoreCommands/BuildSystemSupport.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ private struct SwiftBuildSystemFactory: BuildSystemFactory {
121121
explicitProduct: explicitProduct
122122
)
123123
},
124+
packageManagerResourcesDirectory: swiftCommandState.packageManagerResourcesDirectory,
124125
outputStream: outputStream ?? self.swiftCommandState.outputStream,
125126
logLevel: logLevel ?? self.swiftCommandState.logLevel,
126127
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 resources required for SwiftPM to operate. (default: <Toolchain Directory>/usr/share/pm)", 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
@@ -225,6 +225,9 @@ public final class SwiftCommandState {
225225

226226
/// Path to the shared configuration directory
227227
public let sharedConfigurationDirectory: AbsolutePath
228+
229+
/// Path to the package manager's own resources directory.
230+
public let packageManagerResourcesDirectory: AbsolutePath?
228231

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

Sources/SwiftBuildSupport/SwiftBuildSystem.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ func withService(
6262
func withSession(
6363
service: SWBBuildService,
6464
name: String,
65+
packageManagerResourcesDirectory: Basics.AbsolutePath?,
6566
body: @escaping (
6667
_ session: SWBBuildServiceSession,
6768
_ diagnostics: [SwiftBuild.SwiftBuildMessage.DiagnosticInfo]
6869
) async throws -> Void
6970
) async throws {
70-
switch await service.createSession(name: name, cachePath: nil, inferiorProductsPath: nil, environment: nil) {
71+
switch await service.createSession(name: name, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil) {
7172
case (.success(let session), let diagnostics):
7273
do {
7374
try await body(session, diagnostics)
@@ -159,6 +160,7 @@ private final class PlanningOperationDelegate: SWBPlanningOperationDelegate, Sen
159160
public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
160161
private let buildParameters: BuildParameters
161162
private let packageGraphLoader: () async throws -> ModulesGraph
163+
private let packageManagerResourcesDirectory: Basics.AbsolutePath?
162164
private let logLevel: Basics.Diagnostic.Severity
163165
private var packageGraph: AsyncThrowingValueMemoizer<ModulesGraph> = .init()
164166
private var pifBuilder: AsyncThrowingValueMemoizer<PIFBuilder> = .init()
@@ -209,13 +211,15 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
209211
public init(
210212
buildParameters: BuildParameters,
211213
packageGraphLoader: @escaping () async throws -> ModulesGraph,
214+
packageManagerResourcesDirectory: Basics.AbsolutePath?,
212215
outputStream: OutputByteStream,
213216
logLevel: Basics.Diagnostic.Severity,
214217
fileSystem: FileSystem,
215218
observabilityScope: ObservabilityScope
216219
) throws {
217220
self.buildParameters = buildParameters
218221
self.packageGraphLoader = packageGraphLoader
222+
self.packageManagerResourcesDirectory = packageManagerResourcesDirectory
219223
self.outputStream = outputStream
220224
self.logLevel = logLevel
221225
self.fileSystem = fileSystem
@@ -257,7 +261,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
257261
)
258262

259263
do {
260-
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString) { session, _ in
264+
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString, packageManagerResourcesDirectory: self.packageManagerResourcesDirectory) { session, _ in
261265
self.outputStream.send("Building for \(self.buildParameters.configuration == .debug ? "debugging" : "production")...\n")
262266

263267
// Load the workspace, and set the system information to the default

Sources/swift-bootstrap/main.swift

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

Utilities/bootstrap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@ def install_swiftpm(prefix, args):
544544
dest = os.path.join(prefix, "lib", "swift", "pm", "PluginAPI")
545545
install_dylib(args, "PackagePlugin", dest, ["PackagePlugin"])
546546

547+
# Install resource bundles produced during the build.
548+
for file in os.listdir(args.bin_dir):
549+
if file.endswith('.bundle') or file.endswith('.resources'):
550+
install_binary(args, file, os.path.join(os.path.join(prefix, "share"), "pm"))
551+
547552

548553
# Helper function that installs a dynamic library and a set of modules to a particular directory.
549554
@log_entry_exit
@@ -587,7 +592,7 @@ def install_file(args, src, destination, destination_is_directory=True, ignored_
587592

588593
logging.info("Installing %s to %s", src, dest)
589594
if os.path.isdir(src):
590-
shutil.copytree(src, dest, ignore=shutil.ignore_patterns(*ignored_patterns))
595+
shutil.copytree(src, dest, ignore=shutil.ignore_patterns(*ignored_patterns), dirs_exist_ok=True)
591596
else:
592597
shutil.copy2(src, dest)
593598

@@ -851,7 +856,6 @@ def get_swiftpm_env_cmd(args):
851856

852857
if args.llbuild_link_framework:
853858
env_cmd.append("SWIFTPM_LLBUILD_FWK=1")
854-
env_cmd.append("SWIFTPM_NO_SWBUILD_DEPENDENCY=1")
855859
env_cmd.append("SWIFTCI_USE_LOCAL_DEPS=1")
856860
env_cmd.append("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target)
857861

0 commit comments

Comments
 (0)