|
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. |
35 |
| -var swiftSyntaxSwiftSettings: [SwiftSetting] = [] |
36 |
| -var swiftSyntaxBuilderSwiftSettings: [SwiftSetting] = [] |
37 |
| -var swiftParserSwiftSettings: [SwiftSetting] = [] |
38 |
| - |
39 |
| -if buildScriptEnvironment { |
40 |
| - swiftSyntaxSwiftSettings += [ |
41 |
| - .define("SWIFTSYNTAX_ENABLE_ASSERTIONS") |
42 |
| - ] |
43 |
| - swiftSyntaxBuilderSwiftSettings += [ |
44 |
| - .define("SWIFTSYNTAX_NO_OSLOG_DEPENDENCY") |
45 |
| - ] |
46 |
| -} |
47 |
| - |
48 |
| -if rawSyntaxValidation { |
49 |
| - swiftSyntaxSwiftSettings += [ |
50 |
| - .define("SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION") |
51 |
| - ] |
52 |
| -} |
53 |
| - |
54 |
| -if alternateTokenIntrospection { |
55 |
| - swiftParserSwiftSettings += [ |
56 |
| - .define("SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION") |
57 |
| - ] |
58 |
| -} |
59 |
| - |
60 |
| -// MARK: - Build the package |
61 |
| - |
62 | 6 | let package = Package(
|
63 | 7 | name: "swift-syntax",
|
64 | 8 | platforms: [
|
@@ -335,3 +279,57 @@ package.targets.append(
|
335 | 279 | }
|
336 | 280 | )
|
337 | 281 | )
|
| 282 | + |
| 283 | +// MARK: - Parse build arguments |
| 284 | + |
| 285 | +func hasEnvironmentVariable(_ name: String) -> Bool { |
| 286 | + return ProcessInfo.processInfo.environment[name] != nil |
| 287 | +} |
| 288 | + |
| 289 | +/// Set when building swift-syntax using swift-syntax-dev-utils or in Swift CI in general. |
| 290 | +/// |
| 291 | +/// Modifies the build in the following ways |
| 292 | +/// - Enables assertions even in release builds |
| 293 | +/// - Removes the dependency of swift-syntax on os_log |
| 294 | +var buildScriptEnvironment: Bool { hasEnvironmentVariable("SWIFT_BUILD_SCRIPT_ENVIRONMENT") } |
| 295 | + |
| 296 | +/// Check that the layout of the syntax tree is correct. |
| 297 | +/// |
| 298 | +/// See CONTRIBUTING.md for more information |
| 299 | +var rawSyntaxValidation: Bool { hasEnvironmentVariable("SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION") } |
| 300 | + |
| 301 | +/// Mutate the input of `assertParse` test cases. |
| 302 | +/// |
| 303 | +/// See CONTRIBUTING.md for more information |
| 304 | +var alternateTokenIntrospection: Bool { hasEnvironmentVariable("SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION") } |
| 305 | + |
| 306 | +/// Assume that swift-argument-parser is checked out next to swift-syntax and use that instead of fetching a remote dependency. |
| 307 | +var useLocalDependencies: Bool { hasEnvironmentVariable("SWIFTCI_USE_LOCAL_DEPS") } |
| 308 | + |
| 309 | +// MARK: - Compute custom build settings |
| 310 | + |
| 311 | +// These build settings apply to the target and the corresponding test target. |
| 312 | +var swiftSyntaxSwiftSettings: [SwiftSetting] { |
| 313 | + var settings: [SwiftSetting] = [] |
| 314 | + if buildScriptEnvironment { |
| 315 | + settings.append(.define("SWIFTSYNTAX_ENABLE_ASSERTIONS")) |
| 316 | + } |
| 317 | + if rawSyntaxValidation { |
| 318 | + settings.append(.define("SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION")) |
| 319 | + } |
| 320 | + return settings |
| 321 | +} |
| 322 | +var swiftSyntaxBuilderSwiftSettings: [SwiftSetting] { |
| 323 | + if buildScriptEnvironment { |
| 324 | + return [.define("SWIFTSYNTAX_NO_OSLOG_DEPENDENCY")] |
| 325 | + } else { |
| 326 | + return [] |
| 327 | + } |
| 328 | +} |
| 329 | +var swiftParserSwiftSettings: [SwiftSetting] { |
| 330 | + if alternateTokenIntrospection { |
| 331 | + return [.define("SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION")] |
| 332 | + } else { |
| 333 | + return [] |
| 334 | + } |
| 335 | +} |
0 commit comments