Skip to content

Commit eed7a6f

Browse files
committed
Order package manifest to start with the package declaration
Instead of starting with environment variable parsing, start with the actual package manifest, which is most likely the most interesting to most users. rdar://121441220
1 parent 4265ac0 commit eed7a6f

File tree

1 file changed

+54
-56
lines changed

1 file changed

+54
-56
lines changed

Package.swift

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,6 @@
33
import Foundation
44
import PackageDescription
55

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-
626
let package = Package(
637
name: "swift-syntax",
648
platforms: [
@@ -335,3 +279,57 @@ package.targets.append(
335279
}
336280
)
337281
)
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

Comments
 (0)