Skip to content

Commit 469349f

Browse files
authored
Merge pull request #888 from owenv/owenv/lane-width-override
Add SWBBuildRequestAPI to set llbuild scheduler width
2 parents feeb6f7 + ce2dfd0 commit 469349f

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

Sources/SWBBuildSystem/BuildOperation.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ package final class BuildOperation: BuildSystemOperation {
525525
return .commandNamePriority
526526
}()
527527

528-
let laneWidth = UserDefaults.schedulerLaneWidth ?? 0
528+
let laneWidth = request.schedulerLaneWidthOverride ?? UserDefaults.schedulerLaneWidth ?? 0
529529

530530
// Create the low-level build system.
531531
let adaptor: OperationSystemAdaptor
@@ -542,7 +542,7 @@ package final class BuildOperation: BuildSystemOperation {
542542

543543
if let entry {
544544
// If the entry is valid, reuse it.
545-
if let cachedAdaptor = entry.adaptor, entry.environment == buildEnvironment, entry.buildDescription! === buildDescription, entry.llbQoS == llbQoS {
545+
if let cachedAdaptor = entry.adaptor, entry.environment == buildEnvironment, entry.buildDescription! === buildDescription, entry.llbQoS == llbQoS, entry.laneWidth == laneWidth {
546546
adaptor = cachedAdaptor
547547
await adaptor.reset(operation: self, buildOutputDelegate: buildOutputDelegate)
548548
} else {
@@ -551,6 +551,7 @@ package final class BuildOperation: BuildSystemOperation {
551551
entry.adaptor = adaptor
552552
entry.buildDescription = buildDescription
553553
entry.llbQoS = llbQoS
554+
entry.laneWidth = laneWidth
554555
entry.fileSystemMode = fs.fileSystemMode
555556
entry.system = SWBLLBuild.BuildSystem(buildFile: buildDescription.manifestPath.str, databaseFile: dbPath.str, delegate: adaptor, environment: buildEnvironment, serial: serial, traceFile: traceFile?.str, schedulerAlgorithm: algorithm, schedulerLanes: laneWidth, qos: llbQoS)
556557
}

Sources/SWBBuildSystem/BuildSystemCache.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ package final class SystemCacheEntry: CacheableValue {
4040
/// The QoS to use for the llbuild invocation.
4141
var llbQoS: SWBLLBuild.BuildSystem.QualityOfService? = nil
4242

43+
/// Overrides the number of llbuild scheduler lanes.
44+
var laneWidth: UInt32 = 0
45+
4346
/// The system to use.
4447
var system: SWBLLBuild.BuildSystem? = nil
4548

Sources/SWBCore/BuildRequest.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ public final class BuildRequest: CustomStringConvertible, Sendable {
260260
/// The quality-of-service to use for this request.
261261
public let qos: SWBQoS
262262

263+
/// Overrides the number of lanes in the llbuild scheduler.
264+
public let schedulerLaneWidthOverride: UInt32?
265+
263266
/// Optional path of a directory into which to write diagnostic information about the build plan.
264267
public let buildPlanDiagnosticsDirPath: Path?
265268

@@ -282,7 +285,7 @@ public final class BuildRequest: CustomStringConvertible, Sendable {
282285
/// - Parameters:
283286
/// - parameters: The default build parameters, used in non-target specific contexts.
284287
/// - buildTargets: The list of targets which should be built
285-
public init(parameters: BuildParameters, buildTargets: [BuildTargetInfo], dependencyScope: DependencyScope = .workspace, continueBuildingAfterErrors: Bool, hideShellScriptEnvironment: Bool = false, useParallelTargets: Bool, useImplicitDependencies: Bool, useDryRun: Bool, enableStaleFileRemoval: Bool? = nil, showNonLoggedProgress: Bool = true, recordBuildBacktraces: Bool? = nil, generatePrecompiledModulesReport: Bool? = nil, buildDescriptionID: BuildDescriptionID? = nil, qos: SWBQoS? = nil, buildPlanDiagnosticsDirPath: Path? = nil, buildCommand: BuildCommand? = nil, schemeCommand: SchemeCommand? = .launch, containerPath: Path? = nil, jsonRepresentation: Data? = nil) {
288+
public init(parameters: BuildParameters, buildTargets: [BuildTargetInfo], dependencyScope: DependencyScope = .workspace, continueBuildingAfterErrors: Bool, hideShellScriptEnvironment: Bool = false, useParallelTargets: Bool, useImplicitDependencies: Bool, useDryRun: Bool, enableStaleFileRemoval: Bool? = nil, showNonLoggedProgress: Bool = true, recordBuildBacktraces: Bool? = nil, generatePrecompiledModulesReport: Bool? = nil, buildDescriptionID: BuildDescriptionID? = nil, qos: SWBQoS? = nil, schedulerLaneWidthOverride: UInt32? = nil, buildPlanDiagnosticsDirPath: Path? = nil, buildCommand: BuildCommand? = nil, schemeCommand: SchemeCommand? = .launch, containerPath: Path? = nil, jsonRepresentation: Data? = nil) {
286289
self.parameters = parameters
287290
self.buildTargets = buildTargets
288291
self.dependencyScope = dependencyScope
@@ -298,6 +301,7 @@ public final class BuildRequest: CustomStringConvertible, Sendable {
298301
self.generatePrecompiledModulesReport = generatePrecompiledModulesReport ?? SWBFeatureFlag.generatePrecompiledModulesReport.value
299302
self.buildDescriptionID = buildDescriptionID
300303
self.qos = qos ?? UserDefaults.defaultRequestQoS
304+
self.schedulerLaneWidthOverride = schedulerLaneWidthOverride
301305
self.buildPlanDiagnosticsDirPath = buildPlanDiagnosticsDirPath
302306
self.buildCommand = buildCommand ?? .build(style: .buildOnly, skipDependencies: false)
303307
self.schemeCommand = schemeCommand
@@ -332,7 +336,7 @@ extension BuildRequest {
332336
case .buildRequest:
333337
dependencyScope = .buildRequest
334338
}
335-
try self.init(parameters: parameters, buildTargets: payload.configuredTargets.map{ try BuildRequest.BuildTargetInfo(from: $0, defaultParameters: parameters, workspace: workspace) }, dependencyScope: dependencyScope, continueBuildingAfterErrors: payload.continueBuildingAfterErrors, hideShellScriptEnvironment: payload.hideShellScriptEnvironment, useParallelTargets: payload.useParallelTargets, useImplicitDependencies: payload.useImplicitDependencies, useDryRun: payload.useDryRun, enableStaleFileRemoval: nil, showNonLoggedProgress: payload.showNonLoggedProgress, recordBuildBacktraces: payload.recordBuildBacktraces, generatePrecompiledModulesReport: payload.generatePrecompiledModulesReport, buildDescriptionID: payload.buildDescriptionID.map(BuildDescriptionID.init), qos: qos, buildPlanDiagnosticsDirPath: payload.buildPlanDiagnosticsDirPath, buildCommand: buildCommand, schemeCommand: payload.schemeCommand?.coreRepresentation, containerPath: payload.containerPath, jsonRepresentation: payload.jsonRepresentation)
339+
try self.init(parameters: parameters, buildTargets: payload.configuredTargets.map{ try BuildRequest.BuildTargetInfo(from: $0, defaultParameters: parameters, workspace: workspace) }, dependencyScope: dependencyScope, continueBuildingAfterErrors: payload.continueBuildingAfterErrors, hideShellScriptEnvironment: payload.hideShellScriptEnvironment, useParallelTargets: payload.useParallelTargets, useImplicitDependencies: payload.useImplicitDependencies, useDryRun: payload.useDryRun, enableStaleFileRemoval: nil, showNonLoggedProgress: payload.showNonLoggedProgress, recordBuildBacktraces: payload.recordBuildBacktraces, generatePrecompiledModulesReport: payload.generatePrecompiledModulesReport, buildDescriptionID: payload.buildDescriptionID.map(BuildDescriptionID.init), qos: qos, schedulerLaneWidthOverride: payload.schedulerLaneWidthOverride, buildPlanDiagnosticsDirPath: payload.buildPlanDiagnosticsDirPath, buildCommand: buildCommand, schemeCommand: payload.schemeCommand?.coreRepresentation, containerPath: payload.containerPath, jsonRepresentation: payload.jsonRepresentation)
336340
}
337341

338342
/// Whether the build request _explicitly_ contains the specified `target`.

Sources/SWBProtocol/MessageSupport.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ public struct BuildRequestMessagePayload: SerializableCodable, Equatable, Sendab
166166
public var containerPath: Path?
167167
public var buildDescriptionID: String?
168168
public var qos: BuildQoSMessagePayload?
169+
public var schedulerLaneWidthOverride: UInt32?
169170
public var jsonRepresentation: Foundation.Data?
170171

171-
public init(parameters: BuildParametersMessagePayload, configuredTargets: [ConfiguredTargetMessagePayload], dependencyScope: DependencyScopeMessagePayload, continueBuildingAfterErrors: Bool, hideShellScriptEnvironment: Bool, useParallelTargets: Bool, useImplicitDependencies: Bool, useDryRun: Bool, showNonLoggedProgress: Bool, recordBuildBacktraces: Bool?, generatePrecompiledModulesReport: Bool?, buildPlanDiagnosticsDirPath: Path?, buildCommand: BuildCommandMessagePayload, schemeCommand: SchemeCommandMessagePayload?, containerPath: Path?, buildDescriptionID: String?, qos: BuildQoSMessagePayload?, jsonRepresentation: Foundation.Data?) {
172+
public init(parameters: BuildParametersMessagePayload, configuredTargets: [ConfiguredTargetMessagePayload], dependencyScope: DependencyScopeMessagePayload, continueBuildingAfterErrors: Bool, hideShellScriptEnvironment: Bool, useParallelTargets: Bool, useImplicitDependencies: Bool, useDryRun: Bool, showNonLoggedProgress: Bool, recordBuildBacktraces: Bool?, generatePrecompiledModulesReport: Bool?, buildPlanDiagnosticsDirPath: Path?, buildCommand: BuildCommandMessagePayload, schemeCommand: SchemeCommandMessagePayload?, containerPath: Path?, buildDescriptionID: String?, qos: BuildQoSMessagePayload?, schedulerLaneWidthOverride: UInt32?, jsonRepresentation: Foundation.Data?) {
172173
self.parameters = parameters
173174
self.configuredTargets = configuredTargets
174175
self.dependencyScope = dependencyScope
@@ -186,6 +187,7 @@ public struct BuildRequestMessagePayload: SerializableCodable, Equatable, Sendab
186187
self.containerPath = containerPath
187188
self.buildDescriptionID = buildDescriptionID
188189
self.qos = qos
190+
self.schedulerLaneWidthOverride = schedulerLaneWidthOverride
189191
self.jsonRepresentation = jsonRepresentation
190192
}
191193

@@ -207,6 +209,7 @@ public struct BuildRequestMessagePayload: SerializableCodable, Equatable, Sendab
207209
case containerPath
208210
case buildDescriptionID
209211
case qos
212+
case schedulerLaneWidthOverride
210213
case jsonRepresentation
211214
}
212215

@@ -230,6 +233,7 @@ public struct BuildRequestMessagePayload: SerializableCodable, Equatable, Sendab
230233
self.containerPath = try container.decodeIfPresent(Path.self, forKey: BuildRequestMessagePayload.CodingKeys.containerPath)
231234
self.buildDescriptionID = try container.decodeIfPresent(String.self, forKey: BuildRequestMessagePayload.CodingKeys.buildDescriptionID)
232235
self.qos = try container.decodeIfPresent(BuildQoSMessagePayload.self, forKey: BuildRequestMessagePayload.CodingKeys.qos)
236+
self.schedulerLaneWidthOverride = try container.decodeIfPresent(UInt32.self, forKey: BuildRequestMessagePayload.CodingKeys.schedulerLaneWidthOverride)
233237
self.jsonRepresentation = try container.decodeIfPresent(Data.self, forKey: BuildRequestMessagePayload.CodingKeys.jsonRepresentation)
234238

235239
}
@@ -254,6 +258,7 @@ public struct BuildRequestMessagePayload: SerializableCodable, Equatable, Sendab
254258
try container.encodeIfPresent(self.containerPath, forKey: BuildRequestMessagePayload.CodingKeys.containerPath)
255259
try container.encodeIfPresent(self.buildDescriptionID, forKey: BuildRequestMessagePayload.CodingKeys.buildDescriptionID)
256260
try container.encodeIfPresent(self.qos, forKey: BuildRequestMessagePayload.CodingKeys.qos)
261+
try container.encodeIfPresent(self.schedulerLaneWidthOverride, forKey: BuildRequestMessagePayload.CodingKeys.schedulerLaneWidthOverride)
257262
try container.encodeIfPresent(self.jsonRepresentation, forKey: BuildRequestMessagePayload.CodingKeys.jsonRepresentation)
258263
}
259264
}

Sources/SwiftBuild/SWBBuildRequest.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ public struct SWBBuildRequest: Codable, Sendable {
294294
/// The QoS to use for the build operation. If not set then a default QoS, that can be configured with a UserDefault, will be selected.
295295
public var qos: SWBBuildQoS? = nil
296296

297+
/// Overrides the default number of scheduler lanes used by llbuild.
298+
public var schedulerLaneWidthOverride: UInt32? = nil
299+
297300
/// Whether or not legacy build locations are being used. Currently, this flag is only relevant for clean build folder.
298301
public var useLegacyBuildLocations = false
299302

Sources/SwiftBuild/SWBBuildServiceSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ extension SWBBuildQoS {
819819

820820
extension SWBBuildRequest {
821821
var messagePayloadRepresentation: BuildRequestMessagePayload {
822-
return BuildRequestMessagePayload(parameters: parameters.messagePayloadRepresentation, configuredTargets: configuredTargets.map{ $0.messagePayloadRepresentation }, dependencyScope: dependencyScope.messagePayload, continueBuildingAfterErrors: continueBuildingAfterErrors, hideShellScriptEnvironment: hideShellScriptEnvironment, useParallelTargets: useParallelTargets, useImplicitDependencies: useImplicitDependencies, useDryRun: useDryRun, showNonLoggedProgress: showNonLoggedProgress, recordBuildBacktraces: recordBuildBacktraces, generatePrecompiledModulesReport: generatePrecompiledModulesReport, buildPlanDiagnosticsDirPath: buildPlanDiagnosticsDirPath.map(Path.init), buildCommand: buildCommand.messagePayloadRepresentation, schemeCommand: schemeCommand?.messagePayloadRepresentation, containerPath: containerPath.map(Path.init), buildDescriptionID: buildDescriptionID, qos: qos?.messagePayloadRepresentation, jsonRepresentation: try? jsonData())
822+
return BuildRequestMessagePayload(parameters: parameters.messagePayloadRepresentation, configuredTargets: configuredTargets.map{ $0.messagePayloadRepresentation }, dependencyScope: dependencyScope.messagePayload, continueBuildingAfterErrors: continueBuildingAfterErrors, hideShellScriptEnvironment: hideShellScriptEnvironment, useParallelTargets: useParallelTargets, useImplicitDependencies: useImplicitDependencies, useDryRun: useDryRun, showNonLoggedProgress: showNonLoggedProgress, recordBuildBacktraces: recordBuildBacktraces, generatePrecompiledModulesReport: generatePrecompiledModulesReport, buildPlanDiagnosticsDirPath: buildPlanDiagnosticsDirPath.map(Path.init), buildCommand: buildCommand.messagePayloadRepresentation, schemeCommand: schemeCommand?.messagePayloadRepresentation, containerPath: containerPath.map(Path.init), buildDescriptionID: buildDescriptionID, qos: qos?.messagePayloadRepresentation, schedulerLaneWidthOverride: schedulerLaneWidthOverride, jsonRepresentation: try? jsonData())
823823
}
824824
}
825825

Tests/SWBProtocolTests/MessageSerializationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import Testing
5555
)
5656
)
5757

58-
payload = BuildRequestMessagePayload(parameters: params, configuredTargets: [ConfiguredTargetMessagePayload(guid: "some other guid", parameters: params)], dependencyScope: .workspace, continueBuildingAfterErrors: true, hideShellScriptEnvironment: false, useParallelTargets: true, useImplicitDependencies: false, useDryRun: true, showNonLoggedProgress: false, recordBuildBacktraces: nil, generatePrecompiledModulesReport: nil, buildPlanDiagnosticsDirPath: Path("/tmp/foobar"), buildCommand: .prepareForIndexing(buildOnlyTheseTargets: nil, enableIndexBuildArena: false), schemeCommand: .profile, containerPath: Path("/tmp/foobar.xcodeproj"), buildDescriptionID: nil, qos: nil, jsonRepresentation: Data())
58+
payload = BuildRequestMessagePayload(parameters: params, configuredTargets: [ConfiguredTargetMessagePayload(guid: "some other guid", parameters: params)], dependencyScope: .workspace, continueBuildingAfterErrors: true, hideShellScriptEnvironment: false, useParallelTargets: true, useImplicitDependencies: false, useDryRun: true, showNonLoggedProgress: false, recordBuildBacktraces: nil, generatePrecompiledModulesReport: nil, buildPlanDiagnosticsDirPath: Path("/tmp/foobar"), buildCommand: .prepareForIndexing(buildOnlyTheseTargets: nil, enableIndexBuildArena: false), schemeCommand: .profile, containerPath: Path("/tmp/foobar.xcodeproj"), buildDescriptionID: nil, qos: nil, schedulerLaneWidthOverride: nil, jsonRepresentation: Data())
5959
}
6060

6161
@Test func basicMessagesRoundTrip() throws {

0 commit comments

Comments
 (0)