Skip to content

[Dependency Scanning] Adapt to upcoming dependency scanner API change s with the output path. #1198

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
Sep 26, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
// First, take the command line options provided in the dependency information
let moduleDetails = try dependencyGraph.clangModuleDetails(of: moduleId)
moduleDetails.commandLine.forEach { commandLine.appendFlags($0) }

// Add the `-target` option as inherited from the dependent Swift module's PCM args
pcmArgs.forEach { commandLine.appendFlags($0) }

Expand All @@ -243,6 +243,11 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
commandLine.appendFlags("-emit-pcm", "-module-name", moduleId.moduleName,
"-o", targetEncodedModulePath.description)

// Fixup "-o -Xcc -Xclang -Xcc '<replace-me>'"
if let outputIndex = commandLine.firstIndex(of: .flag("<replace-me>")) {
commandLine[outputIndex] = .path(VirtualPath.lookup(targetEncodedModulePath))
}

// The only required input is the .modulemap for this module.
// Command line options in the dependency scanner output will include the
// required modulemap, so here we must only add it to the list of inputs.
Expand All @@ -269,8 +274,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
inputs: inout [TypedVirtualPath],
commandLine: inout [Job.ArgTemplate]) throws {
// Prohibit the frontend from implicitly building textual modules into binary modules.
commandLine.appendFlags("-disable-implicit-swift-modules", "-Xcc", "-Xclang", "-Xcc",
"-fno-implicit-modules", "-Xcc", "-Xclang", "-Xcc", "-fno-implicit-module-maps")
commandLine.appendFlags("-disable-implicit-swift-modules",
"-Xcc", "-Xclang", "-Xcc", "-fno-implicit-modules",
"-Xcc", "-Xclang", "-Xcc", "-fno-implicit-module-maps")
var swiftDependencyArtifacts: [SwiftModuleArtifactInfo] = []
var clangDependencyArtifacts: [ClangModuleArtifactInfo] = []
try addModuleDependencies(moduleId: moduleId, pcmArgs: pcmArgs,
Expand Down Expand Up @@ -298,11 +304,17 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
let clangModulePath =
TypedVirtualPath(file: moduleArtifactInfo.modulePath.path,
type: .pcm)
// If an existing dependency module path stub exists, replace it.
if let existingIndex = commandLine.firstIndex(of: .flag("-fmodule-file=" + moduleArtifactInfo.moduleName + "=<replace-me>")) {
commandLine[existingIndex] = .flag("-fmodule-file=\(moduleArtifactInfo.moduleName)=\(clangModulePath.file.description)")
} else {
commandLine.appendFlags("-Xcc", "-Xclang", "-Xcc",
"-fmodule-file=\(moduleArtifactInfo.moduleName)=\(clangModulePath.file.description)")
}

let clangModuleMapPath =
TypedVirtualPath(file: moduleArtifactInfo.moduleMapPath.path,
type: .clangModuleMap)
commandLine.appendFlags("-Xcc", "-Xclang", "-Xcc",
"-fmodule-file=\(moduleArtifactInfo.moduleName)=\(clangModulePath.file.description)")
commandLine.appendFlags("-Xcc", "-Xclang", "-Xcc",
"-fmodule-map-file=\(clangModuleMapPath.file.description)")
inputs.append(clangModulePath)
Expand Down
22 changes: 20 additions & 2 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ throws {
var downstreamPCMArgs = pcmArgs
switch moduleInfo.details {
case .swift(let swiftModuleDetails):
XCTAssertTrue(job.commandLine.contains(.flag(String("-disable-implicit-swift-modules"))))
downstreamPCMArgs = swiftModuleDetails.extraPcmArgs
let moduleInterfacePath =
TypedVirtualPath(file: swiftModuleDetails.moduleInterfacePath!.path,
Expand Down Expand Up @@ -64,7 +65,6 @@ throws {
XCTFail("Placeholder dependency found.")
}
// Ensure the frontend was prohibited from doing implicit module builds
XCTAssertTrue(job.commandLine.contains(.flag(String("-disable-implicit-swift-modules"))))
XCTAssertTrue(job.commandLine.contains(.flag(String("-fno-implicit-modules"))))
XCTAssertTrue(job.commandLine.contains(.flag(String("-fno-implicit-module-maps"))))

Expand Down Expand Up @@ -223,6 +223,24 @@ final class ExplicitModuleBuildTests: XCTestCase {
}
}

func testClangModuleOutputFixups() throws {
do {
var driver = try Driver(args: ["swiftc", "-explicit-module-build",
"-module-name", "testClangModuleOutputFixups",
"test.swift"])
let moduleDependencyGraph =
try JSONDecoder().decode(
InterModuleDependencyGraph.self,
from: ModuleDependenciesInputs.fastDependencyScannerOutput.data(using: .utf8)!)
driver.explicitDependencyBuildPlanner =
try ExplicitDependencyBuildPlanner(dependencyGraph: moduleDependencyGraph,
toolchain: driver.toolchain)
let modulePrebuildJobs = try driver.explicitDependencyBuildPlanner!.generateExplicitModuleDependenciesBuildJobs()
let c_simdJob = try XCTUnwrap(modulePrebuildJobs.first(where: { $0.descriptionForLifecycle == "Compiling Clang module c_simd" }))
XCTAssertFalse(c_simdJob.commandLine.contains(.flag("<replace-me>")))
}
}

func testModuleDependencyBuildCommandGenerationWithExternalFramework() throws {
do {
let externalDetails: ExternalTargetModuleDetailsMap =
Expand Down Expand Up @@ -492,7 +510,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
let interpretJob = interpretJobs[0]
XCTAssertTrue(interpretJob.requiresInPlaceExecution)
XCTAssertTrue(interpretJob.commandLine.contains(subsequence: ["-frontend", "-interpret"]))
XCTAssertTrue(interpretJob.commandLine.contains("-disable-implicit-swift-modules"))
//XCTAssertTrue(interpretJob.commandLine.contains("-disable-implicit-swift-modules"))
XCTAssertTrue(interpretJob.commandLine.contains(subsequence: ["-Xcc", "-Xclang", "-Xcc", "-fno-implicit-modules"]))

// Figure out which Triples to use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ enum ModuleDependenciesInputs {
"-remove-preceeding-explicit-module-build-incompatible-options",
"-fno-implicit-modules",
"-emit-module",
"-fmodule-name=c_simd"
"-fmodule-name=c_simd",
"-o",
"<replace-me>"
]
}
}
Expand Down