Skip to content

Pin SwiftSyntaxBuilder version for generate-swiftsyntaxbuilder #826

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
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
2 changes: 2 additions & 0 deletions Code-Generation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore Data Xcode stores when opening the project directly
/.swiftpm/xcode
46 changes: 46 additions & 0 deletions Code-Generation/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// swift-tools-version:5.7

import PackageDescription

let package = Package(
name: "CodeGeneration",
platforms: [
.macOS(.v10_15),
],
products: [
.executable(name: "generate-swiftsyntaxbuilder", targets: ["generate-swiftsyntaxbuilder"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-syntax.git", revision: "dcd692d759e09730098e45ba7276d0d96d004bac"),
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.1.4")),
],
targets: [
.executableTarget(
name: "generate-swiftsyntaxbuilder",
dependencies: [
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "ArgumentParser", package: "swift-argument-parser")
],
exclude: [
"gyb_helpers",
"AttributeNodes.swift.gyb",
"AvailabilityNodes.swift.gyb",
"BuilderInitializableTypes.swift.gyb",
"Classification.swift.gyb",
"CommonNodes.swift.gyb",
"DeclNodes.swift.gyb",
"ExpressibleAsConformances.swift.gyb",
"ExprNodes.swift.gyb",
"GenericNodes.swift.gyb",
"NodeSerializationCodes.swift.gyb",
"PatternNodes.swift.gyb",
"StmtNodes.swift.gyb",
"SyntaxBaseKinds.swift.gyb",
"TokenSpec.swift.gyb",
"Traits.swift.gyb",
"Trivia.swift.gyb",
"TypeNodes.swift.gyb"
]
),
]
)
19 changes: 19 additions & 0 deletions Code-Generation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Code-Generation for SwiftSyntax

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).

SwiftSyntax currently uses two mechanisms to generate source code: gyb and SwiftSyntaxBuilder. Both can be run using

```bash
./build-script.py generate-source-code --toolchain /path/to/toolchain.xctoolchain/usr
```

## `gyb`

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`.

## `SwiftSyntaxBuilder`

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-swiftsyntaxbuilder` is run, it can't break its own build.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
BUILDER_INITIALIZABLE_TYPES = {
'CodeBlock': 'CodeBlockItemList',
'MemberDeclBlock': 'MemberDeclList',
'CodeBlockItemList': None,
'MemberDeclList': None,
'PatternBindingList': None,
'SwitchCaseList': None,
'ArrayElementList': None,
'TupleExprElementList': None,
'EnumCaseElementList': None,
'FunctionParameterList': None,
'GenericParameterList': None,
'GenericRequirementList': None,
'InheritedTypeList': None,
'ClosureCaptureItemList': None,
'CaseItemList': None,
'GenericArgumentList': None,
'TuplePatternElementList': None,
'ExprList': None,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES = {
'AccessorList': [
'AccessorBlock'
],
'ArrayElementList': [
'ArrayExpr'
],
'CodeBlockItemList': [
'CodeBlock'
],
'DeclBuildable': [
'CodeBlockItem',
'MemberDeclListItem'
],
'ExprBuildable': [
'CodeBlockItem',
'InitializerClause'
],
'ExprList': [
'ConditionElement'
],
'MatchingPatternCondition': [
'ConditionElement'
],
'MemberDeclList': [
'MemberDeclBlock'
],
'OptionalBindingCondition': [
'ConditionElement'
],
'SequenceExpr': [
'CodeBlockItem',
'TupleExprElement'
],
'SimpleTypeIdentifier': [
'TypeExpr'
],
'StmtBuildable': [
'CodeBlockItem'
],
'Token': [
'BinaryOperatorExpr',
'DeclModifier',
'IdentifierExpr'
],
'TypeBuildable': [
'ReturnClause',
'TypeInitializerClause',
'TypeAnnotation'
]
}

26 changes: 0 additions & 26 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ let package = Package(
.library(name: "SwiftSyntax", type: .static, targets: ["SwiftSyntax"]),
.library(name: "SwiftSyntaxParser", type: .static, targets: ["SwiftSyntaxParser"]),
.library(name: "SwiftSyntaxBuilder", type: .static, targets: ["SwiftSyntaxBuilder"]),
.executable(name: "generate-swift-syntax-builder", targets: ["generate-swift-syntax-builder"])
],
targets: [
.target(
Expand Down Expand Up @@ -142,31 +141,6 @@ let package = Package(
"SwiftOperators",
.product(name: "ArgumentParser", package: "swift-argument-parser")]
),
.executableTarget(
name: "generate-swift-syntax-builder",
dependencies: ["SwiftSyntaxBuilder", .product(name: "ArgumentParser", package: "swift-argument-parser")],
exclude: [
"gyb_helpers",
"gyb_syntax_support",
"AttributeNodes.swift.gyb",
"AvailabilityNodes.swift.gyb",
"BuilderInitializableTypes.swift.gyb",
"Classification.swift.gyb",
"CommonNodes.swift.gyb",
"DeclNodes.swift.gyb",
"ExpressibleAsConformances.swift.gyb",
"ExprNodes.swift.gyb",
"GenericNodes.swift.gyb",
"NodeSerializationCodes.swift.gyb",
"PatternNodes.swift.gyb",
"StmtNodes.swift.gyb",
"SyntaxBaseKinds.swift.gyb",
"TokenSpec.swift.gyb",
"Traits.swift.gyb",
"Trivia.swift.gyb",
"TypeNodes.swift.gyb"
]
),
.testTarget(
name: "SwiftSyntaxTest",
dependencies: ["SwiftSyntax", "_SwiftSyntaxTestSupport"]
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading