Skip to content

Commit 319673b

Browse files
committed
Make CodeGeneration depend on swift-syntax 509.0.0
Having CodeGeneration depend on a stable version of swift-syntax makes rebasing changes a lot easier because CodeGeneration no longer depends on itself.
1 parent ebd7026 commit 319673b

File tree

7 files changed

+30
-40
lines changed

7 files changed

+30
-40
lines changed

CodeGeneration/Package.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
import Foundation
44
import PackageDescription
55

6+
func isOptionEnabled(_ name: String) -> Bool {
7+
if let value = ProcessInfo.processInfo.environment[name] {
8+
return value == "1" || value == "YES"
9+
}
10+
return false
11+
}
12+
613
let package = Package(
714
name: "CodeGeneration",
815
platforms: [
@@ -12,17 +19,7 @@ let package = Package(
1219
.executable(name: "generate-swift-syntax", targets: ["generate-swift-syntax"])
1320
],
1421
dependencies: [
15-
// This directory is a standalone package that uses swift-syntax from the
16-
// outer directory.
17-
// If you are making significant changs to `CodeGeneration` locally and want
18-
// to avoid breaking the build of `CodeGeneration` itself by generating new
19-
// files in the parent swift-syntax package, it is encouraged to change the
20-
// dependency to the following. That way `CodeGeneration` has its own
21-
// checkout of swift-syntax that is unaffected by the newly generated files.
22-
// Be sure to revert the change before committing your changes.
23-
//
24-
// .package(url: "https://github.com/apple/swift-syntax", branch: "main")
25-
.package(path: "..")
22+
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0")
2623
],
2724
targets: [
2825
.executableTarget(
@@ -64,7 +61,7 @@ let package = Package(
6461
]
6562
)
6663

67-
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
64+
if isOptionEnabled("SWIFTCI_USE_LOCAL_DEPS") {
6865
// Building standalone.
6966
package.dependencies += [
7067
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")

CodeGeneration/README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ This directory contains file to generate source code that is part of the SwiftSy
44

55
Some source code inside SwiftSyntax is generated using [SwiftSyntaxBuilder](../Sources/SwiftSyntaxBuilder), a Swift library whose purpose is to generate Swift code using Swift itself. This kind of code generation is performed by the Swift package defined in this directory.
66

7-
This directory is a standalone package that uses swift-syntax from the outer directory.
8-
If you are making significant changes to `CodeGeneration` locally and want to avoid breaking the build of `CodeGeneration` itself by generating new files in the parent swift-syntax package, it is encouraged to change the dependency from
9-
```swift
10-
.package(path: "..")
11-
```
12-
to
13-
```swift
14-
.package(url: "https://github.com/apple/swift-syntax", branch: "main")
15-
```
16-
That way `CodeGeneration` has its own checkout of swift-syntax that is unaffected by the newly generated files. Be sure to revert the change before committing your changes.
17-
187
To re-generate the files after changing `CodeGeneration` run the `generate-swift-syntax`
198
target of `CodeGeneration` and pass `path/to/swift-syntax/Sources` as the argument.
209

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ func rawSyntaxNodesFile(nodesStartingWith: [Character]) -> SourceFileSyntax {
218218
let list = ExprListSyntax {
219219
ExprSyntax("layout.initialize(repeating: nil)")
220220
for (index, child) in node.children.enumerated() {
221-
let optionalMark = child.isOptional ? TokenSyntax.postfixQuestionMarkToken() : nil
221+
let optionalMark = child.isOptional ? "?" : ""
222222

223-
ExprSyntax("layout[\(raw: index)] = \(child.varOrCaseName.backtickedIfNeeded)\(optionalMark).raw")
223+
ExprSyntax("layout[\(raw: index)] = \(child.varOrCaseName.backtickedIfNeeded)\(raw: optionalMark).raw")
224224
.with(\.leadingTrivia, .newline)
225225
}
226226
}
@@ -241,12 +241,12 @@ func rawSyntaxNodesFile(nodesStartingWith: [Character]) -> SourceFileSyntax {
241241

242242
for (index, child) in node.children.enumerated() {
243243
try VariableDeclSyntax("public var \(child.varOrCaseName.backtickedIfNeeded): Raw\(child.buildableType.buildable)") {
244-
let exclamationMark = child.isOptional ? nil : TokenSyntax.exclamationMarkToken()
244+
let exclamationMark = child.isOptional ? "" : "!"
245245

246246
if child.syntaxNodeKind == .syntax {
247-
ExprSyntax("layoutView.children[\(raw: index)]\(exclamationMark)")
247+
ExprSyntax("layoutView.children[\(raw: index)]\(raw: exclamationMark)")
248248
} else {
249-
ExprSyntax("layoutView.children[\(raw: index)].map(\(child.syntaxNodeKind.rawType).init(raw:))\(exclamationMark)")
249+
ExprSyntax("layoutView.children[\(raw: index)].map(\(child.syntaxNodeKind.rawType).init(raw:))\(raw: exclamationMark)")
250250
}
251251
}
252252
}

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxTraitsFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
2626
"""
2727
) {
2828
for child in trait.children {
29-
let questionMark = child.isOptional ? TokenSyntax.postfixQuestionMarkToken() : nil
29+
let questionMark = child.isOptional ? "?" : ""
3030

3131
DeclSyntax(
3232
"""
3333
\(child.documentation)
34-
\(child.apiAttributes)var \(child.varOrCaseName): \(child.syntaxNodeKind.syntaxType)\(questionMark) { get set }
34+
\(child.apiAttributes)var \(child.varOrCaseName): \(child.syntaxNodeKind.syntaxType)\(raw: questionMark) { get set }
3535
"""
3636
)
3737
}

Package.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,32 @@ import PackageDescription
55

66
// MARK: - Parse build arguments
77

8-
func hasEnvironmentVariable(_ name: String) -> Bool {
9-
return ProcessInfo.processInfo.environment[name] != nil
8+
func isOptionEnabled(_ name: String) -> Bool {
9+
if let value = ProcessInfo.processInfo.environment[name] {
10+
return value == "1" || value == "YES"
11+
}
12+
return false
1013
}
1114

1215
/// Set when building swift-syntax using swift-syntax-dev-utils or in Swift CI in general.
1316
///
1417
/// Modifies the build in the following ways
1518
/// - Enables assertions even in release builds
1619
/// - Removes the dependency of swift-syntax on os_log
17-
let buildScriptEnvironment = hasEnvironmentVariable("SWIFT_BUILD_SCRIPT_ENVIRONMENT")
20+
let buildScriptEnvironment = isOptionEnabled("SWIFT_BUILD_SCRIPT_ENVIRONMENT")
1821

1922
/// Check that the layout of the syntax tree is correct.
2023
///
2124
/// See CONTRIBUTING.md for more information
22-
let rawSyntaxValidation = hasEnvironmentVariable("SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION")
25+
let rawSyntaxValidation = isOptionEnabled("SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION")
2326

2427
/// Mutate the input of `assertParse` test cases.
2528
///
2629
/// See CONTRIBUTING.md for more information
27-
let alternateTokenIntrospection = hasEnvironmentVariable("SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION")
30+
let alternateTokenIntrospection = isOptionEnabled("SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION")
2831

2932
/// 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")
33+
let useLocalDependencies = isOptionEnabled("SWIFTCI_USE_LOCAL_DEPS")
3134

3235
// MARK: - Compute custom build settings
3336

Sources/SwiftParser/generated/ExperimentalFeatures.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ extension Parser {
2525

2626
extension Parser.ExperimentalFeatures {
2727
/// Whether to enable the parsing of reference bindings.
28-
public static let referenceBindings = Self(rawValue: 1 << 0)
28+
public static let referenceBindings = Self (rawValue: 1 << 0)
2929

3030
/// Whether to enable the parsing of 'then' statements.
31-
public static let thenStatements = Self(rawValue: 1 << 1)
31+
public static let thenStatements = Self (rawValue: 1 << 1)
3232

3333
/// Whether to enable the parsing of typed throws.
34-
public static let typedThrows = Self(rawValue: 1 << 2)
34+
public static let typedThrows = Self (rawValue: 1 << 2)
3535

3636
/// Whether to enable the parsing of 'do' expressions.
37-
public static let doExpressions = Self(rawValue: 1 << 3)
37+
public static let doExpressions = Self (rawValue: 1 << 3)
3838
}

SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/SourceCodeGeneratorCommand.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extension SourceCodeGeneratorCommand {
3535
let additionalEnvironment = [
3636
"SWIFT_BUILD_SCRIPT_ENVIRONMENT": "1",
3737
"SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION": "1",
38+
"SWIFTCI_USE_LOCAL_DEPS": "0",
3839
]
3940

4041
let process = ProcessRunner(

0 commit comments

Comments
 (0)