Skip to content

Commit c23e23d

Browse files
authored
Merge pull request #1425 from ahoppen/ahoppen/no-gyb
Remove remaining references to gyb
2 parents 9a6b16b + 5871484 commit c23e23d

File tree

69 files changed

+162
-303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+162
-303
lines changed

CodeGeneration/Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ let package = Package(
2323
.product(name: "ArgumentParser", package: "swift-argument-parser"),
2424
"SyntaxSupport",
2525
"Utils",
26+
],
27+
exclude: [
28+
"templates/swiftsyntax/SwiftSyntaxDoccIndexTemplate.md"
2629
]
2730
),
2831
.target(

CodeGeneration/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
This directory contains file to generate source code that is part of the SwiftSyntax package. If you are looking to generate Swift code yourself, you might be interested in [SwiftSyntaxBuilder](../Sources/SwiftSyntaxBuilder).
44

5-
SwiftSyntax currently uses two mechanisms to generate source code: gyb and SwiftSyntaxBuilder. Both can be run using
6-
7-
```bash
8-
./build-script.py generate-source-code --toolchain /path/to/toolchain.xctoolchain/usr
9-
```
5+
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.
106

11-
## `gyb`
7+
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.
128

13-
Files generated using `gyb` have a `.gyb` suffix. [ChangingSwiftSyntax.md](../Sources/SwiftSyntax/Documentation.docc/ChangingSwiftSyntax.md) contains documentation how `gyb` works. This directory contains the definitions that back most of gyb-generation in `gyb_syntax_support`.
9+
To re-generate the files after changing `CodeGeneration` run the `generate-swiftsyntax`
10+
target of `CodeGeneration` and pass `path/to/swift-syntax/Sources` as the argument.
1411

15-
## `SwiftSyntaxBuilder`
12+
On the command line, this would be
13+
```bash
14+
swift run --package-path CodeGeneration generate-swiftsyntax Sources
15+
```
1616

17-
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.
17+
Or if you open the `CodeGeneration` package in Xcode, you can add the
18+
`generate-swift syntax ../Sources` arguments using Product -> Scheme -> Edit Scheme…
1819

19-
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-swiftsyntaxbuilder` is run, it can't break its own build.

CodeGeneration/Sources/Utils/CopyrightHeader.swift

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@
1212

1313
import SwiftSyntax
1414

15-
public func generateCopyrightHeader(for generator: String) -> Trivia {
16-
return """
17-
//// Automatically Generated by \(generator)
18-
//// Do Not Edit Directly!
19-
//===----------------------------------------------------------------------===//
20-
//
21-
// This source file is part of the Swift.org open source project
22-
//
23-
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
24-
// Licensed under Apache License v2.0 with Runtime Library Exception
25-
//
26-
// See https://swift.org/LICENSE.txt for license information
27-
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
28-
//
29-
//===----------------------------------------------------------------------===//
30-
""" + .newlines(2)
31-
}
15+
public var copyrightHeader: Trivia =
16+
"""
17+
//// Automatically generated by generate-swiftsyntax
18+
//// Do not edit directly!
19+
//===----------------------------------------------------------------------===//
20+
//
21+
// This source file is part of the Swift.org open source project
22+
//
23+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
24+
// Licensed under Apache License v2.0 with Runtime Library Exception
25+
//
26+
// See https://swift.org/LICENSE.txt for license information
27+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
28+
//
29+
//===----------------------------------------------------------------------===//
30+
""" + .newlines(2)

CodeGeneration/Sources/Utils/SyntaxBuildableType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct SyntaxBuildableType: Hashable {
2626
public init(syntaxKind: String, isOptional: Bool = false) {
2727
self.isOptional = isOptional
2828
if syntaxKind.hasSuffix("Token") {
29-
// There are different token kinds but all of them are represented by `Token` in the Swift source (see `kind_to_type` in `gyb_syntax_support`).
29+
// There are different token kinds but all of them are represented by `Token` in the Swift source (see `kindToType` in `SyntaxSupport/Utils.swift`).
3030
self.syntaxKind = "Token"
3131
self.tokenKind = syntaxKind
3232
} else {

CodeGeneration/Sources/Utils/Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public func dedented(string: String) -> String {
2222
}
2323

2424
/// Creates a single-line documentation string from indented
25-
/// documentation as written in `gyb_syntax_support`.
25+
/// documentation as written in `CodeGeneration`.
2626
public func flattened(indentedDocumentation: String) -> String {
2727
dedented(string: indentedDocumentation)
2828
.replacingOccurrences(of: "\n", with: "")

CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ struct GenerateSwiftSyntax: ParsableCommand {
7474
var verbose: Bool = false
7575

7676
func run() throws {
77+
let destination = URL(fileURLWithPath: self.destination).standardizedFileURL
78+
7779
let fileSpecs: [GeneratedFileSpec] =
7880
[
7981
// SwiftBasicFormat
@@ -123,21 +125,23 @@ struct GenerateSwiftSyntax: ParsableCommand {
123125
let previouslyGeneratedFilesLock = NSLock()
124126
var previouslyGeneratedFiles = Set(
125127
modules.flatMap { (module) -> [URL] in
126-
let generatedDir = URL(fileURLWithPath: destination)
128+
let generatedDir =
129+
destination
127130
.appendingPathComponent(module)
128131
.appendingPathComponent("generated")
129132
return FileManager.default
130133
.enumerator(at: generatedDir, includingPropertiesForKeys: nil)!
131134
.compactMap { $0 as? URL }
132135
.filter { !$0.hasDirectoryPath }
136+
.map { $0.resolvingSymlinksInPath() }
133137
}
134138
)
135139

136140
var errors: [Error] = []
137141
DispatchQueue.concurrentPerform(iterations: fileSpecs.count) { index in
138142
let fileSpec = fileSpecs[index]
139143
do {
140-
var destination = URL(fileURLWithPath: destination)
144+
var destination = destination
141145
for component in fileSpec.pathComponents {
142146
destination = destination.appendingPathComponent(component)
143147
}

CodeGeneration/Sources/generate-swiftsyntax/templates/basicformat/BasicFormatFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension Child {
4949
}
5050
}
5151

52-
let basicFormatFile = SourceFileSyntax(leadingTrivia: generateCopyrightHeader(for: "generate-swiftbasicformat")) {
52+
let basicFormatFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
5353
DeclSyntax("import SwiftSyntax")
5454

5555
try! ClassDeclSyntax("open class BasicFormat: SyntaxRewriter") {

CodeGeneration/Sources/generate-swiftsyntax/templates/ideutils/SyntaxClassificationFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fileprivate var node_child_classifications: [ChildClassification] {
2929
return result
3030
}
3131

32-
let syntaxClassificationFile = SourceFileSyntax(leadingTrivia: generateCopyrightHeader(for: "generate-ideutils")) {
32+
let syntaxClassificationFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
3333
DeclSyntax("@_spi(RawSyntax) import SwiftSyntax")
3434

3535
try! EnumDeclSyntax("public enum SyntaxClassification") {

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/DeclarationModifierFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SwiftSyntaxBuilder
1515
import SyntaxSupport
1616
import Utils
1717

18-
let declarationModifierFile = SourceFileSyntax(leadingTrivia: generateCopyrightHeader(for: "generate-swiftparser")) {
18+
let declarationModifierFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
1919
DeclSyntax("@_spi(RawSyntax) import SwiftSyntax")
2020

2121
try! EnumDeclSyntax("enum DeclarationModifier: TokenSpecSet") {

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserEntryFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SwiftSyntaxBuilder
1515
import SyntaxSupport
1616
import Utils
1717

18-
let parserEntryFile = SourceFileSyntax(leadingTrivia: generateCopyrightHeader(for: "generate-swiftparser")) {
18+
let parserEntryFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
1919
DeclSyntax("@_spi(RawSyntax) import SwiftSyntax")
2020

2121
try! ExtensionDeclSyntax("extension Parser") {

0 commit comments

Comments
 (0)