Skip to content

Use local git package for code gen #1546

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 3 commits into from
Apr 28, 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
15 changes: 13 additions & 2 deletions CodeGeneration/Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// swift-tools-version:5.7

import PackageDescription
import Foundation

let package = Package(
name: "CodeGeneration",
Expand All @@ -11,8 +12,7 @@ let package = Package(
.executable(name: "generate-swiftsyntax", targets: ["generate-swiftsyntax"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-syntax.git", revision: "c7087adb193b26f02b59d21cd06d17ec202d1bf5"),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"),
.package(url: "..", revision: "HEAD")
],
targets: [
.executableTarget(
Expand Down Expand Up @@ -41,3 +41,14 @@ let package = Package(
),
]
)

if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// Building standalone.
package.dependencies += [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
]
} else {
package.dependencies += [
.package(path: "../../swift-argument-parser")
]
}
3 changes: 2 additions & 1 deletion CodeGeneration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ 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 a pinned version of SwiftSyntaxBuilder. It is thus NOT using SwiftSyntaxBuilder of the parent directory. This guarantees that when `generate-swiftsyntax` is run, it can't break its own build.
This directory is a standalone package that uses HEAD of the current branch. This guarantees that when `generate-swiftsyntax` is run, it can't break its own build when run multiple times without committing.
This means that `CodeGeneration` will build against your latest local commit of SwiftSyntax. If you are making changes to `SwiftSyntax` that affect how code is being generated, commit your SwiftSyntax changes (pushing is not necessary) and re-generate files afterwards.

To re-generate the files after changing `CodeGeneration` run the `generate-swiftsyntax`
target of `CodeGeneration` and pass `path/to/swift-syntax/Sources` as the argument.
Expand Down
282 changes: 141 additions & 141 deletions Sources/SwiftSyntax/generated/SyntaxCollections.swift

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/generated/SyntaxRewriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6904,8 +6904,8 @@ open class SyntaxRewriter {
var childIndex = 0
for (raw, info) in RawSyntaxChildren(syntaxNode) {
defer {
childIndex += 1
}
childIndex += 1
}
guard let child = raw else {
// Node does not exist. If we are collecting rewritten nodes, we need to
// collect this one as well, otherwise we can ignore it.
Expand Down
Loading