3
3
import Foundation
4
4
import PackageDescription
5
5
6
+ // MARK: - Parse build arguments
7
+
8
+ func hasEnvironmentVariable( _ name: String ) -> Bool {
9
+ return ProcessInfo . processInfo. environment [ name] != nil
10
+ }
11
+
12
+ /// Set when building swift-syntax using swift-syntax-dev-utils or in Swift CI in general.
13
+ ///
14
+ /// Modifies the build in the following ways
15
+ /// - Enables assertions even in release builds
16
+ /// - Removes the dependency of swift-syntax on os_log
17
+ /// - Enables raw syntax validation (ie. implies `SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION`)
18
+ /// - Enables alternate token introspection (ie. implies `SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION`)
19
+ let buildScriptEnvironment = hasEnvironmentVariable ( " SWIFT_BUILD_SCRIPT_ENVIRONMENT " )
20
+
21
+ /// Check that the layout of the syntax tree is correct.
22
+ ///
23
+ /// See CONTRIBUTING.md for more information
24
+ let rawSyntaxValidation = hasEnvironmentVariable ( " SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION " )
25
+
26
+ /// Mutate the input of `assertParse` test cases.
27
+ ///
28
+ /// See CONTRIBUTING.md for more information
29
+ let alternateTokenIntrospection = hasEnvironmentVariable ( " SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION " )
30
+
31
+ /// Assume that swift-argument-parser is checked out next to swift-syntax and use that instead of fetching a remote dependency.
32
+ let useLocalDependencies = hasEnvironmentVariable ( " SWIFTCI_USE_LOCAL_DEPS " )
33
+
34
+ // MARK: - Compute custom build settings
35
+
36
+ // These build settings apply to the target and the corresponding test target.
6
37
var swiftSyntaxSwiftSettings : [ SwiftSetting ] = [ ]
7
38
var swiftSyntaxBuilderSwiftSettings : [ SwiftSetting ] = [ ]
8
39
var swiftParserSwiftSettings : [ SwiftSetting ] = [ ]
9
40
10
- /// If we are in a controlled CI environment, we can use internal compiler flags
11
- /// to speed up the build or improve it.
12
- if ProcessInfo . processInfo. environment [ " SWIFT_BUILD_SCRIPT_ENVIRONMENT " ] != nil {
41
+ if buildScriptEnvironment {
13
42
swiftSyntaxSwiftSettings += [
14
43
. define( " SWIFTSYNTAX_ENABLE_ASSERTIONS " )
15
44
]
16
45
swiftSyntaxBuilderSwiftSettings += [
17
46
. define( " SWIFTSYNTAX_NO_OSLOG_DEPENDENCY " )
18
47
]
19
- swiftParserSwiftSettings += [
20
- . define( " SWIFTSYNTAX_NO_OSLOG_DEPENDENCY " )
21
- ]
22
48
}
23
49
24
- if ProcessInfo . processInfo . environment [ " SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION " ] != nil {
50
+ if rawSyntaxValidation {
25
51
swiftSyntaxSwiftSettings += [
26
52
. define( " SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION " )
27
53
]
28
54
}
29
55
30
- if ProcessInfo . processInfo . environment [ " SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION " ] != nil {
56
+ if alternateTokenIntrospection {
31
57
swiftParserSwiftSettings += [
32
58
. define( " SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION " )
33
59
]
34
60
}
35
61
62
+ // MARK: - Build the package
63
+
36
64
let package = Package (
37
65
name: " swift-syntax " ,
38
66
platforms: [
@@ -153,10 +181,11 @@ let package = Package(
153
181
154
182
. testTarget(
155
183
name: " SwiftSyntaxTest " ,
156
- dependencies: [ " _SwiftSyntaxTestSupport " , " SwiftSyntax " , " SwiftSyntaxBuilder " ]
184
+ dependencies: [ " _SwiftSyntaxTestSupport " , " SwiftSyntax " , " SwiftSyntaxBuilder " ] ,
185
+ swiftSettings: swiftSyntaxSwiftSettings
157
186
) ,
158
187
159
- // MARK: Verison marker modules
188
+ // MARK: Version marker modules
160
189
161
190
. target(
162
191
name: " SwiftSyntax509 " ,
@@ -174,7 +203,8 @@ let package = Package(
174
203
175
204
. testTarget(
176
205
name: " SwiftSyntaxBuilderTest " ,
177
- dependencies: [ " _SwiftSyntaxTestSupport " , " SwiftSyntaxBuilder " ]
206
+ dependencies: [ " _SwiftSyntaxTestSupport " , " SwiftSyntaxBuilder " ] ,
207
+ swiftSettings: swiftSyntaxBuilderSwiftSettings
178
208
) ,
179
209
180
210
// MARK: SwiftSyntaxMacros
@@ -303,7 +333,7 @@ package.targets.append(
303
333
)
304
334
)
305
335
306
- if ProcessInfo . processInfo . environment [ " SWIFTCI_USE_LOCAL_DEPS " ] == nil {
336
+ if useLocalDependencies {
307
337
// Building standalone.
308
338
package . dependencies += [
309
339
. package ( url: " https://github.com/apple/swift-argument-parser.git " , from: " 1.2.2 " )
0 commit comments