Skip to content

Commit a32005e

Browse files
Merge pull request #1675 from cachemeifyoucan/eng/PR-84979778
Don't plan compileJob if emitModule is all that is needed in a separate job
2 parents ffbae26 + 50e4330 commit a32005e

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,9 @@ extension Driver {
470470
assert(backendJobs.count <= 1)
471471
addCompileJobGroup(CompileJobGroup(compileJob: compile, backendJob: backendJobs.first))
472472
} else {
473-
// TODO: if !canSkipIfOnlyModule {
474-
// Some other tools still expect the partial jobs. Bring this check
475-
// back once they are updated. rdar://84979778
476-
477473
// We can skip the compile jobs if all we want is a module when it's
478474
// built separately.
475+
if parsedOptions.hasArgument(.driverExplicitModuleBuild), canSkipIfOnlyModule { return }
479476
let compile = try compileJob(primaryInputs: [primaryInput],
480477
outputType: compilerOutputType,
481478
addJobOutputs: addJobOutputs,

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,44 @@ final class ExplicitModuleBuildTests: XCTestCase {
22752275
}
22762276
}
22772277

2278+
func testEmitModuleSeparatelyJobs() throws {
2279+
try withTemporaryDirectory { path in
2280+
try localFileSystem.changeCurrentWorkingDirectory(to: path)
2281+
let moduleCachePath = path.appending(component: "ModuleCache")
2282+
try localFileSystem.createDirectory(moduleCachePath)
2283+
let fileA = path.appending(component: "fileA.swift")
2284+
try localFileSystem.writeFileContents(fileA, bytes:
2285+
"""
2286+
public struct A {}
2287+
"""
2288+
)
2289+
let fileB = path.appending(component: "fileB.swift")
2290+
try localFileSystem.writeFileContents(fileB, bytes:
2291+
"""
2292+
public struct B {}
2293+
"""
2294+
)
2295+
2296+
let outputModule = path.appending(component: "Test.swiftmodule")
2297+
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
2298+
var driver = try Driver(args: ["swiftc",
2299+
"-explicit-module-build", "-v", "-module-name", "Test",
2300+
"-module-cache-path", moduleCachePath.nativePathString(escaped: true),
2301+
"-working-directory", path.nativePathString(escaped: true),
2302+
"-emit-module", outputModule.nativePathString(escaped: true),
2303+
"-experimental-emit-module-separately",
2304+
fileA.nativePathString(escaped: true), fileB.nativePathString(escaped: true)] + sdkArgumentsForTesting,
2305+
env: ProcessEnv.vars)
2306+
let jobs = try driver.planBuild()
2307+
let compileJobs = jobs.filter({ $0.kind == .compile })
2308+
XCTAssertEqual(compileJobs.count, 0)
2309+
let emitModuleJob = jobs.filter({ $0.kind == .emitModule })
2310+
XCTAssertEqual(emitModuleJob.count, 1)
2311+
try driver.run(jobs: jobs)
2312+
XCTAssertFalse(driver.diagnosticEngine.hasErrors)
2313+
}
2314+
}
2315+
22782316
// We only care about prebuilt modules in macOS.
22792317
#if os(macOS)
22802318
func testPrebuiltModuleGenerationJobs() throws {

0 commit comments

Comments
 (0)