diff --git a/Sources/SwiftDriver/Jobs/CompileJob.swift b/Sources/SwiftDriver/Jobs/CompileJob.swift index a2952864b..7a19daaca 100644 --- a/Sources/SwiftDriver/Jobs/CompileJob.swift +++ b/Sources/SwiftDriver/Jobs/CompileJob.swift @@ -292,7 +292,8 @@ extension Driver { } try addCommonFrontendOptions(commandLine: &commandLine, inputs: &inputs, kind: .compile, - explicitModulePlanner: explicitModulePlanner) + explicitModulePlanner: explicitModulePlanner, forVariantEmitModule: false, + forObject: outputType == .object) try addRuntimeLibraryFlags(commandLine: &commandLine) if Driver.canDoCrossModuleOptimization(parsedOptions: &parsedOptions) && @@ -371,6 +372,9 @@ extension Driver { commandLine.appendFlag(map) } + if isFrontendArgSupported(.debugModulePath) { + try commandLine.appendLast(.debugModulePath, from: &parsedOptions) + } try commandLine.appendLast(.trackSystemDependencies, from: &parsedOptions) try commandLine.appendLast(.CrossModuleOptimization, from: &parsedOptions) try commandLine.appendLast(.EnableCMOEverything, from: &parsedOptions) diff --git a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift index c79d6dc2a..acb44c74d 100644 --- a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift +++ b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift @@ -58,7 +58,8 @@ extension Driver { kind: Job.Kind, bridgingHeaderHandling: BridgingHeaderHandling = .precompiled, explicitModulePlanner: ExplicitDependencyBuildPlanner? = nil, - forVariantEmitModule: Bool = false + forVariantEmitModule: Bool = false, + forObject: Bool = false ) throws { // Only pass -target to the REPL or immediate modes if it was explicitly // specified on the command line. @@ -108,6 +109,12 @@ extension Driver { jobNeedPathRemap = false } + if isPlanJobForExplicitModule && forObject && isFrontendArgSupported(.debugModulePath), + let explicitModulePlanner { + let mainModule = explicitModulePlanner.dependencyGraph.mainModule + try addPathOption(option: .debugModulePath, path: VirtualPath.lookup(mainModule.modulePath.path), to: &commandLine, remap: jobNeedPathRemap) + } + // Check if dependency scanner has put the job into direct clang cc1 mode. // If dependency scanner put us into direct cc1 mode, avoid adding `-Xcc` options, since // dependency scanner already adds needed flags and -Xcc options known by swift-driver are @@ -290,6 +297,7 @@ extension Driver { } try commandLine.appendAll(.D, from: &parsedOptions) try commandLine.appendAll(.debugPrefixMap, .coveragePrefixMap, .filePrefixMap, from: &parsedOptions) + try commandLine.appendLast(.debugModulePath, from: &parsedOptions) try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions) try commandLine.appendLast(.warnConcurrency, from: &parsedOptions) if isFrontendArgSupported(.noAllocations) { diff --git a/Sources/SwiftOptions/Options.swift b/Sources/SwiftOptions/Options.swift index 8308d4c74..295e927e6 100644 --- a/Sources/SwiftOptions/Options.swift +++ b/Sources/SwiftOptions/Options.swift @@ -129,6 +129,8 @@ extension Option { public static let debugInverseRequirements: Option = Option("-debug-inverse-requirements", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Print real requirements in -debug-generic-signatures output") public static let debugMapping: Option = Option("-debug-mapping", .flag, attributes: [.noDriver], helpText: "Dumping information for debug purposes") public static let debugMapping_: Option = Option("--debug-mapping", .flag, alias: Option.debugMapping, attributes: [.noDriver], helpText: "Dumping information for debug purposes") + public static let debugModulePathEQ: Option = Option("-debug-module-path=", .joined, alias: Option.debugModulePath, attributes: [.frontend]) + public static let debugModulePath: Option = Option("-debug-module-path", .separate, attributes: [.frontend], helpText: "Path to this module's binary swiftmodule artifact (required by debug info)") public static let debugPrefixMap: Option = Option("-debug-prefix-map", .separate, attributes: [.frontend], metaVar: "", helpText: "Remap source paths in debug info") public static let debugRequirementMachine: Option = Option("-debug-requirement-machine=", .joined, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Fine-grained debug output from the generics implementation") public static let debugTimeExpressionTypeChecking: Option = Option("-debug-time-expression-type-checking", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Dumps the time it takes to type-check each expression") @@ -1554,6 +1556,8 @@ extension Option { Option.explicitAutoLinking, Option.explicitDependencyGraphFormat, Option.explicitInterfaceModuleBuild, + Option.debugModulePathEQ, + Option.debugModulePath, Option.driverExplicitModuleBuild, Option.explicitSwiftModuleMap, Option.exportAs, diff --git a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift index 0758de0f8..9f7fbaa47 100644 --- a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift +++ b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift @@ -718,6 +718,10 @@ final class ExplicitModuleBuildTests: XCTestCase { for job in jobs { XCTAssertEqual(job.outputs.count, 1) let outputFilePath = job.outputs[0].file + if job.kind == .compile && driver.isFrontendArgSupported(.debugModulePath) { + XCTAssertTrue(job.commandLine.contains(subsequence: ["-debug-module-path", try toPathOption("testExplicitModuleBuildJobs.swiftmodule")])) + + } // Swift dependencies if outputFilePath.extension != nil,