Skip to content

Make CodeGeneration depend on swift-syntax 509.0.0 #2239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions CodeGeneration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ This directory contains file to generate source code that is part of the SwiftSy

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.

This directory is a standalone package that uses swift-syntax from the outer directory.
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
```swift
.package(path: "..")
```
to
```swift
.package(url: "https://github.com/apple/swift-syntax", branch: "main")
```
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.

To re-generate the files after changing `CodeGeneration` run the `generate-swift-syntax`
target of `CodeGeneration` and pass `path/to/swift-syntax/Sources` as the argument.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ func rawSyntaxNodesFile(nodesStartingWith: [Character]) -> SourceFileSyntax {
let list = ExprListSyntax {
ExprSyntax("layout.initialize(repeating: nil)")
for (index, child) in node.children.enumerated() {
let optionalMark = child.isOptional ? TokenSyntax.postfixQuestionMarkToken() : nil
let optionalMark = child.isOptional ? "?" : ""

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

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

if child.syntaxNodeKind == .syntax {
ExprSyntax("layoutView.children[\(raw: index)]\(exclamationMark)")
ExprSyntax("layoutView.children[\(raw: index)]\(raw: exclamationMark)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why this change was made. Weren't we planning to phase out the use of raw: interpolation?

} else {
ExprSyntax("layoutView.children[\(raw: index)].map(\(child.syntaxNodeKind.rawType).init(raw:))\(exclamationMark)")
ExprSyntax("layoutView.children[\(raw: index)].map(\(child.syntaxNodeKind.rawType).init(raw:))\(raw: exclamationMark)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
"""
) {
for child in trait.children {
let questionMark = child.isOptional ? TokenSyntax.postfixQuestionMarkToken() : nil
let questionMark = child.isOptional ? "?" : ""

DeclSyntax(
"""
\(child.documentation)
\(child.apiAttributes)var \(child.varOrCaseName): \(child.syntaxNodeKind.syntaxType)\(questionMark) { get set }
\(child.apiAttributes)var \(child.varOrCaseName): \(child.syntaxNodeKind.syntaxType)\(raw: questionMark) { get set }
"""
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ public class ProcessRunner {
public init(
executableURL: URL,
arguments: [String],
additionalEnvironment: [String: String] = [:]
additionalEnvironment: [String: String?] = [:]
) {
process = Process()
process.executableURL = executableURL
process.arguments = arguments
process.environment = additionalEnvironment.merging(ProcessInfo.processInfo.environment) { (additional, _) in additional }
process.environment = ProcessInfo.processInfo.environment
for (key, value) in additionalEnvironment {
process.environment![key] = value
}
}

@discardableResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extension SourceCodeGeneratorCommand {
let additionalEnvironment = [
"SWIFT_BUILD_SCRIPT_ENVIRONMENT": "1",
"SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION": "1",
"SWIFTCI_USE_LOCAL_DEPS": nil,
]

let process = ProcessRunner(
Expand Down