Skip to content

Move generation to a single executable #1149

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
Jan 3, 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
44 changes: 0 additions & 44 deletions CodeGeneration/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,13 @@ let package = Package(
.macOS(.v10_15),
],
products: [
.executable(name: "generate-swiftbasicformat", targets: ["generate-swiftbasicformat"]),
.executable(name: "generate-swiftideutils", targets: ["generate-swiftideutils"]),
.executable(name: "generate-swiftparser", targets: ["generate-swiftparser"]),
.executable(name: "generate-swiftsyntax", targets: ["generate-swiftsyntax"]),
.executable(name: "generate-swiftsyntaxbuilder", targets: ["generate-swiftsyntaxbuilder"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-syntax.git", revision: "74b1286795d6a4e4f5a106638dc99eb482df609d"),
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.1.4")),
],
targets: [
.executableTarget(
name: "generate-swiftbasicformat",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"SyntaxSupport",
"Utils"
]
),
.executableTarget(
name: "generate-swiftideutils",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"SyntaxSupport",
"Utils"
]
),
.executableTarget(
name: "generate-swiftparser",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"SyntaxSupport",
"Utils"
]
),
.executableTarget(
name: "generate-swiftsyntax",
dependencies: [
Expand All @@ -58,16 +24,6 @@ let package = Package(
"SyntaxSupport",
"Utils"
]
),
.executableTarget(
name: "generate-swiftsyntaxbuilder",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"SyntaxSupport",
"Utils"
]
),
.target(
name: "SyntaxSupport",
Expand Down
33 changes: 0 additions & 33 deletions CodeGeneration/Sources/Utils/GenerateTemplates.swift

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,76 @@

import ArgumentParser
import Foundation
import SwiftSyntax
import SwiftSyntaxBuilder
import Utils

private let swiftBasicFormatDir: String = "SwiftBasicFormat"
private let IDEUtilsDir: String = "IDEUtils"
private let swiftParserDir: String = "SwiftParser"
private let swiftSyntaxDir: String = "SwiftSyntax"
private let swiftSyntaxBuilderDir: String = "SwiftSyntaxBuilder"

@main
struct GenerateSwiftSyntax: ParsableCommand {
@Argument(help: "The path to the destination directory where the source files are to be generated")
@Argument(help: "The path to the source directory where the source files are to be generated")
var generatedPath: String

@Flag(help: "Enable verbose output")
var verbose: Bool = false

func run() throws {
try generateTemplates(
templates: [
(miscFile, "Misc.swift"),
(syntaxAnyVisitorFile, "SyntaxAnyVisitor.swift"),
(syntaxBaseNodesFile, "SyntaxBaseNodes.swift"),
(syntaxEnumFile, "SyntaxEnum.swift"),
(syntaxKindFile, "SyntaxKind.swift")
],
destination: URL(fileURLWithPath: generatedPath),
verbose: verbose
)
let templates: [(sourceFile: SourceFileSyntax, module: String, filename: String)] = [
(basicFormatFile, swiftBasicFormatDir, "BasicFormat.swift"),
(syntaxClassificationFile, IDEUtilsDir, "SyntaxClassification.swift"),
(declarationAttributeFile, swiftParserDir, "DeclarationAttribute.swift"),
(declarationModifierFile, swiftParserDir, "DeclarationModifier.swift"),
(parserEntryFile, swiftParserDir, "Parser+Entry.swift"),
(typeAttributeFile, swiftParserDir, "TypeAttribute.swift"),
(miscFile, swiftSyntaxDir, "Misc.swift"),
(syntaxBaseNodesFile, swiftSyntaxDir, "SyntaxBaseNodes.swift"),
(syntaxBaseNodesFile, swiftSyntaxDir, "SyntaxBaseNodes.swift"),
(syntaxEnumFile, swiftSyntaxDir, "SyntaxEnum.swift"),
(syntaxKindFile, swiftSyntaxDir, "SyntaxKind.swift"),
(buildableCollectionNodesFile, swiftSyntaxBuilderDir, "BuildableCollectionNodes.swift"),
(buildableNodesFile, swiftSyntaxBuilderDir, "BuildableNodes.swift"),
(resultBuildersFile, swiftSyntaxBuilderDir, "ResultBuilders.swift"),
(syntaxExpressibleByStringInterpolationConformancesFile, swiftSyntaxBuilderDir, "SyntaxExpressibleByStringInterpolationConformances.swift"),
(tokenFile, swiftSyntaxBuilderDir, "Token.swift"),
(typealiasesFile, swiftSyntaxBuilderDir, "Typealiases.swift"),
]

for template in templates {
try generateTemplate(
sourceFile: template.sourceFile,
module: template.module,
filename: template.filename,
destination: URL(fileURLWithPath: generatedPath),
verbose: verbose)
}
}

private func generateTemplate(
sourceFile: SourceFileSyntax,
module: String,
filename: String,
destination: URL,
verbose: Bool) throws {
try FileManager.default.createDirectory(
atPath: destination.path,
withIntermediateDirectories: true,
attributes: nil
)

let fileURL = destination
.appendingPathComponent(module)
.appendingPathComponent("generated")
.appendingPathComponent(filename)

if verbose {
print("Generating \(fileURL.path)...")
}
let syntax = sourceFile.formatted(using: CodeGenerationFormat())
try "\(syntax)\n".write(to: fileURL, atomically: true, encoding: .utf8)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import SyntaxSupport
import Utils

// Collects the list of classifications to use for contextual classification.
var node_child_classifications: [ChildClassification] {
fileprivate var node_child_classifications: [ChildClassification] {
var result = [ChildClassification]()
for node in SYNTAX_NODES {
for (index, child) in node.children.enumerated() where child.classification?.name != nil {
Expand Down

This file was deleted.

Loading