Skip to content
Merged
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
48 changes: 48 additions & 0 deletions .github/scripts/format-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See http://swift.org/LICENSE.txt for license information
## See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
##
##===----------------------------------------------------------------------===##

set -euo pipefail

fail=0

while IFS= read -r file; do
# Skip empty or binary files
if [ ! -s "$file" ] || [[ "$file" == *png ]] || [[ "$file" == *mlmodel ]] || [[ "$file" == *mlpackage* ]] ; then
continue
fi

# --- Check for trailing whitespace (spaces or tabs before end of line) ---
# Using POSIX-compatible regex; no -P flag needed.
if grep -nE '[[:space:]]+$' "$file" >/dev/null; then
echo "❌ Trailing whitespace in: $file"
# Print offending lines (indent for readability)
grep -nE '[[:space:]]+$' "$file" | sed 's/^/ /'
fail=1
fi

# --- Check for final newline ---
# tail -c handles both GNU and BSD variants
lastchar=$(tail -c 1 "$file" | od -An -tx1 | tr -d ' \n')
if [[ "$lastchar" != "0a" ]]; then
echo "❌ Missing final newline: $file"
fail=1
fi

done < <(git ls-files)

if [[ $fail -eq 0 ]]; then
echo "✅ All tracked files are clean (no trailing whitespace, final newline present)."
else
echo "⚠️ Some files failed checks."
exit 1
fi
10 changes: 10 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ jobs:
license_header_check_project_name: "Swift"
api_breakage_check_enabled: false
format_check_enabled: false

