@@ -825,7 +825,7 @@ extension Driver {
825825 // Print actions using the same style as the old C++ driver
826826 // This is mostly for testing purposes. We should print semantically
827827 // equivalent actions as the old driver.
828- Driver . printActions ( jobs)
828+ printActions ( jobs)
829829 return
830830 }
831831
@@ -915,41 +915,76 @@ extension Driver {
915915 stdoutStream. flush ( )
916916 }
917917
918- private static func printActions( _ jobs: [ Job ] ) {
918+ /// This handles -driver-print-actions flag. The C++ driver has a concept of actions
919+ /// which it builds up a list of actions before then creating them into jobs.
920+ /// The swift-driver doesn't have actions, so the logic here takes the jobs and tries
921+ /// to mimic the actions that would be created by the C++ driver and
922+ /// prints them in *hopefully* the same order.
923+ private func printActions( _ jobs: [ Job ] ) {
919924 defer {
920925 stdoutStream. flush ( )
921926 }
927+
928+ // Put bridging header as first input if we have it
929+ let allInputs : [ TypedVirtualPath ]
930+ if let objcHeader = importedObjCHeader, bridgingPrecompiledHeader != nil {
931+ allInputs = [ TypedVirtualPath ( file: objcHeader, type: . objcHeader) ] + inputFiles
932+ } else {
933+ allInputs = inputFiles
934+ }
935+
922936 var jobIdMap = Dictionary < Job , UInt > ( )
923937 // The C++ driver treats each input as an action, we should print them as
924938 // an action too for testing purposes.
925939 var inputIdMap = Dictionary < TypedVirtualPath , UInt > ( )
926940 var nextId : UInt = 0
941+ var allInputsIterator = allInputs. makeIterator ( )
927942 for job in jobs {
943+ // After "module input" jobs, print any left over inputs
944+ switch job. kind {
945+ case . generatePCH, . compile, . backend:
946+ break
947+ default :
948+ while let input = allInputsIterator. next ( ) {
949+ Self . printInputIfNew ( input, inputIdMap: & inputIdMap, nextId: & nextId)
950+ }
951+ }
928952 // All input action IDs for this action.
929- var inputIds = Set < UInt > ( )
953+ var inputIds = [ UInt] ( )
930954 // Collect input job IDs.
931955 for input in job. displayInputs. isEmpty ? job. inputs : job. displayInputs {
956+ if let id = inputIdMap [ input] {
957+ inputIds. append ( id)
958+ continue
959+ }
932960 var foundInput = false
933961 for (prevJob, id) in jobIdMap {
934962 if prevJob. outputs. contains ( input) {
935963 foundInput = true
936- inputIds. insert ( id)
964+ inputIds. append ( id)
965+ break
937966 }
938967 }
939- if ( !foundInput) {
940- if inputIdMap [ input] == nil {
941- stdoutStream <<< nextId <<< " : " <<< " input, "
942- stdoutStream <<< " \" " <<< input. file <<< " \" , " <<< input. type <<< " \n "
943- inputIdMap [ input] = nextId
944- nextId += 1
968+ if !foundInput {
969+ while let nextInputAction = allInputsIterator. next ( ) {
970+ Self . printInputIfNew ( nextInputAction, inputIdMap: & inputIdMap, nextId: & nextId)
971+ if let id = inputIdMap [ input] {
972+ inputIds. append ( id)
973+ break
974+ }
945975 }
946- inputIds. insert ( inputIdMap [ input] !)
947976 }
948977 }
978+
949979 // Print current Job
950980 stdoutStream <<< nextId <<< " : " <<< job. kind. rawValue <<< " , { "
951- stdoutStream <<< inputIds. sorted ( ) . map ( { $0. description } )
952- . joined ( separator: " , " )
981+ switch job. kind {
982+ // Don't sort for compile jobs. Puts pch last
983+ case . compile:
984+ stdoutStream <<< inputIds. map ( \. description) . joined ( separator: " , " )
985+ default :
986+ stdoutStream <<< inputIds. sorted ( ) . map ( \. description) . joined ( separator: " , " )
987+ }
953988 var typeName = job. outputs. first? . type. name
954989 if typeName == nil {
955990 typeName = " none "
@@ -960,6 +995,15 @@ extension Driver {
960995 }
961996 }
962997
998+ private static func printInputIfNew( _ input: TypedVirtualPath , inputIdMap: inout [ TypedVirtualPath : UInt ] , nextId: inout UInt ) {
999+ if inputIdMap [ input] == nil {
1000+ stdoutStream <<< nextId <<< " : " <<< " input, "
1001+ stdoutStream <<< " \" " <<< input. file <<< " \" , " <<< input. type <<< " \n "
1002+ inputIdMap [ input] = nextId
1003+ nextId += 1
1004+ }
1005+ }
1006+
9631007 private func printVersion< S: OutputByteStream > ( outputStream: inout S ) throws {
9641008 outputStream <<< frontendTargetInfo. compilerVersion <<< " \n "
9651009 outputStream <<< " Target: \( frontendTargetInfo. target. triple. triple) \n "
0 commit comments