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