@@ -12,6 +12,8 @@ import func POSIX.getenv
12
12
import func POSIX. mkdir
13
13
import PackageType
14
14
import Utility
15
+ import func POSIX. fopen
16
+ import func libc. fclose
15
17
16
18
/**
17
19
- Returns: path to generated YAML for consumption by the llbuild based swift-build-tool
@@ -25,25 +27,20 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
25
27
let Xcc = Xcc . flatMap { [ " -Xcc " , $0] }
26
28
let Xld = Xld . flatMap { [ " -Xlinker " , $0] }
27
29
let prefix = try mkdir ( prefix, conf. dirname)
28
- let yaml = try YAML ( path: " \( prefix) .yaml " )
29
- let write = yaml. write
30
30
31
- let ( buildableTests, buildableNonTests) = ( modules. map { $0 as Buildable } + products. map { $0 as Buildable } ) . partition { $0. isTest}
32
- let ( tests, nontests) = ( buildableTests. map { $0. targetName} , buildableNonTests. map { $0. targetName} )
33
-
34
- defer { yaml. close ( ) }
35
-
36
- try write ( " client: " )
37
- try write ( " name: swift-build " )
38
- try write ( " tools: {} " )
39
- try write ( " targets: " )
40
- try write ( " default: " , nontests)
41
- try write ( " test: " , tests)
42
- try write ( " commands: " )
31
+ var nonTests = [ Command] ( )
32
+ var tests = [ Command] ( )
33
+
34
+ /// Appends the command to appropriate array
35
+ func append( command: Command , buildable: Buildable ) {
36
+ if buildable. isTest {
37
+ tests. append ( command)
38
+ } else {
39
+ nonTests. append ( command)
40
+ }
41
+ }
43
42
44
43
var mkdirs = Set < String > ( )
45
-
46
-
47
44
let swiftcArgs = Xcc + Xswiftc
48
45
49
46
for case let module as SwiftModule in modules {
@@ -65,23 +62,22 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
65
62
#endif
66
63
67
64
let node = IncrementalNode ( module: module, prefix: prefix)
68
-
69
- try write ( " " , module. targetName, " : " )
70
- try write ( " tool: swift-compiler " )
71
- try write ( " executable: " , Resources . path. swiftc)
72
- try write ( " module-name: " , module. c99name)
73
- try write ( " module-output-path: " , node. moduleOutputPath)
74
- try write ( " inputs: " , node. inputs)
75
- try write ( " outputs: " , node. outputs)
76
- try write ( " import-paths: " , prefix)
77
- try write ( " temps-path: " , node. tempsPath)
78
- try write ( " objects: " , node. objectPaths)
79
- try write ( " other-args: " , args + otherArgs)
80
- try write ( " sources: " , module. sources. paths)
81
-
82
- // this must be set or swiftc compiles single source file
83
- // modules with a main() for some reason
84
- try write ( " is-library: " , module. type == . Library)
65
+ let swiftc = SwiftcTool (
66
+ inputs: node. inputs,
67
+ outputs: node. outputs,
68
+ executable: Resources . path. swiftc,
69
+ moduleName: module. c99name,
70
+ moduleOutputPath: node. moduleOutputPath,
71
+ importPaths: prefix,
72
+ tempsPath: node. tempsPath,
73
+ objects: node. objectPaths,
74
+ otherArgs: args + otherArgs,
75
+ sources: module. sources. paths,
76
+ isLibrary: module. type == . Library) /// this must be set or swiftc compiles single source
77
+ /// file modules with a main() for some reason
78
+
79
+ let command = Command ( name: module. targetName, tool: swiftc)
80
+ append ( command, buildable: module)
85
81
86
82
for o in node. objectPaths {
87
83
mkdirs. insert ( o. parentDirectory)
@@ -96,12 +92,14 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
96
92
args += [ " -parse-as-library " ]
97
93
}
98
94
99
- try write ( " " , module. targetName, " : " )
100
- try write ( " tool: shell " )
101
- try write ( " description: Compiling \( module. name) " )
102
- try write ( " inputs: " , inputs)
103
- try write ( " outputs: " , [ productPath, module. targetName] )
104
- try write ( " args: " , [ Resources . path. swiftc, " -o " , productPath] + args + module. sources. paths + otherArgs)
95
+ let shell = ShellTool (
96
+ description: " Compiling \( module. name) " ,
97
+ inputs: inputs,
98
+ outputs: [ productPath, module. targetName] ,
99
+ args: [ Resources . path. swiftc, " -o " , productPath] + args + module. sources. paths + otherArgs)
100
+
101
+ let command = Command ( name: module. targetName, tool: shell)
102
+ append ( command, buildable: module)
105
103
}
106
104
}
107
105
@@ -178,15 +176,30 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
178
176
179
177
let inputs = product. modules. flatMap { [ $0. targetName] + IncrementalNode( module: $0, prefix: prefix) . inputs }
180
178
181
- try write ( " \( product. targetName) : " )
182
- try write ( " tool: shell " )
183
- try write ( " description: Linking \( product) " )
184
- try write ( " inputs: " , inputs)
185
- try write ( " outputs: " , [ product. targetName, outpath] )
186
- try write ( " args: " , args)
179
+ let shell = ShellTool (
180
+ description: " Linking \( product) " ,
181
+ inputs: inputs,
182
+ outputs: [ product. targetName, outpath] ,
183
+ args: args)
184
+
185
+ let command = Command ( name: product. targetName, tool: shell)
186
+ append ( command, buildable: product)
187
187
}
188
188
189
- return yaml. path
189
+ //Create Targets
190
+ let nontestTarget = Target ( name: " default " , commands: nonTests)
191
+ let testTarget = Target ( name: " test " , commands: tests)
192
+
193
+ //Generate YAML String for the targets
194
+ let yamlString = llbuildYAML ( targets: [ nontestTarget, testTarget] )
195
+
196
+ //Write YAML to file
197
+ let yamlPath = " \( prefix) .yaml "
198
+ let fp = try fopen ( yamlPath, mode: . Write)
199
+ defer { fclose ( fp) }
200
+ try fputs ( yamlString, fp)
201
+
202
+ return yamlPath
190
203
}
191
204
192
205
0 commit comments