forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackage.swift
150 lines (124 loc) · 4.29 KB
/
Package.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// swift-tools-version:5.0
import PackageDescription
import Foundation
var unsupportedTests: Set<String> = ["ObjectiveCNoBridgingStubs"]
#if !os(macOS) && !os(iOS) && !os(watchOS) && !os(tvOS)
unsupportedTests.insert("ObjectiveCBridging")
unsupportedTests.insert("ObjectiveCBridgingStubs")
#endif
//===---
// Single Source Libraries
//
/// Return the source files in subDirectory that we will translate into
/// libraries. Each source library will be compiled as its own module.
func getSingleSourceLibraries(subDirectory: String) -> [String] {
let f = FileManager.`default`
let dirURL = URL(fileURLWithPath: subDirectory)
let fileURLs = try! f.contentsOfDirectory(at: dirURL,
includingPropertiesForKeys: nil)
return fileURLs.compactMap { (path: URL) -> String? in
let c = path.lastPathComponent.split(separator: ".")
// Too many components. Must be a gyb file.
if c.count > 2 {
return nil
}
if c[1] != "swift" {
return nil
}
let name = String(c[0])
// We do not support this test.
if unsupportedTests.contains(name) {
return nil
}
return name
}
}
var singleSourceLibraryDirs: [String] = []
singleSourceLibraryDirs.append("single-source")
var singleSourceLibraries: [String] = singleSourceLibraryDirs.flatMap {
getSingleSourceLibraries(subDirectory: $0)
}
//===---
// Multi Source Libraries
//
func getMultiSourceLibraries(subDirectory: String) -> [(String, String)] {
let f = FileManager.`default`
let dirURL = URL(string: subDirectory)!
let subDirs = try! f.contentsOfDirectory(at: dirURL, includingPropertiesForKeys: nil)
return subDirs.map { (subDirectory, $0.lastPathComponent) }
}
var multiSourceLibraryDirs: [String] = []
multiSourceLibraryDirs.append("multi-source")
var multiSourceLibraries: [(parentSubDir: String, name: String)] = multiSourceLibraryDirs.flatMap {
getMultiSourceLibraries(subDirectory: $0)
}
//===---
// Products
//
var products: [Product] = []
products.append(.library(name: "TestsUtils", type: .static, targets: ["TestsUtils"]))
products.append(.library(name: "DriverUtils", type: .static, targets: ["DriverUtils"]))
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
products.append(.library(name: "ObjectiveCTests", type: .static, targets: ["ObjectiveCTests"]))
#endif
products.append(.executable(name: "SwiftBench", targets: ["SwiftBench"]))
products += singleSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) }
products += multiSourceLibraries.map {
return .library(name: $0.name, type: .static, targets: [$0.name])
}
//===---
// Targets
//
var targets: [Target] = []
targets.append(.target(name: "TestsUtils", path: "utils", sources: ["TestsUtils.swift"]))
targets.append(.systemLibrary(name: "LibProc", path: "utils/LibProc"))
targets.append(
.target(name: "DriverUtils",
dependencies: [.target(name: "TestsUtils"), "LibProc"],
path: "utils",
sources: ["DriverUtils.swift", "ArgParse.swift"]))
var swiftBenchDeps: [Target.Dependency] = [.target(name: "TestsUtils")]
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
swiftBenchDeps.append(.target(name: "ObjectiveCTests"))
#endif
swiftBenchDeps.append(.target(name: "DriverUtils"))
swiftBenchDeps += singleSourceLibraries.map { .target(name: $0) }
swiftBenchDeps += multiSourceLibraries.map { .target(name: $0.name) }
targets.append(
.target(name: "SwiftBench",
dependencies: swiftBenchDeps,
path: "utils",
sources: ["main.swift"]))
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
targets.append(
.target(name: "ObjectiveCTests",
path: "utils/ObjectiveCTests",
publicHeadersPath: "."))
#endif
var singleSourceDeps: [Target.Dependency] = [.target(name: "TestsUtils")]
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
singleSourceDeps.append(.target(name: "ObjectiveCTests"))
#endif
targets += singleSourceLibraries.map { name in
return .target(name: name,
dependencies: singleSourceDeps,
path: "single-source",
sources: ["\(name).swift"])
}
targets += multiSourceLibraries.map { lib in
return .target(
name: lib.name,
dependencies: [
.target(name: "TestsUtils")
],
path: lib.parentSubDir)
}
//===---
// Top Level Definition
//
let p = Package(
name: "swiftbench",
products: products,
targets: targets,
swiftLanguageVersions: [.v4]
)