Skip to content

[Explicit Moduel Builds] Adapt to swift-driver's InterModuleDependencyOracle API for cross-target dependency tracking #3042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2021
Merged
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
30 changes: 9 additions & 21 deletions Sources/Build/ManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,9 @@ extension LLBuildManifestBuilder {
ResolvedTarget.Dependency.target($0, conditions: [])
}
let allPackageDependencies = try topologicalSort(nodes, successors: { $0.dependencies })

// All modules discovered so far as a part of this package manifest.
// This includes modules that correspond to the package's own targets, package dependency
// targets, and modules that are discovered as dependencies of the above in individual
// dependency scanning actions
var discoveredModulesMap : SwiftDriver.ModuleInfoMap = [:]
// Instantiate the inter-module dependency oracle which will cache commonly-scanned
// modules across targets' Driver instances.
let dependencyOracle = InterModuleDependencyOracle()

// Create commands for all target descriptions in the plan.
for dependency in allPackageDependencies.reversed() {
Expand Down Expand Up @@ -349,7 +346,7 @@ extension LLBuildManifestBuilder {
switch description {
case .swift(let desc):
try self.createExplicitSwiftTargetCompileCommand(description: desc,
discoveredModulesMap: &discoveredModulesMap)
dependencyOracle: dependencyOracle)
case .clang(let desc):
try self.createClangCompileCommand(desc)
}
Expand All @@ -358,7 +355,7 @@ extension LLBuildManifestBuilder {

private func createExplicitSwiftTargetCompileCommand(
description: SwiftTargetBuildDescription,
discoveredModulesMap: inout SwiftDriver.ModuleInfoMap
dependencyOracle: InterModuleDependencyOracle
) throws {
// Inputs.
let inputs = try self.computeSwiftCompileCmdInputs(description)
Expand All @@ -370,7 +367,7 @@ extension LLBuildManifestBuilder {

// Commands.
try addExplicitBuildSwiftCmds(description, inputs: inputs,
discoveredModulesMap: &discoveredModulesMap)
dependencyOracle: dependencyOracle)

self.addTargetCmd(description, cmdOutputs: cmdOutputs)
self.addModuleWrapCmd(description)
Expand All @@ -379,7 +376,7 @@ extension LLBuildManifestBuilder {
private func addExplicitBuildSwiftCmds(
_ targetDescription: SwiftTargetBuildDescription,
inputs: [Node],
discoveredModulesMap: inout SwiftDriver.ModuleInfoMap
dependencyOracle: InterModuleDependencyOracle
) throws {
// Pass the driver its external dependencies (target dependencies)
var dependencyModulePathMap: SwiftDriver.ExternalTargetModulePathMap = [:]
Expand All @@ -398,18 +395,9 @@ extension LLBuildManifestBuilder {
env: ProcessEnv.vars)
var driver = try Driver(args: commandLine, fileSystem: targetDescription.fs,
executor: executor,
externalBuildArtifacts: (dependencyModulePathMap, discoveredModulesMap))

externalTargetModulePathMap: dependencyModulePathMap,
interModuleDependencyOracle: dependencyOracle)
let jobs = try driver.planBuild()

// Save the path to the target's module to be used by its dependents
// Save the dependency graph of this target to be used by its dependents
guard let dependencyGraph = driver.interModuleDependencyGraph else {
throw InternalError("Expected module dependency graph for target: \(targetDescription)")
}
try InterModuleDependencyGraph.mergeModules(from: dependencyGraph,
into: &discoveredModulesMap)

try addSwiftDriverJobs(for: targetDescription, jobs: jobs, inputs: inputs, resolver: resolver,
isMainModule: { driver.isExplicitMainModuleJob(job: $0)})
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ final class BuildPlanTests: XCTestCase {
let bSwift = bPath.appending(component: "B.swift")
let cSwift = cPath.appending(component: "C.swift")
try localFileSystem.writeFileContents(main) {
$0 <<< "baz()"
$0 <<< "baz();"
}
try localFileSystem.writeFileContents(aSwift) {
$0 <<< "import B"
$0 <<< "import C"
$0 <<< "import B;"
$0 <<< "import C;"
$0 <<< "public func baz() { bar() }"
}
try localFileSystem.writeFileContents(bSwift) {
$0 <<< "import C"
$0 <<< "import C;"
$0 <<< "public func bar() { foo() }"
}
try localFileSystem.writeFileContents(cSwift) {
Expand Down