Skip to content

Commit 6c65044

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 6c65044

File tree

5 files changed

+13
-20
lines changed

5 files changed

+13
-20
lines changed

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
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ public class ProcessRunner {
4444
public init(
4545
executableURL: URL,
4646
arguments: [String],
47-
additionalEnvironment: [String: String] = [:]
47+
additionalEnvironment: [String: String?] = [:]
4848
) {
4949
process = Process()
5050
process.executableURL = executableURL
5151
process.arguments = arguments
52-
process.environment = additionalEnvironment.merging(ProcessInfo.processInfo.environment) { (additional, _) in additional }
52+
process.environment = ProcessInfo.processInfo.environment
53+
for (key, value) in additionalEnvironment {
54+
process.environment![key] = value
55+
}
5356
}
5457

5558
@discardableResult

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": nil,
3839
]
3940

4041
let process = ProcessRunner(

0 commit comments

Comments
 (0)