Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/SWBBuildService/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ private struct SetSessionUserPreferencesMsg: MessageHandler {
enableBuildSystemCaching: message.enableBuildSystemCaching,
activityTextShorteningLevel: message.activityTextShorteningLevel,
usePerConfigurationBuildLocations: message.usePerConfigurationBuildLocations,
allowsExternalToolExecution: message.allowsExternalToolExecution ?? UserPreferences.allowsExternalToolExecutionDefaultValue)
allowsExternalToolExecution: message.allowsExternalToolExecution ?? UserPreferences.allowsExternalToolExecutionDefaultValue,
emitFrontendCommandLines: message.emitFrontendCommandLines ?? false)
)

return VoidResponse()
Expand Down
10 changes: 8 additions & 2 deletions Sources/SWBCore/WorkspaceContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public struct UserPreferences: Sendable {
/// Whether dynamic tasks are allowed to request processes be spawned as external tools.
public let allowsExternalToolExecution: Bool

/// Whether the frontend command lines for compiler invocations should be emitted to the build log.
public let emitFrontendCommandLines: Bool

public static var allowsExternalToolExecutionDefaultValue: Bool {
#if RC_PLAYGROUNDS
return true
Expand All @@ -123,7 +126,8 @@ public struct UserPreferences: Sendable {
enableBuildSystemCaching: UserDefaults.enableBuildSystemCaching,
activityTextShorteningLevel: UserDefaults.activityTextShorteningLevel,
usePerConfigurationBuildLocations: UserDefaults.usePerConfigurationBuildLocations,
allowsExternalToolExecution: UserDefaults.allowsExternalToolExecution
allowsExternalToolExecution: UserDefaults.allowsExternalToolExecution,
emitFrontendCommandLines: UserDefaults.emitFrontendCommandLines
)

public init(
Expand All @@ -132,14 +136,16 @@ public struct UserPreferences: Sendable {
enableBuildSystemCaching: Bool,
activityTextShorteningLevel: ActivityTextShorteningLevel,
usePerConfigurationBuildLocations: Bool?,
allowsExternalToolExecution: Bool
allowsExternalToolExecution: Bool,
emitFrontendCommandLines: Bool
) {
self.enableDebugActivityLogs = enableDebugActivityLogs
self.enableBuildDebugging = enableBuildDebugging
self.enableBuildSystemCaching = enableBuildSystemCaching
self.activityTextShorteningLevel = activityTextShorteningLevel
self.usePerConfigurationBuildLocations = usePerConfigurationBuildLocations
self.allowsExternalToolExecution = allowsExternalToolExecution
self.emitFrontendCommandLines = emitFrontendCommandLines
}
}

Expand Down
5 changes: 4 additions & 1 deletion Sources/SWBProtocol/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ public struct SetSessionUserPreferencesRequest: SessionMessage, RequestMessage,
public let activityTextShorteningLevel: ActivityTextShorteningLevel
public let usePerConfigurationBuildLocations: Bool?
public let allowsExternalToolExecution: Bool?
public let emitFrontendCommandLines: Bool?

public init(sessionHandle: String, enableDebugActivityLogs: Bool, enableBuildDebugging: Bool, enableBuildSystemCaching: Bool, activityTextShorteningLevel: ActivityTextShorteningLevel, usePerConfigurationBuildLocations: Bool?) {
self.sessionHandle = sessionHandle
Expand All @@ -665,16 +666,18 @@ public struct SetSessionUserPreferencesRequest: SessionMessage, RequestMessage,
self.activityTextShorteningLevel = activityTextShorteningLevel
self.usePerConfigurationBuildLocations = usePerConfigurationBuildLocations
self.allowsExternalToolExecution = nil
self.emitFrontendCommandLines = nil
}

public init(sessionHandle: String, enableDebugActivityLogs: Bool, enableBuildDebugging: Bool, enableBuildSystemCaching: Bool, activityTextShorteningLevel: ActivityTextShorteningLevel, usePerConfigurationBuildLocations: Bool?, allowsExternalToolExecution: Bool) {
public init(sessionHandle: String, enableDebugActivityLogs: Bool, enableBuildDebugging: Bool, enableBuildSystemCaching: Bool, activityTextShorteningLevel: ActivityTextShorteningLevel, usePerConfigurationBuildLocations: Bool?, allowsExternalToolExecution: Bool, emitFrontendCommandLines: Bool? = nil) {
self.sessionHandle = sessionHandle
self.enableDebugActivityLogs = enableDebugActivityLogs
self.enableBuildDebugging = enableBuildDebugging
self.enableBuildSystemCaching = enableBuildSystemCaching
self.activityTextShorteningLevel = activityTextShorteningLevel
self.usePerConfigurationBuildLocations = usePerConfigurationBuildLocations
self.allowsExternalToolExecution = allowsExternalToolExecution
self.emitFrontendCommandLines = emitFrontendCommandLines
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ package final class BuildPlan: StaleFileRemovalContext {
self.invalidationPaths = Array(invalidationPaths.sorted(by: \.str))
self.recursiveSearchPathResults = globalProductPlan.recursiveSearchPathResolver.allResults
self.copiedPathMap = copiedPathMap
self.emitFrontendCommandLines = productPlanResultContexts.map { $0.productPlan.taskProducerContext.emitFrontendCommandLines }.reduce(false, { $0 || $1 })
self.emitFrontendCommandLines = planRequest.workspaceContext.userPreferences.emitFrontendCommandLines || productPlanResultContexts.map { $0.productPlan.taskProducerContext.emitFrontendCommandLines }.reduce(false, { $0 || $1 })
}

static func unexpectedDuplicateTasksWithIdentifier(_ tasks: [any PlannedTask], _ workspace: Workspace, _ delegate: any TaskPlanningDelegate) {
Expand Down
9 changes: 6 additions & 3 deletions Sources/SWBTestSupport/TestWorkspaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1599,15 +1599,17 @@ extension UserPreferences {
enableBuildSystemCaching: true,
activityTextShorteningLevel: .default,
usePerConfigurationBuildLocations: nil,
allowsExternalToolExecution: false)
allowsExternalToolExecution: false,
emitFrontendCommandLines: false)

package func with(
enableDebugActivityLogs: Bool? = nil,
enableBuildDebugging: Bool? = nil,
enableBuildSystemCaching: Bool? = nil,
activityTextShorteningLevel: ActivityTextShorteningLevel? = nil,
usePerConfigurationBuildLocations: Bool?? = .none,
allowsExternalToolExecution: Bool? = nil
allowsExternalToolExecution: Bool? = nil,
emitFrontendCommandLines: Bool? = nil
) -> UserPreferences {
let usePerConfigurationBuildLocationsValue: Bool?
switch usePerConfigurationBuildLocations {
Expand All @@ -1625,7 +1627,8 @@ extension UserPreferences {
enableBuildSystemCaching: enableBuildSystemCaching ?? self.enableBuildSystemCaching,
activityTextShorteningLevel: activityTextShorteningLevel ?? self.activityTextShorteningLevel,
usePerConfigurationBuildLocations: usePerConfigurationBuildLocationsValue,
allowsExternalToolExecution: allowsExternalToolExecution ?? self.allowsExternalToolExecution
allowsExternalToolExecution: allowsExternalToolExecution ?? self.allowsExternalToolExecution,
emitFrontendCommandLines: emitFrontendCommandLines ?? self.emitFrontendCommandLines
)
}
}
5 changes: 5 additions & 0 deletions Sources/SWBUtil/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ public enum UserDefaults: Sendable {
return string(forKey: "CompilationCachingDiskSizeLimit")
}

/// Whether the frontend command lines for compiler invocations should be emitted to the build log.
public static var emitFrontendCommandLines: Bool {
return bool(forKey: "EmitFrontendCommandLines")
}

/// Provides the default level of QoS support within Swift Build for global queues that are not tied to specific build requests.
public static var undeterminedQoS: SWBQoS {
// With 'unspecified' the QoS of the caller is influencing the QoS to be used for the enqueued work item.
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftBuild/SWBBuildServiceSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,15 @@ public final class SWBBuildServiceSession: Sendable {
_ = try await service.send(request: SetSessionUserPreferencesRequest(sessionHandle: self.uid, enableDebugActivityLogs: enableDebugActivityLogs, enableBuildDebugging: enableBuildDebugging, enableBuildSystemCaching: enableBuildSystemCaching, activityTextShorteningLevel: ActivityTextShorteningLevel(rawValue: activityTextShorteningLevel) ?? .default, usePerConfigurationBuildLocations: usePerConfigurationBuildLocations))
}

@available(*, deprecated, renamed: "setUserPreferences(enableDebugActivityLogs:enableBuildDebugging:enableBuildSystemCaching:activityTextShorteningLevel:usePerConfigurationBuildLocations:allowsExternalToolExecution:emitFrontendCommandLines:)")
public func setUserPreferences(enableDebugActivityLogs: Bool, enableBuildDebugging: Bool, enableBuildSystemCaching: Bool, activityTextShorteningLevel: Int, usePerConfigurationBuildLocations: Bool?, allowsExternalToolExecution: Bool) async throws {
_ = try await service.send(request: SetSessionUserPreferencesRequest(sessionHandle: self.uid, enableDebugActivityLogs: enableDebugActivityLogs, enableBuildDebugging: enableBuildDebugging, enableBuildSystemCaching: enableBuildSystemCaching, activityTextShorteningLevel: ActivityTextShorteningLevel(rawValue: activityTextShorteningLevel) ?? .default, usePerConfigurationBuildLocations: usePerConfigurationBuildLocations, allowsExternalToolExecution: allowsExternalToolExecution))
}

public func setUserPreferences(enableDebugActivityLogs: Bool, enableBuildDebugging: Bool, enableBuildSystemCaching: Bool, activityTextShorteningLevel: Int, usePerConfigurationBuildLocations: Bool?, allowsExternalToolExecution: Bool, emitFrontendCommandLines: Bool) async throws {
_ = try await service.send(request: SetSessionUserPreferencesRequest(sessionHandle: self.uid, enableDebugActivityLogs: enableDebugActivityLogs, enableBuildDebugging: enableBuildDebugging, enableBuildSystemCaching: enableBuildSystemCaching, activityTextShorteningLevel: ActivityTextShorteningLevel(rawValue: activityTextShorteningLevel) ?? .default, usePerConfigurationBuildLocations: usePerConfigurationBuildLocations, allowsExternalToolExecution: allowsExternalToolExecution, emitFrontendCommandLines: emitFrontendCommandLines))
}

public func lookupToolchain(at path: String) async throws -> SWBToolchainIdentifier? {
return try await service.send(request: LookupToolchainRequest(sessionHandle: self.uid, path: Path(path))).toolchainIdentifier.map { SWBToolchainIdentifier(rawValue: $0) }
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftBuildTestSupport/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ extension SWBBuildServiceSession {
enableBuildSystemCaching: userPreferences.enableBuildSystemCaching,
activityTextShorteningLevel: userPreferences.activityTextShorteningLevel.rawValue,
usePerConfigurationBuildLocations: userPreferences.usePerConfigurationBuildLocations,
allowsExternalToolExecution: userPreferences.allowsExternalToolExecution)
allowsExternalToolExecution: userPreferences.allowsExternalToolExecution,
emitFrontendCommandLines: userPreferences.emitFrontendCommandLines)
}

package func generateIndexingFileSettings(for request: SWBBuildRequest, targetID: String, delegate: any SWBIndexingDelegate) async throws -> SWBIndexingFileSettings {
Expand Down
8 changes: 8 additions & 0 deletions SwiftBuild.docc/Development/build-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ defaults write org.swift.swift-build EnableDebugActivityLogs -bool YES
This will cause Swift Build to emit more detailed note diagnostics to the build log
which is deemed to verbose for normal usage.

### Frontend command lines

```
defaults write org.swift.swift-build EmitFrontendCommandLines -bool YES
```

This will cause Swift Build to emit the frontend command lines for compiler invocations to the build log. It is a lighter-weight subset of `EnableDebugActivityLogs` equivalent to setting the `EMIT_FRONTEND_COMMAND_LINES` build setting persistently.

### Incremental build debugging

```
Expand Down
34 changes: 34 additions & 0 deletions Tests/SWBBuildSystemTests/BuildOperationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8120,6 +8120,40 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script
}
}

@Test(.requireSDKs(.macOS), arguments: [true, false])
func emitFrontendCommandLines(preference: Bool) async throws {
// Each parameterized invocation is independent, giving the BuildDescriptionManager
// a fresh workspace so it plans with the correct emitFrontendCommandLines value.
try await withTemporaryDirectory { tmpDirPath in
let testWorkspace = try await TestWorkspace(
"Test",
sourceRoot: tmpDirPath.join("Test"),
projects: [
TestProject(
"aProject",
groupTree: TestGroup("Sources", path: "Sources", children: [TestFile("Source.swift")]),
buildConfigurations: [TestBuildConfiguration("Debug", buildSettings: [
"PRODUCT_NAME": "$(TARGET_NAME)",
"SWIFT_VERSION": swiftVersion,
"SWIFT_USE_INTEGRATED_DRIVER": "YES",
])],
targets: [TestStandardTarget("TargetA", type: .framework, buildPhases: [TestSourcesBuildPhase(["Source.swift"])])])
])
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
let SRCROOT = testWorkspace.sourceRoot.join("aProject")
try await tester.fs.writeFileContents(SRCROOT.join("Sources/Source.swift")) { $0 <<< "struct A {}\n" }
tester.userPreferences = .defaultForTesting.with(emitFrontendCommandLines: preference)
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
results.checkNoErrors()
results.checkTask(.matchRuleType("SwiftCompile")) { task in
results.checkTaskOutput(task) { output in
#expect(output.stringValue?.contains("swift-frontend") == preference)
}
}
}
}
}

@Test(.requireSDKs(.host))
func swiftSDKToolsets() async throws {
try await withTemporaryDirectory { tmpDirPath async throws -> Void in
Expand Down
1 change: 1 addition & 0 deletions Tests/SWBCoreTests/SettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5715,4 +5715,5 @@ import SWBTestSupport
}
}
}

}
2 changes: 2 additions & 0 deletions Tests/SWBProtocolTests/MessageSerializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ import Testing
assertMsgPackMessageRoundTrip(SetSessionSystemInfoRequest(sessionHandle: "theSession", operatingSystemVersion: Version(11, 1, 3), productBuildVersion: "25A573", nativeArchitecture: "arm64"))
assertMsgPackMessageRoundTrip(SetSessionUserInfoRequest(sessionHandle: "theSession", user: "mobile", group: "mobile", uid: 501, gid: 99, home: "/root", processEnvironment: ["HOME": "/root"], buildSystemEnvironment: ["SRCROOT": "/"]))
assertMsgPackMessageRoundTrip(SetSessionUserPreferencesRequest(sessionHandle: "theSession", enableDebugActivityLogs: true, enableBuildDebugging: true, enableBuildSystemCaching: true, activityTextShorteningLevel: .default, usePerConfigurationBuildLocations: nil))
assertMsgPackMessageRoundTrip(SetSessionUserPreferencesRequest(sessionHandle: "theSession", enableDebugActivityLogs: true, enableBuildDebugging: true, enableBuildSystemCaching: true, activityTextShorteningLevel: .default, usePerConfigurationBuildLocations: nil, allowsExternalToolExecution: true))
assertMsgPackMessageRoundTrip(SetSessionUserPreferencesRequest(sessionHandle: "theSession", enableDebugActivityLogs: true, enableBuildDebugging: true, enableBuildSystemCaching: true, activityTextShorteningLevel: .default, usePerConfigurationBuildLocations: nil, allowsExternalToolExecution: true, emitFrontendCommandLines: true))
assertMsgPackMessageRoundTrip(ListSessionsRequest())
assertMsgPackMessageRoundTrip(ListSessionsResponse(sessions: ["theSession": .init(name: "itsGreat", activeBuildCount: 0, activeNormalBuildCount: 0, activeIndexBuildCount: 0)]))
assertMsgPackMessageRoundTrip(DeleteSessionRequest(sessionHandle: "theSession"))
Expand Down
Loading