From 6189b0e272a7280440c4a5f211b133de1fe359d1 Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Wed, 13 Aug 2025 04:24:34 +0100 Subject: [PATCH] SwiftModuleBuildDescription: Fix diagnostic file paths for WMO builds WMO builds have a single frontend invocation and produce a single diagnostic file named after the module. --- .../SwiftModuleBuildDescription.swift | 16 +++++++++-- Tests/CommandsTests/PackageCommandTests.swift | 28 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift b/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift index a6d79c01ca4..19a7c3322f8 100644 --- a/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift +++ b/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift @@ -1126,10 +1126,22 @@ extension SwiftModuleBuildDescription { extension SwiftModuleBuildDescription { package var diagnosticFiles: [AbsolutePath] { - self.sources.compactMap { self.diagnosticFile(sourceFile: $0) } + // WMO builds have a single frontend invocation and produce a single + // diagnostic file named after the module. + if self.useWholeModuleOptimization { + return [ + self.diagnosticFile(name: self.target.name) + ] + } + + return self.sources.map(self.diagnosticFile(sourceFile:)) + } + + private func diagnosticFile(name: String) -> AbsolutePath { + self.tempsPath.appending(component: "\(name).dia") } private func diagnosticFile(sourceFile: AbsolutePath) -> AbsolutePath { - self.tempsPath.appending(component: "\(sourceFile.basenameWithoutExt).dia") + self.diagnosticFile(name: sourceFile.basenameWithoutExt) } } diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index 8469e246e44..c9308aa6b2f 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -2168,7 +2168,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { } } - func testMigrateCommand() async throws { + func _testMigrateCommand(configuration: BuildConfiguration) async throws { try XCTSkipIf( !UserToolchain.default.supportesSupportedFeatures, "skipping because test environment compiler doesn't support `-print-supported-features`" @@ -2196,7 +2196,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { } let (stdout, _) = try await self.execute( - ["migrate", "--to-feature", featureName], + ["migrate", "-c", configuration.rawValue, "--to-feature", featureName], packagePath: fixturePath ) @@ -2220,6 +2220,14 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { try await doMigration(featureName: "InferIsolatedConformances", expectedSummary: "Applied 3 fix-its in 2 files") } + func testMigrateCommandDebug() async throws { + try await _testMigrateCommand(configuration: .debug) + } + + func testMigrateCommandRelease() async throws { + try await _testMigrateCommand(configuration: .release) + } + func testMigrateCommandWithBuildToolPlugins() async throws { try XCTSkipIf( !UserToolchain.default.supportesSupportedFeatures, @@ -4432,7 +4440,19 @@ class PackageCommandSwiftBuildTests: PackageCommandTestCase { try await super.testNoParameters() } - override func testMigrateCommand() async throws { + override func testMigrateCommandDebug() async throws { + try XCTSkipOnWindows( + because: """ + Possibly https://github.com/swiftlang/swift-package-manager/issues/8602: + error: Could not choose a single platform for target 'AllIncludingTests' from the supported platforms 'android qnx webassembly'. Specialization parameters imposed by workspace: platform 'nil' sdkVariant 'nil' supportedPlatforms: 'nil' toolchain: 'nil' + """, + skipPlatformCi: true, + ) + + try await super.testMigrateCommandDebug() + } + + override func testMigrateCommandRelease() async throws { try XCTSkipOnWindows( because: """ Possibly https://github.com/swiftlang/swift-package-manager/issues/8602: @@ -4441,7 +4461,7 @@ class PackageCommandSwiftBuildTests: PackageCommandTestCase { skipPlatformCi: true, ) - try await super.testMigrateCommand() + try await super.testMigrateCommandRelease() } override func testMigrateCommandUpdateManifest2Targets() async throws {