Skip to content

Commit f475a39

Browse files
authored
Merge pull request #123 from artemcm/End2EndExplicitModuleBuildTest
[Explicit Module Builds] Add end-to-end explicit module build compile test
2 parents 6fcc735 + d5c25cf commit f475a39

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
151151
$0 <<< "import G;"
152152
}
153153

154-
var pcmArgs9 = ["-Xcc","-target","-Xcc","x86_64-apple-macosx10.9"]
155-
var pcmArgs15 = ["-Xcc","-target","-Xcc","x86_64-apple-macosx10.15"]
156-
157154
let packageRootPath = URL(fileURLWithPath: #file).pathComponents
158155
.prefix(while: { $0 != "Tests" }).joined(separator: "/").dropFirst()
159156
let testInputsPath = packageRootPath + "/TestInputs"
@@ -164,12 +161,19 @@ final class ExplicitModuleBuildTests: XCTestCase {
164161
"-I", swiftModuleInterfacesPath,
165162
"-experimental-explicit-module-build",
166163
main.pathString])
164+
165+
let jobs = try driver.planBuild()
166+
// Figure out which Triples to use.
167+
let dependencyGraph = driver.explicitModuleBuildHandler!.dependencyGraph
168+
guard case .swift(let mainModuleSwiftDetails) = dependencyGraph.mainModule.details else {
169+
XCTFail("Main module does not have Swift details field")
170+
return
171+
}
172+
let pcmArgsCurrent = mainModuleSwiftDetails.extraPcmArgs!
173+
var pcmArgs9 = ["-Xcc","-target","-Xcc","x86_64-apple-macosx10.9"]
167174
if driver.targetTriple.isDarwin {
168175
pcmArgs9.append(contentsOf: ["-Xcc", "-fapinotes-swift-version=5"])
169-
pcmArgs15.append(contentsOf: ["-Xcc", "-fapinotes-swift-version=5"])
170176
}
171-
let jobs = try driver.planBuild()
172-
let dependencyGraph = driver.explicitModuleBuildHandler!.dependencyGraph
173177
for job in jobs {
174178
XCTAssertEqual(job.outputs.count, 1)
175179
switch (job.outputs[0].file) {
@@ -188,22 +192,22 @@ final class ExplicitModuleBuildTests: XCTestCase {
188192
case .relative(RelativePath("SwiftOnoneSupport.swiftmodule")):
189193
try checkExplicitModuleBuildJob(job: job, moduleId: .swift("SwiftOnoneSupport"),
190194
moduleDependencyGraph: dependencyGraph)
191-
case .relative(try pcmArgsEncodedRelativeModulePath(for: "A", with: pcmArgs15)):
195+
case .relative(try pcmArgsEncodedRelativeModulePath(for: "A", with: pcmArgsCurrent)):
192196
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("A"),
193197
moduleDependencyGraph: dependencyGraph)
194-
case .relative(try pcmArgsEncodedRelativeModulePath(for: "B", with: pcmArgs15)):
198+
case .relative(try pcmArgsEncodedRelativeModulePath(for: "B", with: pcmArgsCurrent)):
195199
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("B"),
196200
moduleDependencyGraph: dependencyGraph)
197-
case .relative(try pcmArgsEncodedRelativeModulePath(for: "C", with: pcmArgs15)):
201+
case .relative(try pcmArgsEncodedRelativeModulePath(for: "C", with: pcmArgsCurrent)):
198202
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("C"),
199203
moduleDependencyGraph: dependencyGraph)
200-
case .relative(try pcmArgsEncodedRelativeModulePath(for: "G", with: pcmArgs15)):
204+
case .relative(try pcmArgsEncodedRelativeModulePath(for: "G", with: pcmArgsCurrent)):
201205
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("G"),
202206
moduleDependencyGraph: dependencyGraph)
203207
case .relative(try pcmArgsEncodedRelativeModulePath(for: "SwiftShims", with: pcmArgs9)):
204208
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("SwiftShims"),
205209
moduleDependencyGraph: dependencyGraph)
206-
case .relative(try pcmArgsEncodedRelativeModulePath(for: "SwiftShims", with: pcmArgs15)):
210+
case .relative(try pcmArgsEncodedRelativeModulePath(for: "SwiftShims", with: pcmArgsCurrent)):
207211
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("SwiftShims"),
208212
moduleDependencyGraph: dependencyGraph)
209213
case .temporary(RelativePath("main.o")):
@@ -223,4 +227,36 @@ final class ExplicitModuleBuildTests: XCTestCase {
223227
}
224228
}
225229
}
230+
231+
func testExplicitModuleBuildEndToEnd() throws {
232+
// The macOS-only restriction is temporary while Clang's dependency scanner
233+
// is gaining the ability to perform name-based module lookup.
234+
#if os(macOS)
235+
try withTemporaryDirectory { path in
236+
try localFileSystem.changeCurrentWorkingDirectory(to: path)
237+
let main = path.appending(component: "main.swift")
238+
try localFileSystem.writeFileContents(main) {
239+
$0 <<< "import C;"
240+
$0 <<< "import E;"
241+
$0 <<< "import G;"
242+
}
243+
244+
let packageRootPath = URL(fileURLWithPath: #file).pathComponents
245+
.prefix(while: { $0 != "Tests" }).joined(separator: "/").dropFirst()
246+
let testInputsPath = packageRootPath + "/TestInputs"
247+
let cHeadersPath : String = testInputsPath + "/ExplicitModuleBuilds/CHeaders"
248+
let swiftModuleInterfacesPath : String = testInputsPath + "/ExplicitModuleBuilds/Swift"
249+
var driver = try Driver(args: ["swiftc",
250+
"-I", cHeadersPath,
251+
"-I", swiftModuleInterfacesPath,
252+
"-experimental-explicit-module-build",
253+
"-working-directory", path.pathString,
254+
main.pathString])
255+
let jobs = try driver.planBuild()
256+
let resolver = try ArgsResolver(fileSystem: localFileSystem)
257+
try driver.run(jobs: jobs, resolver: resolver, processSet: ProcessSet())
258+
XCTAssertFalse(driver.diagnosticEngine.hasErrors)
259+
}
260+
#endif
261+
}
226262
}

0 commit comments

Comments
 (0)