From 63538a2f57e345a2e0ca3cbad41a831152e8e371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Pi=C3=B1era?= Date: Sat, 20 Dec 2025 10:44:08 +0100 Subject: [PATCH] Emit warning for unhandled files in SwiftBuild MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The native build system emits a warning when source directories contain files that are not handled by the build (not Swift sources, not declared as resources, and not excluded). SwiftBuild was missing this diagnostic, creating an inconsistency between the two build systems. This adds the diagnoseUnhandledFiles check to PIFBuilder.swift, mirroring the implementation in BuildOperation.swift for the native build system. Fixes https://github.com/swiftlang/swift-package-manager/issues/8786 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- Sources/SwiftBuildSupport/PIFBuilder.swift | 42 ++++++++++++++++++++++ Tests/FunctionalTests/PluginTests.swift | 4 +-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftBuildSupport/PIFBuilder.swift b/Sources/SwiftBuildSupport/PIFBuilder.swift index 6e304910499..5f3fec1a19e 100644 --- a/Sources/SwiftBuildSupport/PIFBuilder.swift +++ b/Sources/SwiftBuildSupport/PIFBuilder.swift @@ -389,6 +389,12 @@ public final class PIFBuilder { observabilityScope: observabilityScope ) + self.diagnoseUnhandledFiles( + package: package, + module: module, + buildToolPluginInvocationResults: buildToolPluginResults + ) + let result = PackagePIFBuilder.BuildToolPluginInvocationResult( prebuildCommandOutputPaths: runResults.flatMap( { $0.derivedFiles }), buildCommands: buildCommands @@ -530,6 +536,42 @@ public final class PIFBuilder { ) return try await builder.generatePIF(preservePIFModelStructure: preservePIFModelStructure, buildParameters: buildParameters) } + + private func diagnoseUnhandledFiles( + package: ResolvedPackage, + module: ResolvedModule, + buildToolPluginInvocationResults: [BuildToolPluginInvocationResult] + ) { + guard package.manifest.toolsVersion >= .v5_3 else { + return + } + + var unhandledFiles = Set(module.underlying.others) + if unhandledFiles.isEmpty { + return + } + + let handledFiles = buildToolPluginInvocationResults.flatMap { $0.buildCommands.flatMap(\.inputFiles) } + unhandledFiles.subtract(handledFiles) + + if unhandledFiles.isEmpty { + return + } + + let diagnosticsEmitter = self.observabilityScope.makeDiagnosticsEmitter { + var metadata = ObservabilityMetadata() + metadata.packageIdentity = package.identity + metadata.packageKind = package.manifest.packageKind + metadata.moduleName = module.name + return metadata + } + var warning = + "found \(unhandledFiles.count) file(s) which are unhandled; explicitly declare them as resources or exclude from the target\n" + for file in unhandledFiles { + warning += " " + file.pathString + "\n" + } + diagnosticsEmitter.emit(warning: warning) + } } fileprivate final class PackagePIFBuilderDelegate: PackagePIFBuilder.BuildDelegate { diff --git a/Tests/FunctionalTests/PluginTests.swift b/Tests/FunctionalTests/PluginTests.swift index e9a8162e650..3653ee36b62 100644 --- a/Tests/FunctionalTests/PluginTests.swift +++ b/Tests/FunctionalTests/PluginTests.swift @@ -73,7 +73,6 @@ struct PluginTests { @Test( .IssueWindowsRelativePathAssert, - .bug("https://github.com/swiftlang/swift-package-manager/issues/8786"), .requiresSwiftConcurrencySupport, .tags( .Feature.Command.Test, @@ -93,8 +92,7 @@ struct PluginTests { #expect(stderr.contains("file(s) which are unhandled; explicitly declare them as resources or exclude from the target"), "expected warning not emitted") } } when: { - (ProcessInfo.hostOperatingSystem == .windows && CiEnvironment.runningInSelfHostedPipeline && buildSystem == .native) - || (buildSystem == .swiftbuild) + ProcessInfo.hostOperatingSystem == .windows && CiEnvironment.runningInSelfHostedPipeline && buildSystem == .native } }