Skip to content

Commit eb6551d

Browse files
authored
Merge pull request #607 from swiftlang/owenv/linux-dsym-fix
Don't attempt to generate DSYMs on non-darwin platforms
2 parents ab3abb2 + 71507d0 commit eb6551d

File tree

5 files changed

+87
-55
lines changed

5 files changed

+87
-55
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ public final class BuiltinMacros {
995995
public static let PLATFORM_REQUIRES_SWIFT_AUTOLINK_EXTRACT = BuiltinMacros.declareBooleanMacro("PLATFORM_REQUIRES_SWIFT_AUTOLINK_EXTRACT")
996996
public static let PLATFORM_REQUIRES_SWIFT_MODULEWRAP = BuiltinMacros.declareBooleanMacro("PLATFORM_REQUIRES_SWIFT_MODULEWRAP")
997997
public static let RPATH_ORIGIN = BuiltinMacros.declareStringMacro("RPATH_ORIGIN")
998+
public static let PLATFORM_USES_DSYMS = BuiltinMacros.declareBooleanMacro("PLATFORM_USES_DSYMS")
998999
public static let SWIFT_ABI_CHECKER_BASELINE_DIR = BuiltinMacros.declareStringMacro("SWIFT_ABI_CHECKER_BASELINE_DIR")
9991000
public static let SWIFT_ABI_CHECKER_EXCEPTIONS_FILE = BuiltinMacros.declareStringMacro("SWIFT_ABI_CHECKER_EXCEPTIONS_FILE")
10001001
public static let SWIFT_ABI_GENERATION_TOOL_OUTPUT_DIR = BuiltinMacros.declareStringMacro("SWIFT_ABI_GENERATION_TOOL_OUTPUT_DIR")
@@ -2168,6 +2169,7 @@ public final class BuiltinMacros {
21682169
PLATFORM_REQUIRES_SWIFT_AUTOLINK_EXTRACT,
21692170
PLATFORM_REQUIRES_SWIFT_MODULEWRAP,
21702171
RPATH_ORIGIN,
2172+
PLATFORM_USES_DSYMS,
21712173
SWIFT_ABI_CHECKER_BASELINE_DIR,
21722174
SWIFT_ABI_CHECKER_EXCEPTIONS_FILE,
21732175
SWIFT_ABI_GENERATION_TOOL_OUTPUT_DIR,

Sources/SWBCore/Settings/Settings.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,6 +2548,7 @@ private class SettingsBuilder {
25482548
if let origin = imageFormat.rpathOrigin {
25492549
sdkTable.push(BuiltinMacros.RPATH_ORIGIN, literal: origin)
25502550
}
2551+
sdkTable.push(BuiltinMacros.PLATFORM_USES_DSYMS, literal: imageFormat.usesDsyms)
25512552
}
25522553

25532554
// Add additional SDK default settings.

Sources/SWBTaskConstruction/TaskProducers/BuildPhaseTaskProducers/SourcesTaskProducer.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ final class SourcesTaskProducer: FilesBasedBuildPhaseTaskProducerBase, FilesBase
349349
/// Returns `true` if the target which defines the settings in the given `scope` should generate a dSYM file.
350350
/// - remark: This method allows this task producer to ask this question about other targets by passing a `scope` for the target in question.
351351
private func shouldGenerateDSYM(_ scope: MacroEvaluationScope) -> Bool {
352+
guard scope.evaluate(BuiltinMacros.PLATFORM_USES_DSYMS) else {
353+
return false
354+
}
352355
let dSYMForDebugInfo = scope.evaluate(BuiltinMacros.GCC_GENERATE_DEBUGGING_SYMBOLS) && scope.evaluate(BuiltinMacros.DEBUG_INFORMATION_FORMAT) == "dwarf-with-dsym"
353356
// When emitting remarks, for now, a dSYM is required (<rdar://problem/45458590>)
354357
let dSYMForRemarks = scope.evaluate(BuiltinMacros.CLANG_GENERATE_OPTIMIZATION_REMARKS)

Sources/SWBUtil/ProcessInfo.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,21 @@ extension ImageFormat {
231231

232232
public var rpathOrigin: String? {
233233
switch self {
234-
case .macho:
235-
return "@loader_path"
236-
case .elf:
237-
return "$ORIGIN"
238-
default:
239-
return nil
234+
case .macho:
235+
return "@loader_path"
236+
case .elf:
237+
return "$ORIGIN"
238+
default:
239+
return nil
240+
}
241+
}
242+
243+
public var usesDsyms: Bool {
244+
switch self {
245+
case .macho:
246+
return true
247+
default:
248+
return false
240249
}
241250
}
242251
}

Tests/SWBTaskConstructionTests/DebugInformationTests.swift

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Testing
14+
import Foundation
1415

1516
import SWBCore
1617
import SWBTestSupport
@@ -21,7 +22,7 @@ import SWBUtil
2122
@Suite
2223
fileprivate struct DebugInformationTests: CoreBasedTests {
2324
/// Test the different DWARF version formats we support.
24-
@Test(.requireSDKs(.macOS))
25+
@Test(.requireSDKs(.host), .skipHostOS(.windows))
2526
func debugInformationVersion() async throws {
2627
let testProject = try await TestProject(
2728
"aProject",
@@ -55,7 +56,7 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
5556
let tester = try await TaskConstructionTester(getCore(), testProject)
5657

5758
// Test the default version.
58-
await tester.checkBuild(BuildParameters(configuration: "Config"), runDestination: .macOS) { results in
59+
await tester.checkBuild(BuildParameters(configuration: "Config"), runDestination: .host) { results in
5960
// Check clang.
6061
results.checkTask(.matchRuleType("CompileC")) { task in
6162
task.checkCommandLineContains(["-g"])
@@ -75,7 +76,7 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
7576
}
7677

7778
// Test explicitly setting to DWARF 4.
78-
await tester.checkBuild(BuildParameters(configuration: "Config", overrides: ["DEBUG_INFORMATION_VERSION" : "dwarf4"]), runDestination: .macOS) { results in
79+
await tester.checkBuild(BuildParameters(configuration: "Config", overrides: ["DEBUG_INFORMATION_VERSION" : "dwarf4"]), runDestination: .host) { results in
7980
// Check clang.
8081
results.checkTask(.matchRuleType("CompileC")) { task in
8182
task.checkCommandLineContains(["-g", "-gdwarf-4"])
@@ -93,7 +94,7 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
9394
}
9495

9596
// Test explicitly setting to DWARF 5.
96-
await tester.checkBuild(BuildParameters(configuration: "Config", overrides: ["DEBUG_INFORMATION_VERSION" : "dwarf5"]), runDestination: .macOS) { results in
97+
await tester.checkBuild(BuildParameters(configuration: "Config", overrides: ["DEBUG_INFORMATION_VERSION" : "dwarf5"]), runDestination: .host) { results in
9798
// Check clang.
9899
results.checkTask(.matchRuleType("CompileC")) { task in
99100
task.checkCommandLineContains(["-g", "-gdwarf-5"])
@@ -111,7 +112,7 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
111112
}
112113

113114
// Test disabling debug information.
114-
await tester.checkBuild(BuildParameters(configuration: "Config", overrides: ["DEBUG_INFORMATION_FORMAT" : "", "DEBUG_INFORMATION_VERSION" : "dwarf5"]), runDestination: .macOS) { results in
115+
await tester.checkBuild(BuildParameters(configuration: "Config", overrides: ["DEBUG_INFORMATION_FORMAT" : "", "DEBUG_INFORMATION_VERSION" : "dwarf5"]), runDestination: .host) { results in
115116
// Check clang.
116117
results.checkTask(.matchRuleType("CompileC")) { task in
117118
task.checkCommandLineDoesNotContain("-g")
@@ -132,7 +133,7 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
132133
}
133134

134135
/// Check that we only generate dSYMs when appropriate.
135-
@Test(.requireSDKs(.macOS))
136+
@Test(.requireSDKs(.host), .skipHostOS(.windows))
136137
func dSYMGeneration() async throws {
137138
let testProject = TestProject(
138139
"aProject",
@@ -158,7 +159,7 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
158159
let tester = try await TaskConstructionTester(getCore(), testProject)
159160

160161
// Check behavior with dSYMs disabled.
161-
await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["DEBUG_INFORMATION_FORMAT": "dwarf"]), runDestination: .macOS) { results in
162+
await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["DEBUG_INFORMATION_FORMAT": "dwarf"]), runDestination: .host) { results in
162163
// There shouldn't be a dSYM task.
163164
results.checkNoTask(.matchRuleType("GenerateDSYMFile"))
164165

@@ -167,10 +168,14 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
167168
}
168169

169170
// Check behavior with dSYMs enabled.
170-
await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["DEBUG_INFORMATION_FORMAT": "dwarf-with-dsym"]), runDestination: .macOS) { results in
171+
try await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["DEBUG_INFORMATION_FORMAT": "dwarf-with-dsym"]), runDestination: .host) { results in
171172
// Check the expected dSYM task.
172-
results.checkTask(.matchRuleType("GenerateDSYMFile")) { task in
173-
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/Test/aProject/build/Debug/CoreFoo.framework/Versions/A/CoreFoo"])
173+
if try ProcessInfo.processInfo.hostOperatingSystem() == .macOS {
174+
results.checkTask(.matchRuleType("GenerateDSYMFile")) { task in
175+
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/Test/aProject/build/Debug/CoreFoo.framework/Versions/A/CoreFoo"])
176+
}
177+
} else {
178+
results.checkNoTask(.matchRuleType("GenerateDSYMFile"))
174179
}
175180

176181
// Check there are no diagnostics.
@@ -179,26 +184,30 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
179184

180185
// Check install behavior with dSYMs enabled.
181186
let buildVariants = ["debug", "normal"]
182-
await tester.checkBuild(BuildParameters(action: .install, configuration: "Debug", overrides: [
187+
try await tester.checkBuild(BuildParameters(action: .install, configuration: "Debug", overrides: [
183188
"DEBUG_INFORMATION_FORMAT": "dwarf-with-dsym",
184189
"BUILD_VARIANTS": buildVariants.joined(separator: " "),
185-
]), runDestination: .macOS) { results in
190+
]), runDestination: .host) { results in
186191
// Check tasks for each build variant.
187192
for buildVariant in buildVariants {
188-
let binaryName = "CoreFoo" + (buildVariant == "normal" ? "" : "_\(buildVariant)")
189-
190-
// Check the dsymutil task for the build variant.
191-
var dsymutilTask: (any PlannedTask)? = nil
192-
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename(binaryName)) { task in
193-
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/aProject.dst/Library/Frameworks/CoreFoo.framework/Versions/A/\(binaryName)"])
194-
dsymutilTask = task
195-
}
193+
if try ProcessInfo.processInfo.hostOperatingSystem() == .macOS {
194+
let binaryName = "CoreFoo" + (buildVariant == "normal" ? "" : "_\(buildVariant)")
195+
196+
// Check the dsymutil task for the build variant.
197+
var dsymutilTask: (any PlannedTask)? = nil
198+
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename(binaryName)) { task in
199+
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/aProject.dst/Library/Frameworks/CoreFoo.framework/Versions/A/\(binaryName)"])
200+
dsymutilTask = task
201+
}
196202

197-
// Make sure the strip task for this build variant is ordered after the dsymutil task.
198-
results.checkTask(.matchRuleType("Strip"), .matchRuleItemBasename(binaryName)) { task in
199-
if let dsymutilTask {
200-
results.checkTaskFollows(task, antecedent: dsymutilTask)
203+
// Make sure the strip task for this build variant is ordered after the dsymutil task.
204+
results.checkTask(.matchRuleType("Strip"), .matchRuleItemBasename(binaryName)) { task in
205+
if let dsymutilTask {
206+
results.checkTaskFollows(task, antecedent: dsymutilTask)
207+
}
201208
}
209+
} else {
210+
results.checkNoTask(.matchRuleType("GenerateDSYMFile"))
202211
}
203212
}
204213

@@ -207,50 +216,58 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
207216
}
208217

209218
// Check install behavior with `DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT` enabled.
210-
await tester.checkBuild(BuildParameters(action: .install, configuration: "Debug", overrides: [
219+
try await tester.checkBuild(BuildParameters(action: .install, configuration: "Debug", overrides: [
211220
"DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT": "YES",
212221
"DEBUG_INFORMATION_FORMAT": "dwarf-with-dsym",
213222
"BUILD_VARIANTS": buildVariants.joined(separator: " "),
214-
]), runDestination: .macOS) { results in
215-
var dsymutilTasks = [any PlannedTask]()
216-
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo")) { task in
217-
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/aProject.dst/Library/Frameworks/CoreFoo.framework/Versions/A/CoreFoo"])
218-
dsymutilTasks.append(task)
219-
}
223+
]), runDestination: .host) { results in
224+
if try ProcessInfo.processInfo.hostOperatingSystem() == .macOS {
225+
var dsymutilTasks = [any PlannedTask]()
226+
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo")) { task in
227+
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/aProject.dst/Library/Frameworks/CoreFoo.framework/Versions/A/CoreFoo"])
228+
dsymutilTasks.append(task)
229+
}
220230

221-
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo_debug")) { task in
222-
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/aProject.dst/Library/Frameworks/CoreFoo.framework/Versions/A/CoreFoo_debug"])
223-
dsymutilTasks.append(task)
224-
}
231+
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo_debug")) { task in
232+
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/aProject.dst/Library/Frameworks/CoreFoo.framework/Versions/A/CoreFoo_debug"])
233+
dsymutilTasks.append(task)
234+
}
225235

226-
results.checkTask(.matchRuleType("Copy"), .matchRuleItemBasename("CoreFoo.framework.dSYM")) { task in
227-
task.checkCommandLine(["builtin-copy", "-exclude", ".DS_Store", "-exclude", "CVS", "-exclude", ".svn", "-exclude", ".git", "-exclude", ".hg", "-resolve-src-symlinks", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/aProject.dst/Library/Frameworks"])
236+
results.checkTask(.matchRuleType("Copy"), .matchRuleItemBasename("CoreFoo.framework.dSYM")) { task in
237+
task.checkCommandLine(["builtin-copy", "-exclude", ".DS_Store", "-exclude", "CVS", "-exclude", ".svn", "-exclude", ".git", "-exclude", ".hg", "-resolve-src-symlinks", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/aProject.dst/Library/Frameworks"])
228238

229-
// Make sure this task follows the dSYM producer tasks.
230-
for dsymutilTask in dsymutilTasks {
231-
results.checkTaskDependsOn(task, antecedent: dsymutilTask)
239+
// Make sure this task follows the dSYM producer tasks.
240+
for dsymutilTask in dsymutilTasks {
241+
results.checkTaskDependsOn(task, antecedent: dsymutilTask)
242+
}
232243
}
244+
} else {
245+
results.checkNoTask(.matchRuleType("GenerateDSYMFile"))
233246
}
234247

235248
// Check there are no diagnostics.
236249
results.checkNoDiagnostics()
237250
}
238251

239252
// Check build behavior with `DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT` enabled.
240-
await tester.checkBuild(BuildParameters(action: .build, configuration: "Debug", overrides: [
253+
try await tester.checkBuild(BuildParameters(action: .build, configuration: "Debug", overrides: [
241254
"DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT": "YES",
242255
"DEBUG_INFORMATION_FORMAT": "dwarf-with-dsym",
243256
"BUILD_VARIANTS": buildVariants.joined(separator: " "),
244-
]), runDestination: .macOS) { results in
245-
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo")) { task in
246-
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/Test/aProject/build/Debug/CoreFoo.framework/Versions/A/CoreFoo"])
247-
}
257+
]), runDestination: .host) { results in
258+
if try ProcessInfo.processInfo.hostOperatingSystem() == .macOS {
259+
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo")) { task in
260+
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/Test/aProject/build/Debug/CoreFoo.framework/Versions/A/CoreFoo"])
261+
}
248262

249-
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo_debug")) { task in
250-
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/Test/aProject/build/Debug/CoreFoo.framework/Versions/A/CoreFoo_debug"])
251-
}
263+
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo_debug")) { task in
264+
task.checkRuleInfo(["GenerateDSYMFile", "/tmp/Test/aProject/build/Debug/CoreFoo.framework.dSYM", "/tmp/Test/aProject/build/Debug/CoreFoo.framework/Versions/A/CoreFoo_debug"])
265+
}
252266

253-
results.checkNoTask(.matchRuleType("Copy"), .matchRuleItemBasename("CoreFoo.framework.dSYM"))
267+
results.checkNoTask(.matchRuleType("Copy"), .matchRuleItemBasename("CoreFoo.framework.dSYM"))
268+
} else {
269+
results.checkNoTask(.matchRuleType("GenerateDSYMFile"))
270+
}
254271

255272
// Check there are no diagnostics.
256273
results.checkNoDiagnostics()

0 commit comments

Comments
 (0)