From 9c66cc8e0f76bf757374e5b46cb2cb9bf9883830 Mon Sep 17 00:00:00 2001 From: David Ungar Date: Fri, 9 Oct 2020 18:03:09 -0700 Subject: [PATCH] add primaryInputs to jobs --- .../ExplicitModuleBuildHandler.swift | 2 ++ .../ModuleDependencyScanning.swift | 2 ++ .../SwiftDriver/Jobs/AutolinkExtractJob.swift | 1 + Sources/SwiftDriver/Jobs/BackendJob.swift | 1 + Sources/SwiftDriver/Jobs/CompileJob.swift | 1 + Sources/SwiftDriver/Jobs/EmitModuleJob.swift | 1 + .../SwiftDriver/Jobs/GenerateDSYMJob.swift | 1 + Sources/SwiftDriver/Jobs/GeneratePCHJob.swift | 1 + Sources/SwiftDriver/Jobs/GeneratePCMJob.swift | 1 + Sources/SwiftDriver/Jobs/InterpretJob.swift | 1 + Sources/SwiftDriver/Jobs/Job.swift | 5 ++++ Sources/SwiftDriver/Jobs/LinkJob.swift | 1 + Sources/SwiftDriver/Jobs/MergeModuleJob.swift | 1 + Sources/SwiftDriver/Jobs/ModuleWrapJob.swift | 1 + Sources/SwiftDriver/Jobs/Planning.swift | 2 ++ .../SwiftDriver/Jobs/PrintTargetInfoJob.swift | 1 + Sources/SwiftDriver/Jobs/ReplJob.swift | 1 + .../SwiftDriver/Jobs/VerifyDebugInfoJob.swift | 1 + .../Jobs/VerifyModuleInterfaceJob.swift | 1 + Tests/SwiftDriverTests/JobExecutorTests.swift | 25 +++++++++++-------- .../ModuleDependencyGraphTests.swift | 5 ++-- 21 files changed, 43 insertions(+), 13 deletions(-) diff --git a/Sources/SwiftDriver/Explicit Module Builds/ExplicitModuleBuildHandler.swift b/Sources/SwiftDriver/Explicit Module Builds/ExplicitModuleBuildHandler.swift index d638c41e1..34bb27935 100644 --- a/Sources/SwiftDriver/Explicit Module Builds/ExplicitModuleBuildHandler.swift +++ b/Sources/SwiftDriver/Explicit Module Builds/ExplicitModuleBuildHandler.swift @@ -187,6 +187,7 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn tool: .absolute(try toolchain.getToolPath(.swiftCompiler)), commandLine: commandLine, inputs: inputs, + primaryInputs: [], outputs: outputs ) } @@ -232,6 +233,7 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn tool: .absolute(try toolchain.getToolPath(.swiftCompiler)), commandLine: commandLine, inputs: inputs, + primaryInputs: [], outputs: outputs ) } diff --git a/Sources/SwiftDriver/Explicit Module Builds/ModuleDependencyScanning.swift b/Sources/SwiftDriver/Explicit Module Builds/ModuleDependencyScanning.swift index 64615370e..93cc141d3 100644 --- a/Sources/SwiftDriver/Explicit Module Builds/ModuleDependencyScanning.swift +++ b/Sources/SwiftDriver/Explicit Module Builds/ModuleDependencyScanning.swift @@ -48,6 +48,7 @@ extension Driver { commandLine: commandLine, displayInputs: inputs, inputs: inputs, + primaryInputs: [], outputs: [TypedVirtualPath(file: .standardOutput, type: .jsonDependencies)], supportsResponseFiles: true) } @@ -156,6 +157,7 @@ extension Driver { commandLine: commandLine, displayInputs: inputs, inputs: inputs, + primaryInputs: [], outputs: outputs, supportsResponseFiles: true) } diff --git a/Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift b/Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift index 65499348d..dd99a1b90 100644 --- a/Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift +++ b/Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift @@ -34,6 +34,7 @@ extension Driver { tool: .absolute(try toolchain.getToolPath(.swiftAutolinkExtract)), commandLine: commandLine, inputs: inputs, + primaryInputs: [], outputs: [.init(file: output, type: .autolink)], supportsResponseFiles: true ) diff --git a/Sources/SwiftDriver/Jobs/BackendJob.swift b/Sources/SwiftDriver/Jobs/BackendJob.swift index 9f27bb6f8..1c68b2742 100644 --- a/Sources/SwiftDriver/Jobs/BackendJob.swift +++ b/Sources/SwiftDriver/Jobs/BackendJob.swift @@ -72,6 +72,7 @@ extension Driver { commandLine: commandLine, displayInputs: inputs, inputs: inputs, + primaryInputs: [], outputs: outputs, supportsResponseFiles: true ) diff --git a/Sources/SwiftDriver/Jobs/CompileJob.swift b/Sources/SwiftDriver/Jobs/CompileJob.swift index 82ed2d8b6..7133f3aaa 100644 --- a/Sources/SwiftDriver/Jobs/CompileJob.swift +++ b/Sources/SwiftDriver/Jobs/CompileJob.swift @@ -267,6 +267,7 @@ extension Driver { commandLine: commandLine, displayInputs: primaryInputs, inputs: inputs, + primaryInputs: primaryInputs, outputs: outputs, supportsResponseFiles: true ) diff --git a/Sources/SwiftDriver/Jobs/EmitModuleJob.swift b/Sources/SwiftDriver/Jobs/EmitModuleJob.swift index e0dc822e0..977d21936 100644 --- a/Sources/SwiftDriver/Jobs/EmitModuleJob.swift +++ b/Sources/SwiftDriver/Jobs/EmitModuleJob.swift @@ -75,6 +75,7 @@ extension Driver { tool: .absolute(try toolchain.getToolPath(.swiftCompiler)), commandLine: commandLine, inputs: inputs, + primaryInputs: [], outputs: outputs ) } diff --git a/Sources/SwiftDriver/Jobs/GenerateDSYMJob.swift b/Sources/SwiftDriver/Jobs/GenerateDSYMJob.swift index fc60e79b8..e971bb297 100644 --- a/Sources/SwiftDriver/Jobs/GenerateDSYMJob.swift +++ b/Sources/SwiftDriver/Jobs/GenerateDSYMJob.swift @@ -29,6 +29,7 @@ extension Driver { commandLine: commandLine, displayInputs: [], inputs: inputs, + primaryInputs: [], outputs: [.init(file: outputPath, type: .dSYM)] ) } diff --git a/Sources/SwiftDriver/Jobs/GeneratePCHJob.swift b/Sources/SwiftDriver/Jobs/GeneratePCHJob.swift index 2e5522f45..176e5f620 100644 --- a/Sources/SwiftDriver/Jobs/GeneratePCHJob.swift +++ b/Sources/SwiftDriver/Jobs/GeneratePCHJob.swift @@ -68,6 +68,7 @@ extension Driver { commandLine: commandLine, displayInputs: [], inputs: inputs, + primaryInputs: [], outputs: outputs, supportsResponseFiles: true ) diff --git a/Sources/SwiftDriver/Jobs/GeneratePCMJob.swift b/Sources/SwiftDriver/Jobs/GeneratePCMJob.swift index 8416cff41..1a0eff3d8 100644 --- a/Sources/SwiftDriver/Jobs/GeneratePCMJob.swift +++ b/Sources/SwiftDriver/Jobs/GeneratePCMJob.swift @@ -59,6 +59,7 @@ extension Driver { commandLine: commandLine, displayInputs: [], inputs: inputs, + primaryInputs: [], outputs: outputs ) } diff --git a/Sources/SwiftDriver/Jobs/InterpretJob.swift b/Sources/SwiftDriver/Jobs/InterpretJob.swift index 2ff9d23c5..4f5936e5e 100644 --- a/Sources/SwiftDriver/Jobs/InterpretJob.swift +++ b/Sources/SwiftDriver/Jobs/InterpretJob.swift @@ -46,6 +46,7 @@ extension Driver { tool: .absolute(try toolchain.getToolPath(.swiftCompiler)), commandLine: commandLine, inputs: inputs, + primaryInputs: [], outputs: [], extraEnvironment: extraEnvironment, requiresInPlaceExecution: true, diff --git a/Sources/SwiftDriver/Jobs/Job.swift b/Sources/SwiftDriver/Jobs/Job.swift index 8109a0f09..de59c867d 100644 --- a/Sources/SwiftDriver/Jobs/Job.swift +++ b/Sources/SwiftDriver/Jobs/Job.swift @@ -70,6 +70,9 @@ public struct Job: Codable, Equatable, Hashable { /// The list of inputs for this job. public var inputs: [TypedVirtualPath] + /// The primary inputs for compile jobs + public var primaryInputs: [TypedVirtualPath] + /// The outputs produced by the job. public var outputs: [TypedVirtualPath] @@ -89,6 +92,7 @@ public struct Job: Codable, Equatable, Hashable { commandLine: [ArgTemplate], displayInputs: [TypedVirtualPath]? = nil, inputs: [TypedVirtualPath], + primaryInputs: [TypedVirtualPath], outputs: [TypedVirtualPath], extraEnvironment: [String: String] = [:], requiresInPlaceExecution: Bool = false, @@ -100,6 +104,7 @@ public struct Job: Codable, Equatable, Hashable { self.commandLine = commandLine self.displayInputs = displayInputs ?? [] self.inputs = inputs + self.primaryInputs = primaryInputs self.outputs = outputs self.extraEnvironment = extraEnvironment self.requiresInPlaceExecution = requiresInPlaceExecution diff --git a/Sources/SwiftDriver/Jobs/LinkJob.swift b/Sources/SwiftDriver/Jobs/LinkJob.swift index 75c92c0b4..1dd5b536f 100644 --- a/Sources/SwiftDriver/Jobs/LinkJob.swift +++ b/Sources/SwiftDriver/Jobs/LinkJob.swift @@ -58,6 +58,7 @@ extension Driver { tool: .absolute(toolPath), commandLine: commandLine, inputs: inputs, + primaryInputs: [], outputs: [.init(file: outputFile, type: .image)] ) } diff --git a/Sources/SwiftDriver/Jobs/MergeModuleJob.swift b/Sources/SwiftDriver/Jobs/MergeModuleJob.swift index 87bc2da9d..5cbb14e02 100644 --- a/Sources/SwiftDriver/Jobs/MergeModuleJob.swift +++ b/Sources/SwiftDriver/Jobs/MergeModuleJob.swift @@ -67,6 +67,7 @@ extension Driver { tool: .absolute(try toolchain.getToolPath(.swiftCompiler)), commandLine: commandLine, inputs: inputs, + primaryInputs: [], outputs: outputs, supportsResponseFiles: true ) diff --git a/Sources/SwiftDriver/Jobs/ModuleWrapJob.swift b/Sources/SwiftDriver/Jobs/ModuleWrapJob.swift index 596bcecf6..068eaa16c 100644 --- a/Sources/SwiftDriver/Jobs/ModuleWrapJob.swift +++ b/Sources/SwiftDriver/Jobs/ModuleWrapJob.swift @@ -32,6 +32,7 @@ extension Driver { tool: .absolute(try toolchain.getToolPath(.swiftCompiler)), commandLine: commandLine, inputs: [moduleInput], + primaryInputs: [], outputs: [.init(file: outputPath, type: .object)], supportsResponseFiles: true ) diff --git a/Sources/SwiftDriver/Jobs/Planning.swift b/Sources/SwiftDriver/Jobs/Planning.swift index 29dc9a3d2..e084bc986 100644 --- a/Sources/SwiftDriver/Jobs/Planning.swift +++ b/Sources/SwiftDriver/Jobs/Planning.swift @@ -472,6 +472,7 @@ extension Driver { tool: .absolute(try toolchain.getToolPath(.swiftCompiler)), commandLine: [.flag("--version")], inputs: [], + primaryInputs: [], outputs: [], requiresInPlaceExecution: true) } @@ -487,6 +488,7 @@ extension Driver { tool: .absolute(try toolchain.getToolPath(.swiftHelp)), commandLine: commandLine, inputs: [], + primaryInputs: [], outputs: [], requiresInPlaceExecution: true) } diff --git a/Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift b/Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift index bba2da1c9..3425b8a54 100644 --- a/Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift +++ b/Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift @@ -165,6 +165,7 @@ extension Toolchain { commandLine: commandLine, displayInputs: [], inputs: [], + primaryInputs: [], outputs: [.init(file: .standardOutput, type: .jsonTargetInfo)], requiresInPlaceExecution: requiresInPlaceExecution, supportsResponseFiles: false diff --git a/Sources/SwiftDriver/Jobs/ReplJob.swift b/Sources/SwiftDriver/Jobs/ReplJob.swift index f82331d86..df6848b37 100644 --- a/Sources/SwiftDriver/Jobs/ReplJob.swift +++ b/Sources/SwiftDriver/Jobs/ReplJob.swift @@ -29,6 +29,7 @@ extension Driver { tool: .absolute(try toolchain.getToolPath(.lldb)), commandLine: [Job.ArgTemplate.flag(lldbArg)], inputs: inputs, + primaryInputs: [], outputs: [], requiresInPlaceExecution: true ) diff --git a/Sources/SwiftDriver/Jobs/VerifyDebugInfoJob.swift b/Sources/SwiftDriver/Jobs/VerifyDebugInfoJob.swift index 33705d7dd..86268cbb4 100644 --- a/Sources/SwiftDriver/Jobs/VerifyDebugInfoJob.swift +++ b/Sources/SwiftDriver/Jobs/VerifyDebugInfoJob.swift @@ -27,6 +27,7 @@ extension Driver { commandLine: commandLine, displayInputs: [], inputs: inputs, + primaryInputs: [], outputs: [] ) } diff --git a/Sources/SwiftDriver/Jobs/VerifyModuleInterfaceJob.swift b/Sources/SwiftDriver/Jobs/VerifyModuleInterfaceJob.swift index 93d876e09..e506c548c 100644 --- a/Sources/SwiftDriver/Jobs/VerifyModuleInterfaceJob.swift +++ b/Sources/SwiftDriver/Jobs/VerifyModuleInterfaceJob.swift @@ -34,6 +34,7 @@ extension Driver { commandLine: commandLine, displayInputs: [], inputs: [interfaceInput], + primaryInputs: [], outputs: [outputFile] ) } diff --git a/Tests/SwiftDriverTests/JobExecutorTests.swift b/Tests/SwiftDriverTests/JobExecutorTests.swift index f892f0448..20cf9c379 100644 --- a/Tests/SwiftDriverTests/JobExecutorTests.swift +++ b/Tests/SwiftDriverTests/JobExecutorTests.swift @@ -113,6 +113,11 @@ final class JobExecutorTests: XCTestCase { .relative(RelativePath("main")): exec.pathString, ] + let inputs: [String: TypedVirtualPath] = [ + "foo" : .init(file: .relative(RelativePath( "foo.swift")), type: .swift), + "main": .init(file: .relative(RelativePath("main.swift")), type: .swift) + ] + let compileFoo = Job( moduleName: "main", kind: .compile, @@ -121,8 +126,8 @@ final class JobExecutorTests: XCTestCase { "-frontend", "-c", "-primary-file", - .path(.relative(RelativePath("foo.swift"))), - .path(.relative(RelativePath("main.swift"))), + .path(inputs[ "foo"]!.file), + .path(inputs["main"]!.file), "-target", "x86_64-apple-darwin18.7.0", "-enable-objc-interop", "-sdk", @@ -130,10 +135,8 @@ final class JobExecutorTests: XCTestCase { "-module-name", "main", "-o", .path(.temporary(RelativePath("foo.o"))), ], - inputs: [ - .init(file: .relative(RelativePath("foo.swift")), type: .swift), - .init(file: .relative(RelativePath("main.swift")), type: .swift), - ], + inputs: Array(inputs.values), + primaryInputs: [inputs["foo"]!], outputs: [.init(file: .temporary(RelativePath("foo.o")), type: .object)] ) @@ -146,7 +149,7 @@ final class JobExecutorTests: XCTestCase { "-c", .path(.relative(RelativePath("foo.swift"))), "-primary-file", - .path(.relative(RelativePath("main.swift"))), + .path(inputs["main"]!.file), "-target", "x86_64-apple-darwin18.7.0", "-enable-objc-interop", "-sdk", @@ -154,10 +157,8 @@ final class JobExecutorTests: XCTestCase { "-module-name", "main", "-o", .path(.temporary(RelativePath("main.o"))), ], - inputs: [ - .init(file: .relative(RelativePath("foo.swift")), type: .swift), - .init(file: .relative(RelativePath("main.swift")), type: .swift), - ], + inputs: Array(inputs.values), + primaryInputs: [inputs["main"]!], outputs: [.init(file: .temporary(RelativePath("main.o")), type: .object)] ) @@ -182,6 +183,7 @@ final class JobExecutorTests: XCTestCase { .init(file: .temporary(RelativePath("foo.o")), type: .object), .init(file: .temporary(RelativePath("main.o")), type: .object), ], + primaryInputs: [], outputs: [.init(file: .relative(RelativePath("main")), type: .image)] ) @@ -213,6 +215,7 @@ final class JobExecutorTests: XCTestCase { tool: .absolute(AbsolutePath("/usr/bin/swift")), commandLine: [.flag("something")], inputs: [], + primaryInputs: [], outputs: [.init(file: .temporary(RelativePath("main")), type: .object)] ) diff --git a/Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift b/Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift index 982906859..12984528a 100644 --- a/Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift +++ b/Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift @@ -1311,8 +1311,9 @@ extension Job { kind: .compile, tool: VirtualPath(path: ""), commandLine: [], - inputs: [TypedVirtualPath(file: VirtualPath(path: dummyBaseName + ".swift" ), type: .swift )], - outputs: [TypedVirtualPath(file: VirtualPath(path: dummyBaseName + ".swiftdeps"), type: .swiftDeps)]) + inputs: [TypedVirtualPath(file: VirtualPath(path: dummyBaseName + ".swift" ), type: .swift )], + primaryInputs: [TypedVirtualPath(file: VirtualPath(path: dummyBaseName + ".swift" ), type: .swift )], + outputs: [TypedVirtualPath(file: VirtualPath(path: dummyBaseName + ".swiftdeps"), type: .swiftDeps)]) } }