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
9 changes: 7 additions & 2 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,13 @@ extension Driver {
if let outputFileMapPath = try outputFileMap?.existingOutput(inputFile: input.fileHandle, outputType: outputType) {
outputPath = outputFileMapPath
} else if let output = inputOutputMap[input]?.first, output.file != .standardOutput, compilerOutputType != nil {
// Alongside primary output
outputPath = try output.file.replacingExtension(with: outputType).intern()
// For optimization records, use finalOutputPath over derived path
if outputType == .yamlOptimizationRecord || outputType == .bitstreamOptimizationRecord {
outputPath = finalOutputPath
} else {
// Alongside primary output for other types
outputPath = try output.file.replacingExtension(with: outputType).intern()
}
} else {
outputPath = try VirtualPath.createUniqueTemporaryFile(RelativePath(validating: input.file.basenameWithoutExt.appendingFileTypeExtension(outputType))).intern()
}
Expand Down
43 changes: 43 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3542,6 +3542,49 @@ final class SwiftDriverTests: XCTestCase {
try checkSupplementaryOutputFileMap(format: "bitstream", .bitstreamOptimizationRecord)
}

func testOptimizationRecordPathUserProvidedPath() throws {

do {
var driver = try Driver(args: [
"swiftc", "-save-optimization-record", "-save-optimization-record-path", "/tmp/test.opt.yaml",
"-c", "test.swift"
])
let plannedJobs = try driver.planBuild()
let compileJob = try XCTUnwrap(plannedJobs.first { $0.kind == .compile })

XCTAssertTrue(compileJob.commandLine.contains(.path(VirtualPath.absolute(try AbsolutePath(validating: "/tmp/test.opt.yaml")))))
XCTAssertTrue(compileJob.commandLine.contains(.flag("-save-optimization-record-path")))
}

do {
var driver = try Driver(args: [
"swiftc", "-wmo", "-save-optimization-record", "-save-optimization-record-path", "/tmp/wmo.opt.yaml",
"-c", "test.swift"
])
let plannedJobs = try driver.planBuild()
let compileJob = try XCTUnwrap(plannedJobs.first { $0.kind == .compile })

XCTAssertTrue(compileJob.commandLine.contains(.path(VirtualPath.absolute(try AbsolutePath(validating: "/tmp/wmo.opt.yaml")))))
XCTAssertTrue(compileJob.commandLine.contains(.flag("-save-optimization-record-path")))
}

do {
var driver = try Driver(args: [
"swiftc", "-wmo", "-num-threads", "4", "-save-optimization-record",
"-save-optimization-record-path", "/tmp/mt1.opt.yaml",
"-save-optimization-record-path", "/tmp/mt2.opt.yaml",
"-c", "test1.swift", "test2.swift"
])
let plannedJobs = try driver.planBuild()
let compileJob = try XCTUnwrap(plannedJobs.first { $0.kind == .compile })

XCTAssertTrue(compileJob.commandLine.contains(.flag("-save-optimization-record-path")))
let hasFirstPath = compileJob.commandLine.contains(.path(VirtualPath.absolute(try AbsolutePath(validating: "/tmp/mt1.opt.yaml"))))
let hasSecondPath = compileJob.commandLine.contains(.path(VirtualPath.absolute(try AbsolutePath(validating: "/tmp/mt2.opt.yaml"))))
XCTAssertTrue(hasFirstPath || hasSecondPath, "Should contain at least one user-provided optimization record path")
}
}

func testUpdateCode() throws {
do {
var driver = try Driver(args: [
Expand Down