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
+ let buildScriptEnvironment = hasEnvironmentVariable ( " SWIFT_BUILD_SCRIPT_ENVIRONMENT " )
18
+
19
+ /// Check that the layout of the syntax tree is correct.
20
+ ///
21
+ /// See CONTRIBUTING.md for more information
22
+ let rawSyntaxValidation = hasEnvironmentVariable ( " SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION " )
23
+
24
+ /// Mutate the input of `assertParse` test cases.
25
+ ///
26
+ /// See CONTRIBUTING.md for more information
27
+ let alternateTokenIntrospection = hasEnvironmentVariable ( " SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION " )
28
+
29
+ /// Assume that swift-argument-parser is checked out next to swift-syntax and use that instead of fetching a remote dependency.
30
+ let useLocalDependencies = hasEnvironmentVariable ( " SWIFTCI_USE_LOCAL_DEPS " )
31
+
32
+ // MARK: - Compute custom build settings
33
+
34
+ // These build settings apply to the target and the corresponding test target.
6
35
var swiftSyntaxSwiftSettings : [ SwiftSetting ] = [ ]
7
36
var swiftSyntaxBuilderSwiftSettings : [ SwiftSetting ] = [ ]
8
37
var swiftParserSwiftSettings : [ SwiftSetting ] = [ ]
9
38
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 {
39
+ if buildScriptEnvironment {
13
40
swiftSyntaxSwiftSettings += [
14
41
. define( " SWIFTSYNTAX_ENABLE_ASSERTIONS " )
15
42
]
16
43
swiftSyntaxBuilderSwiftSettings += [
17
44
. define( " SWIFTSYNTAX_NO_OSLOG_DEPENDENCY " )
18
45
]
19
- swiftParserSwiftSettings += [
20
- . define( " SWIFTSYNTAX_NO_OSLOG_DEPENDENCY " )
21
- ]
22
46
}
23
47
24
- if ProcessInfo . processInfo . environment [ " SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION " ] != nil {
48
+ if rawSyntaxValidation {
25
49
swiftSyntaxSwiftSettings += [
26
50
. define( " SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION " )
27
51
]
28
52
}
29
53
30
- if ProcessInfo . processInfo . environment [ " SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION " ] != nil {
54
+ if alternateTokenIntrospection {
31
55
swiftParserSwiftSettings += [
32
56
. define( " SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION " )
33
57
]
34
58
}
35
59
60
+ // MARK: - Build the package
61
+
36
62
let package = Package (
37
63
name: " swift-syntax " ,
38
64
platforms: [
@@ -153,10 +179,11 @@ let package = Package(
153
179
154
180
. testTarget(
155
181
name: " SwiftSyntaxTest " ,
156
- dependencies: [ " _SwiftSyntaxTestSupport " , " SwiftSyntax " , " SwiftSyntaxBuilder " ]
182
+ dependencies: [ " _SwiftSyntaxTestSupport " , " SwiftSyntax " , " SwiftSyntaxBuilder " ] ,
183
+ swiftSettings: swiftSyntaxSwiftSettings
157
184
) ,
158
185
159
- // MARK: Verison marker modules
186
+ // MARK: Version marker modules
160
187
161
188
. target(
162
189
name: " SwiftSyntax509 " ,
@@ -174,7 +201,8 @@ let package = Package(
174
201
175
202
. testTarget(
176
203
name: " SwiftSyntaxBuilderTest " ,
177
- dependencies: [ " _SwiftSyntaxTestSupport " , " SwiftSyntaxBuilder " ]
204
+ dependencies: [ " _SwiftSyntaxTestSupport " , " SwiftSyntaxBuilder " ] ,
205
+ swiftSettings: swiftSyntaxBuilderSwiftSettings
178
206
) ,
179
207
180
208
// MARK: SwiftSyntaxMacros
@@ -303,7 +331,7 @@ package.targets.append(
303
331
)
304
332
)
305
333
306
- if ProcessInfo . processInfo . environment [ " SWIFTCI_USE_LOCAL_DEPS " ] == nil {
334
+ if useLocalDependencies {
307
335
// Building standalone.
308
336
package . dependencies += [
309
337
. package ( url: " https://github.com/apple/swift-argument-parser.git " , from: " 1.2.2 " )
0 commit comments