@@ -42,47 +42,90 @@ struct Context: CustomStringConvertible {
42
42
file: file, line: line)
43
43
}
44
44
45
- /// Each module has its own directory under the root
46
- private func modulePath( for module: Module ) -> AbsolutePath {
47
- rootDir. appending ( component: module. name)
48
- }
49
- func derivedDataPath( for module: Module ) -> AbsolutePath {
50
- modulePath ( for: module) . appending ( component: " \( module. name) DD " )
51
- }
52
- func sourceDir( for module: Module ) -> AbsolutePath {
53
- modulePath ( for: module)
45
+ var description : String {
46
+ " Incremental imports \( incrementalImports) "
54
47
}
55
- func swiftFilePath( for source: Source , in module: Module ) -> AbsolutePath {
56
- sourceDir ( for: module) . appending ( component: " \( source. name) .swift " )
48
+
49
+ func failMessage( _ step: Step ) -> String {
50
+ " \( description) , in step \( stepIndex) , \( step. whatIsBuilt) "
57
51
}
58
- func objFilePath( for source: Source , in module: Module ) -> AbsolutePath {
59
- derivedDataPath ( for: module) . appending ( component: " \( source. name) .o " )
52
+
53
+ func fail( _ msg: String , _ step: Step ) {
54
+ XCTFail ( " \( msg) \( failMessage ( step) ) " )
60
55
}
61
- func allObjFilePaths( in module: Module ) -> [ AbsolutePath ] {
62
- module. sources. map { objFilePath ( for: $0, in: module) }
56
+ }
57
+
58
+ // MARK: Paths
59
+
60
+ extension Context {
61
+ /// Computes the directory containing the given module's build products.
62
+ ///
63
+ /// - Parameter module: The module.
64
+ /// - Returns: An absolute path to the build root - relative to the root
65
+ /// directory of this test context.
66
+ func buildRoot( for module: Module ) -> AbsolutePath {
67
+ self . rootDir. appending ( component: " \( module. name) -buildroot " )
63
68
}
64
- func allImportedObjFilePaths( in module: Module ) -> [ AbsolutePath ] {
65
- module. imports. flatMap ( allObjFilePaths ( in: ) )
69
+
70
+ /// Computes the directory containing the given module's source files.
71
+ ///
72
+ /// - Parameter module: The module.
73
+ /// - Returns: An absolute path to the build root - relative to the root
74
+ /// directory of this test context.
75
+ func sourceRoot( for module: Module ) -> AbsolutePath {
76
+ self . rootDir. appending ( component: " \( module. name) -srcroot " )
66
77
}
78
+
79
+ /// Computes the path to the output file map for the given module.
80
+ ///
81
+ /// - Parameter module: The module.
82
+ /// - Returns: An absolute path to the output file map - relative to the root
83
+ /// directory of this test context.
67
84
func outputFileMapPath( for module: Module ) -> AbsolutePath {
68
- derivedDataPath ( for: module) . appending ( component: " OFM.json " )
85
+ self . buildRoot ( for: module) . appending ( component: " OFM " )
69
86
}
87
+
88
+ /// Computes the path to the `.swiftmodule` file for the given module.
89
+ ///
90
+ /// - Parameter module: The module.
91
+ /// - Returns: An absolute path to the swiftmodule file - relative to the root
92
+ /// directory of this test context.
70
93
func swiftmodulePath( for module: Module ) -> AbsolutePath {
71
- derivedDataPath ( for: module) . appending ( component: " \( module. name) .swiftmodule " )
72
- }
73
- func executablePath( for module: Module ) -> AbsolutePath {
74
- derivedDataPath ( for: module) . appending ( component: " a.out " )
94
+ self . buildRoot ( for: module) . appending ( component: " \( module. name) .swiftmodule " )
75
95
}
76
96
77
- var description : String {
78
- " Incremental imports \( incrementalImports) "
97
+ /// Computes the path to the `.swift` file for the given module.
98
+ ///
99
+ /// - Parameter source: The name of the swift file.
100
+ /// - Parameter module: The module.
101
+ /// - Returns: An absolute path to the swift file - relative to the root
102
+ /// directory of this test context.
103
+ func swiftFilePath( for source: Source , in module: Module ) -> AbsolutePath {
104
+ self . sourceRoot ( for: module) . appending ( component: " \( source. name) .swift " )
79
105
}
80
106
81
- func failMessage( _ step: Step ) -> String {
82
- " \( description) , in step \( stepIndex) , \( step. whatIsBuilt) "
107
+ /// Computes the path to the `.o` file for the given module.
108
+ ///
109
+ /// - Parameter source: The name of the swift file.
110
+ /// - Parameter module: The module.
111
+ /// - Returns: An absolute path to the object file - relative to the root
112
+ /// directory of this test context.
113
+ func objectFilePath( for source: Source , in module: Module ) -> AbsolutePath {
114
+ self . buildRoot ( for: module) . appending ( component: " \( source. name) .o " )
83
115
}
84
116
85
- func fail( _ msg: String , _ step: Step ) {
86
- XCTFail ( " \( msg) \( failMessage ( step) ) " )
117
+ /// Computes the path to the executable file for the given module.
118
+ ///
119
+ /// - Parameter module: The module.
120
+ /// - Returns: An absolute path to the executable file - relative to the root
121
+ /// directory of this test context.
122
+ func executablePath( for module: Module ) -> AbsolutePath {
123
+ #if os(Windows)
124
+ return self . buildRoot ( for: module) . appending ( component: " a.exe " )
125
+ #else
126
+ return self . buildRoot ( for: module) . appending ( component: " a.out " )
127
+ #endif
87
128
}
88
129
}
130
+
131
+
0 commit comments