space-format-check:
name: Space format check
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run space format check
run: cat .github/scripts/format-check.sh | bash
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.0
6.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct GenerateWindowsInstallerComponentGroups: CommandPlugin {
<Component>
<File Source="$(ToolchainRoot)\usr\bin\\#(sourceModule.name).dll" />
</Component>

"""#

let resources = sourceModule.sourceFiles.filter { resource in resource.type == .resource && ["xcspec", "xcbuildrules"].contains(resource.url.pathExtension) }
Expand All @@ -41,7 +41,7 @@ struct GenerateWindowsInstallerComponentGroups: CommandPlugin {
<Component>
<File Source="$(ToolchainRoot)\usr\share\pm\SwiftBuild_\#(sourceModule.name).resources\\#(resource.url.lastPathComponent)" />
</Component>

"""#
}
resourcesComponents += " </ComponentGroup>\n"
Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBAndroidPlatform/AndroidSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public import Foundation
init(from decoder: any Decoder, configuration: Version) throws {
struct DynamicCodingKey: CodingKey {
var stringValue: String

init?(stringValue: String) {
self.stringValue = stringValue
}

let intValue: Int? = nil

init?(intValue: Int) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBApplePlatform/EXUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class ExtensionPointExtractorSpec: GenericCommandLineToolSpec, SpecIdentif
let inputs = cbc.inputs.map { input in
return delegate.createNode(input.absolutePath)
}.filter { node in
node.path.fileExtension == "swiftconstvalues"
node.path.fileExtension == "swiftconstvalues"
}
var outputs = [any PlannedNode]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ final class AppExtensionInfoPlistGeneratorTaskProducer: PhasedTaskProducer, Task
let isApplePlatform = context.isApplePlatform
guard AppExtensionPlistGeneratorSpec.shouldConstructTask(scope: scope, productType: productType, isApplePlatform: isApplePlatform) else {
return []
}
}

let tasks: [any PlannedTask] = []
let buildFilesProcessingContext = BuildFilesProcessingContext(scope)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBBuildService/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ package struct ServiceMessageHandlers: ServiceExtension {
service.registerMessageHandler(ComputeDependencyClosureMsg.self)
service.registerMessageHandler(ComputeDependencyGraphMsg.self)
service.registerMessageHandler(DumpBuildDependencyInfoMsg.self)

service.registerMessageHandler(BuildDescriptionConfiguredTargetsMsg.self)
service.registerMessageHandler(BuildDescriptionSelectConfiguredTargetsForIndexMsg.self)
service.registerMessageHandler(BuildDescriptionConfiguredTargetSourcesMsg.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBBuildSystem/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ package final class BuildOperation: BuildSystemOperation {
// Create the low-level build system.
let adaptor: OperationSystemAdaptor
let system: BuildSystem

let llbQoS: SWBLLBuild.BuildSystem.QualityOfService?
switch request.qos {
case .default: llbQoS = .default
Expand Down
24 changes: 12 additions & 12 deletions Sources/SWBCore/CustomTaskTypeDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,48 @@
public import SWBUtil

public final class CustomTaskTypeDescription: TaskTypeDescription {

private init() {
}

public static let only: any TaskTypeDescription = CustomTaskTypeDescription()

public var payloadType: (any TaskPayload.Type)? {
nil
}

public var isUnsafeToInterrupt: Bool {
false
}

public var toolBasenameAliases: [String] {
[]
}

public func commandLineForSignature(for task: any ExecutableTask) -> [ByteString]? {
return nil
}

public func serializedDiagnosticsPaths(_ task: any ExecutableTask, _ fs: any FSProxy) -> [Path] {
[]
}

public func generateIndexingInfo(for task: any ExecutableTask, input: TaskGenerateIndexingInfoInput) -> [TaskGenerateIndexingInfoOutput] {
[]
}

public func generatePreviewInfo(for task: any ExecutableTask, input: TaskGeneratePreviewInfoInput, fs: any FSProxy) -> [TaskGeneratePreviewInfoOutput] {
[]
}

public func generateDocumentationInfo(for task: any ExecutableTask, input: TaskGenerateDocumentationInfoInput) -> [TaskGenerateDocumentationInfoOutput] {
[]
}

public func customOutputParserType(for task: any ExecutableTask) -> (any TaskOutputParser.Type)? {
ShellScriptOutputParser.self
}

public func interestingPath(for task: any ExecutableTask) -> Path? {
nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBCore/ShellScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public func computeScriptEnvironment(_ type: ScriptType, scope: MacroEvaluationS
for macro in alwaysPresentPathMacros {
result[macro.name] = scope.evaluate(macro).str
}

for macro in [BuiltinMacros.BUILD_COMPONENTS, BuiltinMacros.BUILD_VARIANTS] {
result[macro.name] = scope.evaluateAsString(macro)
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public struct DiscoveredLdLinkerToolSpecInfo: DiscoveredCommandLineToolSpecInfo

// Any unparsed bytes belong to the first line. We don't want to run `split` over these because it can lead to accidentally quadratic behavior if write is called many times per line.
lines[0] = unparsedBytes + lines[0]

let linesToParse = lines.dropLast()

if let target = self.task.forTarget?.target {
Expand All @@ -203,13 +203,13 @@ public struct DiscoveredLdLinkerToolSpecInfo: DiscoveredCommandLineToolSpecInfo
let lineString = String(decoding: lineBytes, as: Unicode.UTF8.self)
if lineString.contains(": error:")
|| lineString.contains(": warning:") {

let issueString = "\(projectPath.str): \(targetName): \(lineString)"
return ByteString(encodingAsUTF8: issueString)
}
return ByteString(lineBytes)
}

// Forward the bytes
processedLines.forEach {
delegate.emitOutput($0)
Expand All @@ -223,12 +223,12 @@ public struct DiscoveredLdLinkerToolSpecInfo: DiscoveredCommandLineToolSpecInfo
delegate.emitOutput("\n")
}
}

// Parse any complete lines of output.
for line in linesToParse {
parseLine(line)
}

// Track the last, incomplete line to as the unparsed bytes.
unparsedBytes = lines.last ?? []
}
Expand Down Expand Up @@ -809,7 +809,7 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
func emitDependencyDiagnostic(type: String, node: PlannedPathNode) {
if delegate.userPreferences.enableDebugActivityLogs {
let projectLocation = cbc.producer.projectLocation

delegate.note("Added \(type) dependency '\(node.path.str)' from command line argument \(arg)", location: projectLocation)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBCore/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public struct SwiftSDK: Sendable {
// Load info.json from the artifact bundle
let infoPath = artifactBundle.join("info.json")
guard try fs.isFile(infoPath) else { return [] }

let infoData = try Data(fs.read(infoPath))

let schema = try JSONDecoder().decode(SchemaVersionInfo.self, from: infoData)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBCore/ToolInfo/ClangToolInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
public var toolFeatures: ToolFeatures<FeatureFlag>
public func hasFeature(_ feature: String) -> Bool {
// FIXME: Remove once the feature flag is re-added to clang.
// rdar://139515136
// rdar://139515136
if feature == FeatureFlag.extractAPISupportsCPlusPlus.rawValue {
return clangVersion > Version(17)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBLLBuild/LowLevelBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension SWBUtil.FileInfo: SWBLLBuild.FileInfo {
// This should be remove from llbuild FileInfo protocol as it just not needed, would also be nice to remove the stat requirement too.
preconditionFailure()
}

public var statBuf: stat {
var statBuf: stat = stat()

Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBProtocol/BuildOperationMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public struct CreateBuildRequest: SessionChannelBuildMessage, RequestMessage, Se

public struct BuildStartRequest: SessionMessage, RequestMessage, Equatable {
public typealias ResponseMessage = VoidResponse

public static let name = "BUILD_START"

/// The identifier for the session to initiate the request in.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBProtocol/DependencyClosureMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public import SWBUtil

public struct ComputeDependencyClosureRequest: SessionMessage, RequestMessage, SerializableCodable, Equatable {
public typealias ResponseMessage = StringListResponse

public static let name = "COMPUTE_DEPENDENCY_CLOSURE_REQUEST"

public let sessionHandle: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBProtocol/DependencyGraphMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public struct DependencyGraphResponse: Message, SerializableCodable, Equatable {

public struct DumpBuildDependencyInfoRequest: SessionChannelBuildMessage, RequestMessage, SerializableCodable, Equatable {
public typealias ResponseMessage = VoidResponse

public static let name = "DUMP_BUILD_DEPENDENCY_INFO_REQUEST"

/// The identifier for the session to initiate the request in.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBProtocol/DocumentationMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public import SWBUtil
/// For a description of how this feature works, see the `SWBBuildServiceSession.generateDocumentationInfo` documentation.
public struct DocumentationInfoRequest: SessionChannelBuildMessage, RequestMessage, Equatable {
public typealias ResponseMessage = VoidResponse

public static let name = "DOCUMENTATION_INFO_REQUESTED"

/// The identifier for the session to initiate the request in.
Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBProtocol/IndexingMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public struct IndexingFileSettingsResponse: IndexingInfoResponse, Message, Equat

public struct IndexingHeaderInfoRequest: IndexingInfoRequest, RequestMessage, SessionChannelBuildMessage, SerializableCodable, Equatable {
public typealias ResponseMessage = VoidResponse

public static let name = "INDEXING_HEADER_INFO_REQUESTED"

/// The identifier for the session to initiate the request in.
Expand Down Expand Up @@ -143,7 +143,7 @@ let indexingMessageTypes: [any Message.Type] = [

public struct BuildDescriptionTargetInfoRequest: SessionChannelBuildMessage, RequestMessage, SerializableCodable, Equatable {
public typealias ResponseMessage = VoidResponse

public static let name = "BUILD_DESCRIPTION_TARGET_INFO"

/// The identifier for the session to initiate the request in.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBProtocol/MacroEvaluationMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public struct AllExportedMacrosAndValuesResponse: Message, Equatable, Serializab
/// Request to get macro assignment and resolved value information to show in the build settings editor.
public struct BuildSettingsEditorInfoRequest: SessionMessage, RequestMessage, Equatable, SerializableCodable {
public typealias ResponseMessage = BuildSettingsEditorInfoResponse

public static let name = "INFO_FOR_BUILD_SETTINGS_EDITOR_REQUEST"

public let sessionHandle: String
Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBProtocol/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public struct PingRequest: RequestMessage, Equatable {

public struct SetConfigItemRequest: RequestMessage, Equatable {
public typealias ResponseMessage = VoidResponse

public static let name = "SET_CONFIG_ITEM"

public let key: String
Expand Down Expand Up @@ -288,7 +288,7 @@ public struct GetBuildSettingsDescriptionRequest: SessionMessage, RequestMessage

public struct CreateXCFrameworkRequest: RequestMessage, Equatable, SerializableCodable {
public typealias ResponseMessage = StringResponse

public static let name = "CREATE_XCFRAMEWORK_REQUEST"

public let developerPath: Path?
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBProtocol/ProjectDescriptorMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public struct DescribeSchemesResponse: Message, Equatable {

public struct DescribeProductsRequest: SessionChannelMessage, RequestMessage, Equatable {
public typealias ResponseMessage = VoidResponse

public static let name = "PRODUCT_DESCRIPTION_REQUESTED"

/// The identifier for the session to initiate the request in.
Expand Down
6 changes: 3 additions & 3 deletions Sources/SWBProtocol/ProjectModel/CustomTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct CustomTask: SerializableCodable, Sendable {
self.enableSandboxing = enableSandboxing
self.preparesForIndexing = preparesForIndexing
}

enum CodingKeys: CodingKey {
case commandLine
case environmentVars
Expand All @@ -44,7 +44,7 @@ public struct CustomTask: SerializableCodable, Sendable {
case enableSandboxing
case preparesForIndexing
}

public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.commandLine, forKey: .commandLine)
Expand All @@ -57,7 +57,7 @@ public struct CustomTask: SerializableCodable, Sendable {
try container.encode(enableSandboxing, forKey: .enableSandboxing)
try container.encode(preparesForIndexing, forKey: .preparesForIndexing)
}

public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.commandLine = try container.decode([MacroExpressionSource].self, forKey: .commandLine)
Expand Down
Loading
Loading