|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | @testable import Basics
|
| 14 | +@testable import Build |
14 | 15 | @testable import CoreCommands
|
15 | 16 | @testable import Commands
|
| 17 | +@testable import PackageModel |
16 | 18 | import SPMTestSupport
|
17 | 19 | import XCTest
|
18 | 20 |
|
19 | 21 | import class TSCBasic.BufferedOutputByteStream
|
| 22 | +import class TSCBasic.InMemoryFileSystem |
20 | 23 | import protocol TSCBasic.OutputByteStream
|
21 | 24 | import var TSCBasic.stderrStream
|
22 | 25 |
|
@@ -232,6 +235,66 @@ final class SwiftToolTests: CommandsTestCase {
|
232 | 235 | // Tests should not modify user's home dir .netrc so leaving that out intentionally
|
233 | 236 | }
|
234 | 237 | }
|
| 238 | + |
| 239 | + func testDebugFormatFlags() throws { |
| 240 | + let fs = InMemoryFileSystem(emptyFiles: [ |
| 241 | + "/Pkg/Sources/exe/main.swift", |
| 242 | + ]) |
| 243 | + |
| 244 | + let explicitDwarfOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-windows-msvc", "-debug-info-format", "dwarf"]) |
| 245 | + let explicitDwarf = try SwiftTool.createSwiftToolForTest(options: explicitDwarfOptions) |
| 246 | + |
| 247 | + let observer = ObservabilitySystem.makeForTesting() |
| 248 | + let graph = try loadPackageGraph(fileSystem: fs, manifests: [ |
| 249 | + Manifest.createRootManifest(displayName: "Pkg", |
| 250 | + path: "/Pkg", |
| 251 | + targets: [TargetDescription(name: "exe")]) |
| 252 | + ], observabilityScope: observer.topScope) |
| 253 | + |
| 254 | + var plan: BuildPlan |
| 255 | + |
| 256 | + plan = try BuildPlan( |
| 257 | + buildParameters: explicitDwarf.buildParameters(), |
| 258 | + graph: graph, |
| 259 | + fileSystem: fs, |
| 260 | + observabilityScope: observer.topScope |
| 261 | + ) |
| 262 | + try XCTAssertMatch(plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [], |
| 263 | + [.anySequence, "-g", "-use-ld=lld", "-Xlinker", "-debug:dwarf"]) |
| 264 | + |
| 265 | + let explicitCodeViewOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-windows-msvc", "-debug-info-format", "codeview"]) |
| 266 | + let explicitCodeView = try SwiftTool.createSwiftToolForTest(options: explicitCodeViewOptions) |
| 267 | + |
| 268 | + plan = try BuildPlan( |
| 269 | + buildParameters: explicitCodeView.buildParameters(), |
| 270 | + graph: graph, |
| 271 | + fileSystem: fs, |
| 272 | + observabilityScope: observer.topScope |
| 273 | + ) |
| 274 | + try XCTAssertMatch(plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [], |
| 275 | + [.anySequence, "-g", "-debug-info-format=codeview", "-Xlinker", "-debug"]) |
| 276 | + |
| 277 | + let implicitDwarfOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-windows-msvc"]) |
| 278 | + let implicitDwarf = try SwiftTool.createSwiftToolForTest(options: implicitDwarfOptions) |
| 279 | + plan = try BuildPlan( |
| 280 | + buildParameters: implicitDwarf.buildParameters(), |
| 281 | + graph: graph, |
| 282 | + fileSystem: fs, |
| 283 | + observabilityScope: observer.topScope |
| 284 | + ) |
| 285 | + try XCTAssertMatch(plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [], |
| 286 | + [.anySequence, "-g", "-use-ld=lld", "-Xlinker", "-debug:dwarf"]) |
| 287 | + |
| 288 | + // Explicitly pass Linux as when the SwiftTool tests are enabled on |
| 289 | + // Windows, this would fail otherwise as CodeView is supported on the |
| 290 | + // native host. |
| 291 | + let unsupportedCodeViewOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-linux-gnu", "-debug-info-format", "codeview"]) |
| 292 | + let stream = BufferedOutputByteStream() |
| 293 | + let unsupportedCodeView = try SwiftTool.createSwiftToolForTest(outputStream: stream, options: unsupportedCodeViewOptions) |
| 294 | + |
| 295 | + XCTAssertNotNil(try? unsupportedCodeView.buildParameters()) |
| 296 | + XCTAssertMatch(stream.bytes.validDescription, .contains("error: CodeView debug information is currently not supported for this platform")) |
| 297 | + } |
235 | 298 | }
|
236 | 299 |
|
237 | 300 | extension SwiftTool {
|
|
0 commit comments