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
42 changes: 42 additions & 0 deletions Sources/SwiftBuildSupport/PIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions Tests/FunctionalTests/PluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ struct PluginTests {

@Test(
.IssueWindowsRelativePathAssert,
.bug("https://github.com/swiftlang/swift-package-manager/issues/8786"),
.requiresSwiftConcurrencySupport,
.tags(
.Feature.Command.Test,
Expand All @@ -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
}
}

Expand Down