1
- // swift-tools-version:4.2
1
+ // swift-tools-version:5.0
2
2
3
3
import PackageDescription
4
4
import Foundation
@@ -9,10 +9,15 @@ unsupportedTests.insert("ObjectiveCBridging")
9
9
unsupportedTests. insert ( " ObjectiveCBridgingStubs " )
10
10
#endif
11
11
12
- // This is a stop gap hack so we can edit benchmarks in Xcode.
13
- let singleSourceLibraries : [ String ] = {
12
+ //===---
13
+ // Single Source Libraries
14
+ //
15
+
16
+ /// Return the source files in subDirectory that we will translate into
17
+ /// libraries. Each source library will be compiled as its own module.
18
+ func getSingleSourceLibraries( subDirectory: String ) -> [ String ] {
14
19
let f = FileManager . `default`
15
- let dirURL = URL ( fileURLWithPath: " single-source " ) . absoluteURL
20
+ let dirURL = URL ( fileURLWithPath: subDirectory )
16
21
let fileURLs = try ! f. contentsOfDirectory ( at: dirURL,
17
22
includingPropertiesForKeys: nil )
18
23
return fileURLs. compactMap { ( path: URL ) -> String ? in
@@ -25,27 +30,45 @@ let singleSourceLibraries: [String] = {
25
30
return nil
26
31
}
27
32
28
- let s = String ( c [ 0 ] )
33
+ let name = String ( c [ 0 ] )
29
34
30
35
// We do not support this test.
31
- if unsupportedTests. contains ( s ) {
36
+ if unsupportedTests. contains ( name ) {
32
37
return nil
33
38
}
34
39
35
- assert ( s != " PrimsSplit " )
36
- return s
40
+ return name
37
41
}
38
- } ( )
42
+ }
43
+
44
+ var singleSourceLibraryDirs : [ String ] = [ ]
45
+ singleSourceLibraryDirs. append ( " single-source " )
46
+
47
+ var singleSourceLibraries : [ String ] = singleSourceLibraryDirs. flatMap {
48
+ getSingleSourceLibraries ( subDirectory: $0)
49
+ }
39
50
40
- let multiSourceLibraries : [ String ] = {
51
+ //===---
52
+ // Multi Source Libraries
53
+ //
54
+
55
+ func getMultiSourceLibraries( subDirectory: String ) -> [ ( String , String ) ] {
41
56
let f = FileManager . `default`
42
- let dirURL = URL ( fileURLWithPath: " multi-source " ) . absoluteURL
43
- let fileURLs = try ! f. contentsOfDirectory ( at: dirURL,
44
- includingPropertiesForKeys: nil )
45
- return fileURLs. map { ( path: URL ) -> String in
46
- return path. lastPathComponent
47
- }
48
- } ( )
57
+ let dirURL = URL ( string: subDirectory) !
58
+ let subDirs = try ! f. contentsOfDirectory ( at: dirURL, includingPropertiesForKeys: nil )
59
+ return subDirs. map { ( subDirectory, $0. lastPathComponent) }
60
+ }
61
+
62
+ var multiSourceLibraryDirs : [ String ] = [ ]
63
+ multiSourceLibraryDirs. append ( " multi-source " )
64
+
65
+ var multiSourceLibraries : [ ( parentSubDir: String , name: String ) ] = multiSourceLibraryDirs. flatMap {
66
+ getMultiSourceLibraries ( subDirectory: $0)
67
+ }
68
+
69
+ //===---
70
+ // Products
71
+ //
49
72
50
73
var products : [ Product ] = [ ]
51
74
products. append ( . library( name: " TestsUtils " , type: . static, targets: [ " TestsUtils " ] ) )
@@ -54,9 +77,15 @@ products.append(.library(name: "DriverUtils", type: .static, targets: ["DriverUt
54
77
products. append ( . library( name: " ObjectiveCTests " , type: . static, targets: [ " ObjectiveCTests " ] ) )
55
78
#endif
56
79
products. append ( . executable( name: " SwiftBench " , targets: [ " SwiftBench " ] ) )
57
- products . append ( . library ( name : " PrimsSplit " , type : . static , targets : [ " PrimsSplit " ] ) )
80
+
58
81
products += singleSourceLibraries. map { . library( name: $0, type: . static, targets: [ $0] ) }
59
- products += multiSourceLibraries. map { . library( name: $0, type: . static, targets: [ $0] ) }
82
+ products += multiSourceLibraries. map {
83
+ return . library( name: $0. name, type: . static, targets: [ $0. name] )
84
+ }
85
+
86
+ //===---
87
+ // Targets
88
+ //
60
89
61
90
var targets : [ Target ] = [ ]
62
91
targets. append ( . target( name: " TestsUtils " , path: " utils " , sources: [ " TestsUtils.swift " ] ) )
@@ -73,7 +102,7 @@ swiftBenchDeps.append(.target(name: "ObjectiveCTests"))
73
102
#endif
74
103
swiftBenchDeps. append ( . target( name: " DriverUtils " ) )
75
104
swiftBenchDeps += singleSourceLibraries. map { . target( name: $0) }
76
- swiftBenchDeps += multiSourceLibraries. map { . target( name: $0) }
105
+ swiftBenchDeps += multiSourceLibraries. map { . target( name: $0. name ) }
77
106
78
107
targets. append (
79
108
. target( name: " SwiftBench " ,
@@ -92,20 +121,27 @@ var singleSourceDeps: [Target.Dependency] = [.target(name: "TestsUtils")]
92
121
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
93
122
singleSourceDeps. append ( . target( name: " ObjectiveCTests " ) )
94
123
#endif
95
- targets += singleSourceLibraries. map { x in
96
- return . target( name: x,
124
+
125
+ targets += singleSourceLibraries. map { name in
126
+ return . target( name: name,
97
127
dependencies: singleSourceDeps,
98
128
path: " single-source " ,
99
- sources: [ " \( x ) .swift " ] )
129
+ sources: [ " \( name ) .swift " ] )
100
130
}
101
- targets += multiSourceLibraries. map { x in
102
- return . target( name: x,
131
+
132
+ targets += multiSourceLibraries. map { lib in
133
+ return . target(
134
+ name: lib. name,
103
135
dependencies: [
104
136
. target( name: " TestsUtils " )
105
137
] ,
106
- path: " multi-source/ \( x ) " )
138
+ path: lib . parentSubDir )
107
139
}
108
140
141
+ //===---
142
+ // Top Level Definition
143
+ //
144
+
109
145
let p = Package (
110
146
name: " swiftbench " ,
111
147
products: products,
0 commit comments