@@ -15,11 +15,73 @@ import Foundation
1515import TSCBasic
1616import XCTest
1717
18+ /// Check that an explicit module build job contains expected inputs and options
19+ private func checkExplicitModuleBuildJob( job: Job ,
20+ moduleName: String ,
21+ moduleKind: ModuleDependencyId . CodingKeys ,
22+ moduleDependencyGraph: InterModuleDependencyGraph ) throws {
23+ let moduleId = ModuleDependencyId ( name: moduleName, kind: moduleKind)
24+ let moduleInfo = moduleDependencyGraph. modules [ moduleId] !
25+ switch moduleInfo. details {
26+ case . swift( let swiftModuleDetails) :
27+ let moduleInterfacePath =
28+ TypedVirtualPath ( file: try VirtualPath ( path: swiftModuleDetails. moduleInterfacePath!) ,
29+ type: . swiftInterface)
30+ XCTAssertEqual ( job. kind, . emitModule)
31+ XCTAssertTrue ( job. inputs. contains ( moduleInterfacePath) )
32+ case . clang( let clangModuleDetails) :
33+ let moduleMapPath =
34+ TypedVirtualPath ( file: try VirtualPath ( path: clangModuleDetails. moduleMapPath) ,
35+ type: . clangModuleMap)
36+ XCTAssertEqual ( job. kind, . generatePCM)
37+ XCTAssertTrue ( job. inputs. contains ( moduleMapPath) )
38+ }
39+ try checkExplicitModuleBuildJobDependencies ( job: job, moduleInfo: moduleInfo,
40+ moduleDependencyGraph: moduleDependencyGraph)
41+
42+ }
43+
44+ /// Checks that the build job for the specified module contains the required options and inputs
45+ /// to build all of its dependencies explicitly
46+ private func checkExplicitModuleBuildJobDependencies( job: Job ,
47+ moduleInfo : ModuleInfo ,
48+ moduleDependencyGraph: InterModuleDependencyGraph )
49+ throws {
50+ XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -disable-implicit-swift-modules " ) ) ) )
51+ XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -disable-implicit-pcms " ) ) ) )
52+ for dependencyId in moduleInfo. directDependencies {
53+ let dependencyInfo = moduleDependencyGraph. modules [ dependencyId] !
54+ switch dependencyInfo. details {
55+ case . swift:
56+ let swiftDependencyModulePath =
57+ TypedVirtualPath ( file: try VirtualPath ( path: moduleInfo. modulePath) ,
58+ type: . swiftModule)
59+ XCTAssertTrue ( job. inputs. contains ( swiftDependencyModulePath) )
60+ XCTAssertTrue ( job. commandLine. contains (
61+ . flag( String ( " -swift-module-file= \( moduleInfo. modulePath) " ) ) ) )
62+ case . clang( let clangDependencyDetails) :
63+ let clangDependencyModulePath =
64+ TypedVirtualPath ( file: try VirtualPath ( path: moduleInfo. modulePath) ,
65+ type: . pcm)
66+ let clangDependencyModuleMapPath =
67+ TypedVirtualPath ( file: try VirtualPath ( path: clangDependencyDetails. moduleMapPath) ,
68+ type: . pcm)
69+ XCTAssertTrue ( job. inputs. contains ( clangDependencyModulePath) )
70+ XCTAssertTrue ( job. inputs. contains ( clangDependencyModuleMapPath) )
71+ XCTAssertTrue ( job. commandLine. contains (
72+ . flag( String ( " -clang-module-file= \( moduleInfo. modulePath) " ) ) ) )
73+ XCTAssertTrue ( job. commandLine. contains (
74+ . flag( String ( " -clang-module-map-file= \( clangDependencyDetails. moduleMapPath) " ) ) ) )
75+ }
76+ }
77+ }
78+
1879/// Test that for the given JSON module dependency graph, valid jobs are generated
1980final class ExplicitModuleBuildTests : XCTestCase {
2081 func testModuleDependencyBuildCommandGeneration( ) throws {
2182 do {
22- var driver = try Driver ( args: [ " swiftc " , " -driver-print-module-dependencies-jobs " , " test.swift " ] )
83+ var driver = try Driver ( args: [ " swiftc " , " -driver-print-module-dependencies-jobs " ,
84+ " test.swift " ] )
2385 let moduleDependencyGraph =
2486 try JSONDecoder ( ) . decode (
2587 InterModuleDependencyGraph . self,
@@ -31,21 +93,21 @@ final class ExplicitModuleBuildTests: XCTestCase {
3193 XCTAssertEqual ( job. outputs. count, 1 )
3294 switch ( job. outputs [ 0 ] . file) {
3395 case . relative( RelativePath ( " SwiftShims.pcm " ) ) :
34- XCTAssertEqual ( job. kind , . generatePCM )
35- XCTAssertEqual ( job . inputs . count , 1 )
36- XCTAssertTrue ( job . inputs [ 0 ] . file . absolutePath! . pathString . contains ( " swift/shims/module.modulemap " ) )
96+ try checkExplicitModuleBuildJob ( job: job , moduleName : " SwiftShims " ,
97+ moduleKind : ModuleDependencyId . CodingKeys . clang ,
98+ moduleDependencyGraph : moduleDependencyGraph )
3799 case . relative( RelativePath ( " c_simd.pcm " ) ) :
38- XCTAssertEqual ( job. kind , . generatePCM )
39- XCTAssertEqual ( job . inputs . count , 1 )
40- XCTAssertTrue ( job . inputs [ 0 ] . file . absolutePath! . pathString . contains ( " clang-importer-sdk/usr/include/module.map " ) )
100+ try checkExplicitModuleBuildJob ( job: job , moduleName : " c_simd " ,
101+ moduleKind : ModuleDependencyId . CodingKeys . clang ,
102+ moduleDependencyGraph : moduleDependencyGraph )
41103 case . relative( RelativePath ( " Swift.swiftmodule " ) ) :
42- XCTAssertEqual ( job. kind , . emitModule )
43- XCTAssertEqual ( job . inputs . count , 1 )
44- XCTAssertTrue ( job . inputs [ 0 ] . file . absolutePath! . pathString . contains ( " Swift.swiftmodule/x86_64-apple-macos.swiftinterface " ) )
104+ try checkExplicitModuleBuildJob ( job: job , moduleName : " Swift " ,
105+ moduleKind : ModuleDependencyId . CodingKeys . swift ,
106+ moduleDependencyGraph : moduleDependencyGraph )
45107 case . relative( RelativePath ( " SwiftOnoneSupport.swiftmodule " ) ) :
46- XCTAssertEqual ( job. kind , . emitModule )
47- XCTAssertEqual ( job . inputs . count , 1 )
48- XCTAssertTrue ( job . inputs [ 0 ] . file . absolutePath! . pathString . contains ( " SwiftOnoneSupport.swiftmodule/x86_64-apple-macos.swiftinterface " ) )
108+ try checkExplicitModuleBuildJob ( job: job , moduleName : " SwiftOnoneSupport " ,
109+ moduleKind : ModuleDependencyId . CodingKeys . swift ,
110+ moduleDependencyGraph : moduleDependencyGraph )
49111 default :
50112 XCTFail ( " Unexpected module dependency build job output " )
51113 }
0 commit comments