From 44eef24b6c04b9757fed5b994a2df9b8a25bf8bd Mon Sep 17 00:00:00 2001 From: arirays Date: Mon, 31 Jul 2023 14:47:36 -1000 Subject: [PATCH 1/2] Renamed generate-swiftsyntax to generate-swift-syntax --- CodeGeneration/Package.swift | 4 +- CodeGeneration/README.md | 4 +- .../Sources/Utils/CopyrightHeader.swift | 2 +- .../GenerateSwiftSyntax.swift | 0 .../LayoutNode+Extensions.swift | 0 .../templates/Array+Child.swift | 0 .../swiftparser/IsLexerClassifiedFile.swift | 0 .../swiftparser/ParserEntryFile.swift | 0 .../swiftparser/ParserTokenSpecSetFile.swift | 0 .../TokenSpecStaticMembersFile.swift | 0 .../ChildNameForDiagnosticsFile.swift | 0 .../SyntaxKindNameForDiagnosticsFile.swift | 0 .../TokenNameForDiagnosticsFile.swift | 0 .../swiftsyntax/ChildNameForKeyPathFile.swift | 0 .../templates/swiftsyntax/KeywordFile.swift | 0 .../swiftsyntax/RawSyntaxNodesFile.swift | 0 .../swiftsyntax/RawSyntaxValidationFile.swift | 0 .../RenamedChildrenCompatibilityFile.swift | 0 .../swiftsyntax/RenamedSyntaxNodesFile.swift | 0 .../swiftsyntax/SwiftSyntaxDoccIndex.swift | 0 .../SwiftSyntaxDoccIndexTemplate.md | 0 .../swiftsyntax/SyntaxAnyVisitorFile.swift | 0 .../swiftsyntax/SyntaxBaseNodesFile.swift | 0 .../swiftsyntax/SyntaxCollectionsFile.swift | 0 .../swiftsyntax/SyntaxEnumFile.swift | 0 .../swiftsyntax/SyntaxKindFile.swift | 0 .../swiftsyntax/SyntaxNodesFile.swift | 0 .../swiftsyntax/SyntaxRewriterFile.swift | 0 .../swiftsyntax/SyntaxTraitsFile.swift | 0 .../swiftsyntax/SyntaxTransformFile.swift | 0 .../swiftsyntax/SyntaxVisitorFile.swift | 0 .../templates/swiftsyntax/TokenKindFile.swift | 0 .../templates/swiftsyntax/TokensFile.swift | 0 .../swiftsyntax/TriviaPiecesFile.swift | 0 .../BuildableCollectionNodesFile.swift | 66 ++ .../BuildableNodesFile.swift | 0 ...amedChildrenBuilderCompatibilityFile.swift | 0 .../ResultBuildersFile.swift | 0 ...yStringInterpolationConformancesFile.swift | 0 .../generated/IsLexerClassified.swift | 2 +- .../generated/LayoutNodes+Parsable.swift | 2 +- .../generated/Parser+TokenSpecSet.swift | 2 +- .../generated/TokenSpecStaticMembers.swift | 2 +- .../generated/ChildNameForDiagnostics.swift | 2 +- .../SyntaxKindNameForDiagnostics.swift | 2 +- .../generated/TokenNameForDiagnostics.swift | 2 +- .../generated/ChildNameForKeyPath.swift | 2 +- Sources/SwiftSyntax/generated/Keyword.swift | 2 +- .../RenamedChildrenCompatibility.swift | 2 +- .../generated/RenamedNodesCompatibility.swift | 2 +- .../generated/SyntaxAnyVisitor.swift | 2 +- .../generated/SyntaxBaseNodes.swift | 2 +- .../generated/SyntaxCollections.swift | 2 +- .../SwiftSyntax/generated/SyntaxEnum.swift | 2 +- .../SwiftSyntax/generated/SyntaxKind.swift | 2 +- .../generated/SyntaxRewriter.swift | 2 +- .../SwiftSyntax/generated/SyntaxTraits.swift | 2 +- .../generated/SyntaxTransform.swift | 2 +- .../SwiftSyntax/generated/SyntaxVisitor.swift | 2 +- Sources/SwiftSyntax/generated/TokenKind.swift | 2 +- Sources/SwiftSyntax/generated/Tokens.swift | 2 +- .../SwiftSyntax/generated/TriviaPieces.swift | 2 +- .../generated/raw/RawSyntaxValidation.swift | 2 +- .../generated/syntaxNodes/SyntaxNodesAB.swift | 2 +- .../generated/syntaxNodes/SyntaxNodesC.swift | 2 +- .../generated/syntaxNodes/SyntaxNodesD.swift | 2 +- .../generated/syntaxNodes/SyntaxNodesEF.swift | 2 +- .../syntaxNodes/SyntaxNodesGHI.swift | 2 +- .../syntaxNodes/SyntaxNodesJKLMN.swift | 2 +- .../generated/syntaxNodes/SyntaxNodesOP.swift | 2 +- .../syntaxNodes/SyntaxNodesQRS.swift | 2 +- .../syntaxNodes/SyntaxNodesTUVWXYZ.swift | 2 +- .../generated/BuildableNodes.swift | 2 +- .../RenamedChildrenBuilderCompatibility.swift | 2 +- .../generated/ResultBuilders.swift | 2 +- ...bleByStringInterpolationConformances.swift | 2 +- build-script.py | 726 ++++++++++++++++++ 77 files changed, 834 insertions(+), 42 deletions(-) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/GenerateSwiftSyntax.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/LayoutNode+Extensions.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/Array+Child.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftparser/IsLexerClassifiedFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftparser/ParserEntryFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftparser/ParserTokenSpecSetFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftparser/TokenSpecStaticMembersFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/ChildNameForKeyPathFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/KeywordFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/RawSyntaxNodesFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/RawSyntaxValidationFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/RenamedSyntaxNodesFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SwiftSyntaxDoccIndexTemplate.md (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxAnyVisitorFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxBaseNodesFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxCollectionsFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxEnumFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxKindFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxNodesFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxRewriterFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxTraitsFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxTransformFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/SyntaxVisitorFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/TokenKindFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/TokensFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntax/TriviaPiecesFile.swift (100%) create mode 100644 CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntaxbuilder/BuildableNodesFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntaxbuilder/ResultBuildersFile.swift (100%) rename CodeGeneration/Sources/{generate-swiftsyntax => generate-swift-syntax}/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift (100%) create mode 100755 build-script.py diff --git a/CodeGeneration/Package.swift b/CodeGeneration/Package.swift index a497b898e00..c537d705ca8 100644 --- a/CodeGeneration/Package.swift +++ b/CodeGeneration/Package.swift @@ -9,7 +9,7 @@ let package = Package( .macOS(.v10_15) ], products: [ - .executable(name: "generate-swiftsyntax", targets: ["generate-swiftsyntax"]) + .executable(name: "generate-swift-syntax", targets: ["generate-swift-syntax"]) ], dependencies: [ // This directory is a standalone package that uses swift-syntax from the @@ -26,7 +26,7 @@ let package = Package( ], targets: [ .executableTarget( - name: "generate-swiftsyntax", + name: "generate-swift-syntax", dependencies: [ .product(name: "SwiftSyntax", package: "swift-syntax"), .product(name: "SwiftSyntaxBuilder", package: "swift-syntax"), diff --git a/CodeGeneration/README.md b/CodeGeneration/README.md index f67a68c9487..b7e7b561f24 100644 --- a/CodeGeneration/README.md +++ b/CodeGeneration/README.md @@ -15,12 +15,12 @@ to ``` 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-swiftsyntax` +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. On the command line, this would be ```bash -swift run --package-path CodeGeneration generate-swiftsyntax Sources +swift run --package-path CodeGeneration generate-swift-syntax Sources ``` Or if you open the `CodeGeneration` package in Xcode, you can add the diff --git a/CodeGeneration/Sources/Utils/CopyrightHeader.swift b/CodeGeneration/Sources/Utils/CopyrightHeader.swift index 35360c2da3c..25dd003c743 100644 --- a/CodeGeneration/Sources/Utils/CopyrightHeader.swift +++ b/CodeGeneration/Sources/Utils/CopyrightHeader.swift @@ -14,7 +14,7 @@ import SwiftSyntax public var copyrightHeader: Trivia = """ - //// Automatically generated by generate-swiftsyntax + //// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift b/CodeGeneration/Sources/generate-swift-syntax/GenerateSwiftSyntax.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift rename to CodeGeneration/Sources/generate-swift-syntax/GenerateSwiftSyntax.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/LayoutNode+Extensions.swift b/CodeGeneration/Sources/generate-swift-syntax/LayoutNode+Extensions.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/LayoutNode+Extensions.swift rename to CodeGeneration/Sources/generate-swift-syntax/LayoutNode+Extensions.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/Array+Child.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/Array+Child.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/Array+Child.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/Array+Child.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/IsLexerClassifiedFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/IsLexerClassifiedFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/IsLexerClassifiedFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/IsLexerClassifiedFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserEntryFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserEntryFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserEntryFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserEntryFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/TokenSpecStaticMembersFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/TokenSpecStaticMembersFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/TokenSpecStaticMembersFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/TokenSpecStaticMembersFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/ChildNameForKeyPathFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/ChildNameForKeyPathFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/ChildNameForKeyPathFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/ChildNameForKeyPathFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/KeywordFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/KeywordFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/KeywordFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/KeywordFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxNodesFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxValidationFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxValidationFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxValidationFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxValidationFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RenamedSyntaxNodesFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SwiftSyntaxDoccIndexTemplate.md b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndexTemplate.md similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SwiftSyntaxDoccIndexTemplate.md rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndexTemplate.md diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxAnyVisitorFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxAnyVisitorFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxAnyVisitorFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxAnyVisitorFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxCollectionsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxCollectionsFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxCollectionsFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxEnumFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxEnumFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxEnumFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxEnumFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxKindFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxKindFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxKindFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxKindFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxNodesFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxRewriterFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxRewriterFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxTraitsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxTraitsFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxTraitsFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxTraitsFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxTransformFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxTransformFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxTransformFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxTransformFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxVisitorFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxVisitorFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxVisitorFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxVisitorFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokenKindFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/TokenKindFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokenKindFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/TokenKindFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokensFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/TokensFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TokensFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/TokensFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaPiecesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/TriviaPiecesFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaPiecesFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/TriviaPiecesFile.swift diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift new file mode 100644 index 00000000000..bda1ed6a3f7 --- /dev/null +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftSyntax +import SwiftSyntaxBuilder +import SyntaxSupport +import Utils +import SwiftBasicFormat + +let buildableCollectionNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { + DeclSyntax("import SwiftSyntax") + + for node in SYNTAX_NODES.compactMap(\.collectionNode) { + let elementType = node.collectionElementType + + let docComment = + node.documentation.isEmpty + ? [.docLineComment("/// `\(node.kind.syntaxType)` represents a collection of `\(elementType.syntaxBaseName)`")] + : node.documentation + // Generate collection node struct + try! ExtensionDeclSyntax( + """ + \(raw: docComment) + extension \(raw: node.type.syntaxBaseName): ExpressibleByArrayLiteral + """ + ) { + // Generate initializers + if elementType.isBaseType && node.elementChoices.count == 1 { + DeclSyntax( + """ + public init(_ elements: \(ArrayTypeSyntax(element: elementType.parameterType))) { + self = \(raw: node.type.syntaxBaseName)(elements.map { + \(elementType.syntax)(fromProtocol: $0) + } as [\(elementType.syntax)]) + } + """ + ) + + DeclSyntax( + """ + public init(arrayLiteral elements: \(elementType.parameterType)...) { + self.init(elements) + } + """ + ) + } else { + DeclSyntax( + """ + public init(arrayLiteral elements: Element...) { + self.init(elements) + } + """ + ) + } + } + } +} diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift similarity index 100% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift rename to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift diff --git a/Sources/SwiftParser/generated/IsLexerClassified.swift b/Sources/SwiftParser/generated/IsLexerClassified.swift index 5beadf94802..309c49d58cc 100644 --- a/Sources/SwiftParser/generated/IsLexerClassified.swift +++ b/Sources/SwiftParser/generated/IsLexerClassified.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift b/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift index 81cc422106e..6d85fce7971 100644 --- a/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift +++ b/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift index 731685bfe29..492b4085f01 100644 --- a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift +++ b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift b/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift index 6df8195bd1a..7f0f81a9ba7 100644 --- a/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift +++ b/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift index 0822411e14d..2644f78ef3e 100644 --- a/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift index 7e566689464..a53c595a569 100644 --- a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift index 08e7f6ffde7..48e229bafb4 100644 --- a/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift index d24377695b0..e30fc7f2924 100644 --- a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift +++ b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/Keyword.swift b/Sources/SwiftSyntax/generated/Keyword.swift index 01a32f31370..7d1b0927114 100644 --- a/Sources/SwiftSyntax/generated/Keyword.swift +++ b/Sources/SwiftSyntax/generated/Keyword.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift b/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift index bb5d1af7b40..8046f48d3a2 100644 --- a/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift +++ b/Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift b/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift index 6da4dd3138f..1d28a95519a 100644 --- a/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift +++ b/Sources/SwiftSyntax/generated/RenamedNodesCompatibility.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift index 1db7d6a5398..28044024525 100644 --- a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift index a4a70e3ed76..500f478c827 100644 --- a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxCollections.swift b/Sources/SwiftSyntax/generated/SyntaxCollections.swift index 2e3bae9600a..44055d3db14 100644 --- a/Sources/SwiftSyntax/generated/SyntaxCollections.swift +++ b/Sources/SwiftSyntax/generated/SyntaxCollections.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxEnum.swift b/Sources/SwiftSyntax/generated/SyntaxEnum.swift index 5c4e916165f..f85889c3216 100644 --- a/Sources/SwiftSyntax/generated/SyntaxEnum.swift +++ b/Sources/SwiftSyntax/generated/SyntaxEnum.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxKind.swift b/Sources/SwiftSyntax/generated/SyntaxKind.swift index 0e88a337662..54bd33b28d0 100644 --- a/Sources/SwiftSyntax/generated/SyntaxKind.swift +++ b/Sources/SwiftSyntax/generated/SyntaxKind.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift index 7a8f5b154c0..3589db93a3c 100644 --- a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift +++ b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxTraits.swift b/Sources/SwiftSyntax/generated/SyntaxTraits.swift index 56d2259f51a..ac625a859de 100644 --- a/Sources/SwiftSyntax/generated/SyntaxTraits.swift +++ b/Sources/SwiftSyntax/generated/SyntaxTraits.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxTransform.swift b/Sources/SwiftSyntax/generated/SyntaxTransform.swift index 0c2ff101660..f249d3e3587 100644 --- a/Sources/SwiftSyntax/generated/SyntaxTransform.swift +++ b/Sources/SwiftSyntax/generated/SyntaxTransform.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift index 3f7faa3716a..b297d7abb25 100644 --- a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/TokenKind.swift b/Sources/SwiftSyntax/generated/TokenKind.swift index 5c049fcc823..d4c0e30a8e8 100644 --- a/Sources/SwiftSyntax/generated/TokenKind.swift +++ b/Sources/SwiftSyntax/generated/TokenKind.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/Tokens.swift b/Sources/SwiftSyntax/generated/Tokens.swift index 35d0e19ea09..2e703556120 100644 --- a/Sources/SwiftSyntax/generated/Tokens.swift +++ b/Sources/SwiftSyntax/generated/Tokens.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/TriviaPieces.swift b/Sources/SwiftSyntax/generated/TriviaPieces.swift index 9e8e4ec4bfb..44d83e69265 100644 --- a/Sources/SwiftSyntax/generated/TriviaPieces.swift +++ b/Sources/SwiftSyntax/generated/TriviaPieces.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index 932858397df..93e184955ad 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift index c566c34dcec..6b590224dc5 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift index 1e8a259d75b..52239b19e75 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift index d17d283258b..ceddef526b0 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesEF.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesEF.swift index 7ff41fc2a22..cf27f9a296b 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesEF.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesEF.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift index 46647f8ad59..3365abfae0b 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesGHI.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift index 79586bbd16b..82eba2ab903 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesOP.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesOP.swift index 8d19562bf92..8217bac5dde 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesOP.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesOP.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift index 3b1f22c40af..d5c19b991db 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift index d7ee6d106b4..cf66a130e67 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift b/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift index aba990eb121..78c163ce7d3 100644 --- a/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift +++ b/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift b/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift index 3bf72501a9c..47b8759a5b9 100644 --- a/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift +++ b/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift index dfb706efbea..ad23a569c42 100644 --- a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift +++ b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift b/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift index 3c5386c1cf6..32c185bf318 100644 --- a/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift +++ b/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift @@ -1,4 +1,4 @@ -//// Automatically generated by generate-swiftsyntax +//// Automatically generated by generate-swift-syntax //// Do not edit directly! //===----------------------------------------------------------------------===// // diff --git a/build-script.py b/build-script.py new file mode 100755 index 00000000000..e3da995c4fa --- /dev/null +++ b/build-script.py @@ -0,0 +1,726 @@ +#!/usr/bin/env python3 + +import argparse +import os +import platform +import subprocess +import sys +import tempfile +from typing import Dict, List, Optional + + +# ----------------------------------------------------------------------------- +# Constants + +PACKAGE_DIR = os.path.dirname(os.path.realpath(__file__)) +WORKSPACE_DIR = os.path.dirname(PACKAGE_DIR) +EXAMPLES_DIR = os.path.join(PACKAGE_DIR, "Examples") +SOURCES_DIR = os.path.join(PACKAGE_DIR, "Sources") +TESTS_DIR = os.path.join(PACKAGE_DIR, "Tests") +SWIFTIDEUTILS_DIR = os.path.join(SOURCES_DIR, "SwiftIDEUtils") +SWIFTSYNTAX_DIR = os.path.join(SOURCES_DIR, "SwiftSyntax") +SWIFTSYNTAX_DOCUMENTATION_DIR = \ + os.path.join(SWIFTSYNTAX_DIR, "Documentation.docc") +SWIFTBASICFORMAT_DIR = os.path.join(SOURCES_DIR, "SwiftBasicFormat") +SWIFTSYNTAXBUILDER_DIR = os.path.join(SOURCES_DIR, "SwiftSyntaxBuilder") +SWIFTPARSER_DIR = os.path.join(SOURCES_DIR, "SwiftParser") + +CODE_GENERATION_DIR = os.path.join(PACKAGE_DIR, "CodeGeneration") +SYNTAXSUPPORT_DIR = \ + os.path.join(CODE_GENERATION_DIR, "Sources", "SyntaxSupport") + +LLVM_DIR = os.path.join(WORKSPACE_DIR, "llvm-project", "llvm") +SWIFT_DIR = os.path.join(WORKSPACE_DIR, "swift") + +LIT_EXEC = os.path.join(LLVM_DIR, "utils", "lit", "lit.py") + +GROUP_INFO_PATH = os.path.join(PACKAGE_DIR, "utils", "group.json") + + +def fail_for_called_process_error( + succinct_description: str, + error: subprocess.CalledProcessError +) -> None: + printerr(f"FAIL: {succinct_description}") + printerr(f"Executing: {escapeCmd(error.cmd)}") + printerr(error.output) + raise SystemExit(1) + + +# ----------------------------------------------------------------------------- +# Xcode Projects Generation + + +def xcode_gen(config: str) -> None: + print("** Generate SwiftSyntax as an Xcode project **") + os.chdir(PACKAGE_DIR) + swiftpm_call = ["swift", "package", "generate-xcodeproj"] + if config: + swiftpm_call.extend(["--xcconfig-overrides", config]) + check_call(swiftpm_call) + + +# ----------------------------------------------------------------------------- +# Helpers + + +def printerr(message: str) -> None: + print(message, file=sys.stderr) + + +def note(message: str) -> None: + print("--- %s: note: %s" % (os.path.basename(sys.argv[0]), message)) + sys.stdout.flush() + + +def fatal_error(message: str) -> None: + printerr(message) + raise SystemExit(1) + + +def escapeCmdArg(arg: str) -> str: + if '"' in arg or " " in arg: + return '"%s"' % arg.replace('"', '\\"') + else: + return arg + + +def escapeCmd(cmd: List[str]) -> str: + return " ".join([escapeCmdArg(arg) for arg in cmd]) + + +def call(cmd: List[str], env: Dict[str, str] = dict(os.environ), + stdout: Optional[int] = None, stderr: Optional[int] = subprocess.STDOUT, + verbose: bool = False) -> int: + if verbose: + print(escapeCmd(cmd)) + process = subprocess.Popen(cmd, env=env, stdout=stdout, stderr=stderr) + process.wait() + + return process.returncode + + +def check_call(cmd: List[str], cwd: Optional[str] = None, + env: Dict[str, str] = dict(os.environ), verbose: bool = False) -> None: + if verbose: + print(escapeCmd(cmd)) + subprocess.check_call(cmd, cwd=cwd, env=env, stderr=subprocess.STDOUT) + + +def realpath(path: Optional[str]) -> Optional[str]: + if path is None: + return None + return os.path.realpath(path) + + +# ----------------------------------------------------------------------------- +# Generating Files + + +def run_code_generation( + source_dir: str, + toolchain: str, + verbose: bool +) -> None: + print("** Running code generation **") + + swift_exec = os.path.join(toolchain, "bin", "swift") + + swiftpm_call = [ + swift_exec, 'run', + "--package-path", CODE_GENERATION_DIR, + "generate-swift-syntax", source_dir + ] + + if verbose: + swiftpm_call.extend(["--verbose"]) + + env = dict(os.environ) + env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" + env["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" + env["SWIFTCI_USE_LOCAL_DEPS"] = "1" + check_call(swiftpm_call, env=env, verbose=verbose) + + +# ----------------------------------------------------------------------------- +# Building SwiftSyntax + + +def get_swiftpm_invocation( + toolchain: str, action: str, package_dir: str, build_dir: Optional[str], + multiroot_data_file: Optional[str], release: bool +) -> List[str]: + swift_exec = os.path.join(toolchain, "bin", "swift") + + swiftpm_call = [swift_exec, action] + swiftpm_call.extend(["--package-path", package_dir]) + if platform.system() != "Darwin": + swiftpm_call.extend(["--enable-test-discovery"]) + if release: + swiftpm_call.extend(["--configuration", "release"]) + if build_dir: + swiftpm_call.extend(["--scratch-path", build_dir]) + if multiroot_data_file: + swiftpm_call.extend(["--multiroot-data-file", multiroot_data_file]) + + return swiftpm_call + + +class Builder(object): + verbose: bool + toolchain: str + build_dir: Optional[str] + multiroot_data_file: Optional[str] + release: bool + enable_rawsyntax_validation: bool + enable_test_fuzzing: bool + disable_sandbox: bool + + def __init__( + self, + toolchain: str, + build_dir: Optional[str], + multiroot_data_file: Optional[str], + release: bool, + enable_rawsyntax_validation: bool, + enable_test_fuzzing: bool, + verbose: bool, + disable_sandbox: bool = False, + ) -> None: + self.build_dir = build_dir + self.multiroot_data_file = multiroot_data_file + self.release = release + self.enable_rawsyntax_validation = enable_rawsyntax_validation + self.enable_test_fuzzing = enable_test_fuzzing + self.disable_sandbox = disable_sandbox + self.verbose = verbose + self.toolchain = toolchain + + def __get_swiftpm_invocation(self, package_dir: str) -> List[str]: + invocation = get_swiftpm_invocation( + self.toolchain, + "build", + package_dir, + self.build_dir, + self.multiroot_data_file, + self.release + ) + if self.disable_sandbox: + invocation.append("--disable-sandbox") + if self.verbose: + invocation.append("--verbose") + return invocation + + def buildProduct(self, product_name: str) -> None: + print("** Building product " + product_name + " **") + self.__build(PACKAGE_DIR, product_name, is_product=True) + + def buildTarget(self, package_dir: str, target_name: str) -> None: + print("** Building target " + target_name + " **") + self.__build(package_dir, target_name, is_product=False) + + def buildExample(self, example_name: str) -> None: + print("** Building example " + example_name + " **") + self.__build(EXAMPLES_DIR, example_name, is_product=True) + + def __build(self, package_dir: str, name: str, is_product: bool) -> None: + command = list(self.__get_swiftpm_invocation(package_dir)) + command.extend(["--product" if is_product else "--target", name]) + + env = dict(os.environ) + env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" + if self.enable_rawsyntax_validation: + env["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" + if self.enable_test_fuzzing: + env["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1" + # Tell other projects in the unified build to use local dependencies + env["SWIFTCI_USE_LOCAL_DEPS"] = "1" + env["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = \ + os.path.join(self.toolchain, "lib", "swift", "macosx") + + check_call(command, env=env, verbose=self.verbose) + + +# ----------------------------------------------------------------------------- +# Testing + + +def verify_code_generated_files( + toolchain: str, verbose: bool +) -> None: + self_temp_dir = tempfile.mkdtemp() + + try: + run_code_generation( + source_dir=self_temp_dir, + toolchain=toolchain, + verbose=verbose + ) + except subprocess.CalledProcessError as e: + fail_for_called_process_error( + "Source generation using SwiftSyntaxBuilder failed", + e + ) + + print("** Verifing code generated files **") + + for module in ["SwiftParser", "SwiftParserDiagnostics", \ + "SwiftSyntax", "SwiftSyntaxBuilder"]: + self_generated_dir = os.path.join(self_temp_dir, module, "generated") + user_generated_dir = os.path.join(SOURCES_DIR, module, "generated") + check_generated_files_match(self_generated_dir, user_generated_dir) + + +def check_generated_files_match(self_generated_dir: str, + user_generated_dir: str) -> None: + command = [ + "diff", + "--recursive", + "--exclude", + ".*", # Exclude dot files like .DS_Store + "--context=0", + self_generated_dir, + user_generated_dir, + ] + check_call(command) + + +def run_code_generation_tests( + toolchain: str, + verbose: bool +) -> None: + print("** Running CodeGeneration tests **") + + swift_exec = os.path.join(toolchain, "bin", "swift") + + swiftpm_call = [ + swift_exec, 'test', + "--package-path", CODE_GENERATION_DIR + ] + + if verbose: + swiftpm_call.extend(["--verbose"]) + + env = dict(os.environ) + env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" + env["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" + env["SWIFTCI_USE_LOCAL_DEPS"] = "1" + check_call(swiftpm_call, env=env, verbose=verbose) + + +def run_tests( + toolchain: str, + build_dir: Optional[str], + multiroot_data_file: Optional[str], + release: bool, + enable_rawsyntax_validation: bool, + enable_test_fuzzing: bool, + filecheck_exec: Optional[str], + skip_lit_tests: bool, + verbose: bool +) -> None: + print("** Running SwiftSyntax Tests **") + + if not skip_lit_tests: + run_lit_tests( + toolchain=toolchain, + build_dir=build_dir, + release=release, + filecheck_exec=filecheck_exec, + verbose=verbose, + ) + + run_xctests( + package_dir=PACKAGE_DIR, + test_product="swift-syntaxPackageTests", + toolchain=toolchain, + build_dir=build_dir, + multiroot_data_file=multiroot_data_file, + release=release, + enable_rawsyntax_validation=enable_rawsyntax_validation, + enable_test_fuzzing=enable_test_fuzzing, + verbose=verbose, + ) + + run_code_generation_tests( + toolchain=toolchain, + verbose=verbose, + ) + +# ----------------------------------------------------------------------------- +# Lit Tests + + +def check_lit_exec() -> None: + if not os.path.exists(LIT_EXEC): + fatal_error( + """ +Error: Could not find lit.py. +Looking at '%s'. + +Make sure you have the llvm repo checked out next to the swift-syntax repo. +Refer to README.md for more information. +""" + % LIT_EXEC + ) + + +def find_swiftpm_bin_path( + package_dir: str, toolchain: str, build_dir: Optional[str], release: bool +) -> str: + swiftpm_call = get_swiftpm_invocation( + toolchain=toolchain, + action="build", + package_dir=package_dir, + build_dir=build_dir, + multiroot_data_file=None, + release=release, + ) + swiftpm_call.extend(["--show-bin-path"]) + + bin_dir = subprocess.check_output(swiftpm_call) + return bin_dir.strip().decode('utf-8') + + +def find_product_bin_path( + toolchain: str, build_dir: Optional[str], release: bool +) -> str: + return find_swiftpm_bin_path(PACKAGE_DIR, toolchain, build_dir, release) + + +def find_examples_bin_path( + toolchain: str, build_dir: Optional[str], release: bool +) -> str: + return find_swiftpm_bin_path(EXAMPLES_DIR, toolchain, build_dir, release) + + +def run_lit_tests(toolchain: str, build_dir: Optional[str], release: bool, + filecheck_exec: Optional[str], verbose: bool) -> None: + print("** Running lit-based tests **") + + check_lit_exec() + + product_bin_path = find_product_bin_path( + toolchain=toolchain, build_dir=build_dir, release=release) + examples_bin_path = find_examples_bin_path( + toolchain=toolchain, build_dir=build_dir, release=release) + + lit_test_helper_exec = os.path.join(product_bin_path, "lit-test-helper") + + lit_call = ["python3", LIT_EXEC] + lit_call.append(os.path.join(PACKAGE_DIR, "lit_tests")) + + if filecheck_exec: + lit_call.extend(["--param", "FILECHECK=" + filecheck_exec]) + if lit_test_helper_exec: + lit_call.extend(["--param", "LIT_TEST_HELPER=" + lit_test_helper_exec]) + lit_call.extend(["--param", "EXAMPLES_BIN_PATH=" + examples_bin_path]) + lit_call.extend(["--param", "TOOLCHAIN=" + toolchain]) + + # Print all failures + lit_call.extend(["--verbose"]) + # Don't show all commands if verbose is not enabled + if not verbose: + lit_call.extend(["--succinct"]) + check_call(lit_call, verbose=verbose) + + +# ----------------------------------------------------------------------------- +# XCTest Tests + + +def run_xctests( + package_dir: str, + test_product: str, + toolchain: str, + build_dir: Optional[str], + multiroot_data_file: Optional[str], + release: bool, + enable_rawsyntax_validation: bool, + enable_test_fuzzing: bool, + verbose: bool +) -> None: + print("** Running XCTests **") + swiftpm_call = get_swiftpm_invocation( + toolchain=toolchain, + action="test", + package_dir=package_dir, + build_dir=build_dir, + multiroot_data_file=multiroot_data_file, + release=release, + ) + + if verbose: + swiftpm_call.extend(["--verbose"]) + + swiftpm_call.extend(["--test-product", test_product]) + + env = dict(os.environ) + env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" + if enable_rawsyntax_validation: + env["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" + if enable_test_fuzzing: + env["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1" + # Tell other projects in the unified build to use local dependencies + env["SWIFTCI_USE_LOCAL_DEPS"] = "1" + env["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = \ + os.path.join(toolchain, "lib", "swift", "macosx") + + check_call(swiftpm_call, env=env, verbose=verbose) + +# ----------------------------------------------------------------------------- +# Arugment Parsing functions + + +def generate_xcodeproj(args: argparse.Namespace) -> None: + xcode_gen(config=args.xcconfig_path) + + +def generate_source_code_command(args: argparse.Namespace) -> None: + try: + run_code_generation( + source_dir=SOURCES_DIR, + toolchain=args.toolchain, + verbose=args.verbose + ) + except subprocess.CalledProcessError as e: + fail_for_called_process_error( + "Source generation using SwiftSyntaxBuilder failed", e) + + +def verify_source_code_command(args: argparse.Namespace) -> None: + try: + verify_code_generated_files( + toolchain=args.toolchain, + verbose=args.verbose, + ) + except subprocess.CalledProcessError: + printerr( + "FAIL: code-generated files committed to repository do " + + "not match generated ones. Please re-generate the " + + "code-generated-files using the following command, open a PR to the " + + "SwiftSyntax project and merge it alongside the main PR." + + "$ swift-syntax/build-script.py generate-source-code " + + "--toolchain /path/to/toolchain.xctoolchain/usr" + ) + raise SystemExit(1) + + +def build_command(args: argparse.Namespace) -> None: + try: + builder = Builder( + toolchain=realpath(args.toolchain), # pyright: ignore + build_dir=realpath(args.build_dir), + multiroot_data_file=args.multiroot_data_file, + release=args.release, + enable_rawsyntax_validation=args.enable_rawsyntax_validation, + enable_test_fuzzing=args.enable_test_fuzzing, + verbose=args.verbose, + disable_sandbox=args.disable_sandbox, + ) + builder.buildTarget(PACKAGE_DIR, "SwiftSyntax-all") + builder.buildTarget(EXAMPLES_DIR, "Examples-all") + except subprocess.CalledProcessError as e: + fail_for_called_process_error("Building SwiftSyntax failed", e) + + +def test_command(args: argparse.Namespace) -> None: + try: + builder = Builder( + toolchain=realpath(args.toolchain), # pyright: ignore + build_dir=realpath(args.build_dir), + multiroot_data_file=args.multiroot_data_file, + release=args.release, + enable_rawsyntax_validation=args.enable_rawsyntax_validation, + enable_test_fuzzing=args.enable_test_fuzzing, + verbose=args.verbose, + disable_sandbox=args.disable_sandbox, + ) + + builder.buildProduct("lit-test-helper") + builder.buildExample("ExamplePlugin") + + run_tests( + toolchain=realpath(args.toolchain), # pyright: ignore + build_dir=realpath(args.build_dir), + multiroot_data_file=args.multiroot_data_file, + release=args.release, + enable_rawsyntax_validation=args.enable_rawsyntax_validation, + enable_test_fuzzing=args.enable_test_fuzzing, + filecheck_exec=realpath(args.filecheck_exec), + skip_lit_tests=args.skip_lit_tests, + verbose=args.verbose, + ) + print("** All tests passed **") + except subprocess.CalledProcessError as e: + fail_for_called_process_error("Running tests failed", e) + + +# ----------------------------------------------------------------------------- +# Argument Parsing + +_DESCRIPTION = """ +Build and test script for SwiftSyntax. + +The build script can also drive the test suite included in the SwiftSyntax +repo. This requires a custom build of the compiler project since it accesses +test utilities that are not shipped as part of the toolchains. See the Testing +section for arguments that need to be specified for this. +""" + + +def parse_args() -> argparse.Namespace: + def add_default_build_arguments(parser: argparse.ArgumentParser) -> None: + parser.add_argument( + "-r", "--release", action="store_true", help="Build in release mode." + ) + + parser.add_argument( + "--build-dir", + default=None, + help=""" + The directory in which build products shall be put. If omitted + a directory named ".build" will be put in the swift-syntax + directory. + """, + ) + + parser.add_argument( + "--disable-sandbox", + action="store_true", + help="Disable sandboxes when building with SwiftPM", + ) + + parser.add_argument( + "--multiroot-data-file", + help=""" + Path to an Xcode workspace to create a unified build of SwiftSyntax with + other projects. + """, + ) + + parser.add_argument( + "--enable-rawsyntax-validation", + action="store_true", + help=""" + When constructing RawSyntax nodes validate that their layout matches that + defined in `CodeGeneration` and that TokenSyntax nodes have a `tokenKind` + matching the ones specified in `CodeGeneration`. + """ + ) + + parser.add_argument( + "--enable-test-fuzzing", + action="store_true", + help=""" + For each `assertParse` test, perform mutations of the test case based on + alternate token choices that the parser checks, validating that there are + no round-trip or assertion failures. + """ + ) + + parser.add_argument( + "--toolchain", + required=True, + help="The path to the toolchain that shall be used to build SwiftSyntax.", + ) + + parser.add_argument( + "-v", "--verbose", action="store_true", help="Enable verbose logging." + ) + + def add_generate_source_code_args(parser: argparse.ArgumentParser) -> None: + parser.add_argument( + "--toolchain", + required=True, + help="The path to the toolchain that shall be used to build SwiftSyntax.", + ) + + parser.add_argument( + "-v", "--verbose", action="store_true", help="Enable verbose logging." + ) + + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, description=_DESCRIPTION + ) + + # ------------------------------------------------------------------------- + # Shared arguments + + sub_parsers = parser.add_subparsers() + + # ------------------------------------------------------------------------- + generate_xcodeproj_parser = sub_parsers.add_parser( + "generate-xcodeproj", + help="Generate an Xcode project for SwiftSyntax." + ) + generate_xcodeproj_parser.set_defaults(func=generate_xcodeproj) + + generate_xcodeproj_parser.add_argument( + "--xcconfig-path", + help="The path to an xcconfig file for generating Xcode projct.", + ) + + generate_xcodeproj_parser.add_argument( + "-v", "--verbose", action="store_true", help="Enable verbose logging." + ) + + # ------------------------------------------------------------------------- + generate_source_code_parser = sub_parsers.add_parser("generate-source-code") + generate_source_code_parser.set_defaults(func=generate_source_code_command) + + add_generate_source_code_args(generate_source_code_parser) + + generate_source_code_parser.add_argument( + "--add-source-locations", + action="store_true", + help=""" + Insert ###sourceLocation comments in generated code for line-directive. + """, + ) + + # ------------------------------------------------------------------------- + build_parser = sub_parsers.add_parser("build") + build_parser.set_defaults(func=build_command) + + add_default_build_arguments(build_parser) + + # ------------------------------------------------------------------------- + test_parser = sub_parsers.add_parser("test") + test_parser.set_defaults(func=test_command) + + add_default_build_arguments(test_parser) + + test_parser.add_argument( + "--skip-lit-tests", action="store_true", + help="Don't run lit-based tests" + ) + + test_parser.add_argument( + "--filecheck-exec", + default=None, + help=""" + Path to the FileCheck executable that was built as part of the LLVM repository. + If not specified, it will be looked up from PATH. + """, + ) + + # ------------------------------------------------------------------------- + verify_source_code_parser = sub_parsers.add_parser("verify-source-code") + verify_source_code_parser.set_defaults(func=verify_source_code_command) + + add_generate_source_code_args(verify_source_code_parser) + + return parser.parse_args() + + +# ----------------------------------------------------------------------------- + + +def main() -> None: + args = parse_args() + args.func(args) + + +if __name__ == "__main__": + main() From b7bc8625c9380e630fb5837419b33c9604506a98 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 23 Aug 2023 07:56:40 -0700 Subject: [PATCH 2/2] Adjustments to fix build failures after rebase --- .../BuildableCollectionNodesFile.swift | 66 -- .../Contributing/ChangingSwiftSyntax.md | 4 +- .../common/SourceCodeGeneratorCommand.swift | 2 +- build-script.py | 726 ------------------ 4 files changed, 3 insertions(+), 795 deletions(-) delete mode 100644 CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift delete mode 100755 build-script.py diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift deleted file mode 100644 index bda1ed6a3f7..00000000000 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -import SwiftSyntax -import SwiftSyntaxBuilder -import SyntaxSupport -import Utils -import SwiftBasicFormat - -let buildableCollectionNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax("import SwiftSyntax") - - for node in SYNTAX_NODES.compactMap(\.collectionNode) { - let elementType = node.collectionElementType - - let docComment = - node.documentation.isEmpty - ? [.docLineComment("/// `\(node.kind.syntaxType)` represents a collection of `\(elementType.syntaxBaseName)`")] - : node.documentation - // Generate collection node struct - try! ExtensionDeclSyntax( - """ - \(raw: docComment) - extension \(raw: node.type.syntaxBaseName): ExpressibleByArrayLiteral - """ - ) { - // Generate initializers - if elementType.isBaseType && node.elementChoices.count == 1 { - DeclSyntax( - """ - public init(_ elements: \(ArrayTypeSyntax(element: elementType.parameterType))) { - self = \(raw: node.type.syntaxBaseName)(elements.map { - \(elementType.syntax)(fromProtocol: $0) - } as [\(elementType.syntax)]) - } - """ - ) - - DeclSyntax( - """ - public init(arrayLiteral elements: \(elementType.parameterType)...) { - self.init(elements) - } - """ - ) - } else { - DeclSyntax( - """ - public init(arrayLiteral elements: Element...) { - self.init(elements) - } - """ - ) - } - } - } -} diff --git a/Sources/SwiftSyntax/Documentation.docc/Contributing/ChangingSwiftSyntax.md b/Sources/SwiftSyntax/Documentation.docc/Contributing/ChangingSwiftSyntax.md index fab11e6a1f9..dfeabbfe5d4 100644 --- a/Sources/SwiftSyntax/Documentation.docc/Contributing/ChangingSwiftSyntax.md +++ b/Sources/SwiftSyntax/Documentation.docc/Contributing/ChangingSwiftSyntax.md @@ -11,12 +11,12 @@ structures in sync, this project generates code using the Swift package ## Regenerating Files -To re-generate the files after changing `CodeGeneration` run the `generate-swiftsyntax` +To re-generate the files after changing `CodeGeneration` run the `generate-swift-syntax` target of `CodeGeneration`. On the command line, this would be ```bash -swift run --package-path CodeGeneration generate-swiftsyntax +swift run --package-path CodeGeneration generate-swift-syntax ``` ## Adding and Removing Syntax Nodes diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/SourceCodeGeneratorCommand.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/SourceCodeGeneratorCommand.swift index 44bacb934d7..90c1f7ec392 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/SourceCodeGeneratorCommand.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/SourceCodeGeneratorCommand.swift @@ -26,7 +26,7 @@ extension SourceCodeGeneratorCommand { var args = [ "run", "--package-path", Paths.codeGenerationDir.relativePath, - "generate-swiftsyntax", sourceDir.relativePath, + "generate-swift-syntax", sourceDir.relativePath, ] if arguments.verbose { diff --git a/build-script.py b/build-script.py deleted file mode 100755 index e3da995c4fa..00000000000 --- a/build-script.py +++ /dev/null @@ -1,726 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os -import platform -import subprocess -import sys -import tempfile -from typing import Dict, List, Optional - - -# ----------------------------------------------------------------------------- -# Constants - -PACKAGE_DIR = os.path.dirname(os.path.realpath(__file__)) -WORKSPACE_DIR = os.path.dirname(PACKAGE_DIR) -EXAMPLES_DIR = os.path.join(PACKAGE_DIR, "Examples") -SOURCES_DIR = os.path.join(PACKAGE_DIR, "Sources") -TESTS_DIR = os.path.join(PACKAGE_DIR, "Tests") -SWIFTIDEUTILS_DIR = os.path.join(SOURCES_DIR, "SwiftIDEUtils") -SWIFTSYNTAX_DIR = os.path.join(SOURCES_DIR, "SwiftSyntax") -SWIFTSYNTAX_DOCUMENTATION_DIR = \ - os.path.join(SWIFTSYNTAX_DIR, "Documentation.docc") -SWIFTBASICFORMAT_DIR = os.path.join(SOURCES_DIR, "SwiftBasicFormat") -SWIFTSYNTAXBUILDER_DIR = os.path.join(SOURCES_DIR, "SwiftSyntaxBuilder") -SWIFTPARSER_DIR = os.path.join(SOURCES_DIR, "SwiftParser") - -CODE_GENERATION_DIR = os.path.join(PACKAGE_DIR, "CodeGeneration") -SYNTAXSUPPORT_DIR = \ - os.path.join(CODE_GENERATION_DIR, "Sources", "SyntaxSupport") - -LLVM_DIR = os.path.join(WORKSPACE_DIR, "llvm-project", "llvm") -SWIFT_DIR = os.path.join(WORKSPACE_DIR, "swift") - -LIT_EXEC = os.path.join(LLVM_DIR, "utils", "lit", "lit.py") - -GROUP_INFO_PATH = os.path.join(PACKAGE_DIR, "utils", "group.json") - - -def fail_for_called_process_error( - succinct_description: str, - error: subprocess.CalledProcessError -) -> None: - printerr(f"FAIL: {succinct_description}") - printerr(f"Executing: {escapeCmd(error.cmd)}") - printerr(error.output) - raise SystemExit(1) - - -# ----------------------------------------------------------------------------- -# Xcode Projects Generation - - -def xcode_gen(config: str) -> None: - print("** Generate SwiftSyntax as an Xcode project **") - os.chdir(PACKAGE_DIR) - swiftpm_call = ["swift", "package", "generate-xcodeproj"] - if config: - swiftpm_call.extend(["--xcconfig-overrides", config]) - check_call(swiftpm_call) - - -# ----------------------------------------------------------------------------- -# Helpers - - -def printerr(message: str) -> None: - print(message, file=sys.stderr) - - -def note(message: str) -> None: - print("--- %s: note: %s" % (os.path.basename(sys.argv[0]), message)) - sys.stdout.flush() - - -def fatal_error(message: str) -> None: - printerr(message) - raise SystemExit(1) - - -def escapeCmdArg(arg: str) -> str: - if '"' in arg or " " in arg: - return '"%s"' % arg.replace('"', '\\"') - else: - return arg - - -def escapeCmd(cmd: List[str]) -> str: - return " ".join([escapeCmdArg(arg) for arg in cmd]) - - -def call(cmd: List[str], env: Dict[str, str] = dict(os.environ), - stdout: Optional[int] = None, stderr: Optional[int] = subprocess.STDOUT, - verbose: bool = False) -> int: - if verbose: - print(escapeCmd(cmd)) - process = subprocess.Popen(cmd, env=env, stdout=stdout, stderr=stderr) - process.wait() - - return process.returncode - - -def check_call(cmd: List[str], cwd: Optional[str] = None, - env: Dict[str, str] = dict(os.environ), verbose: bool = False) -> None: - if verbose: - print(escapeCmd(cmd)) - subprocess.check_call(cmd, cwd=cwd, env=env, stderr=subprocess.STDOUT) - - -def realpath(path: Optional[str]) -> Optional[str]: - if path is None: - return None - return os.path.realpath(path) - - -# ----------------------------------------------------------------------------- -# Generating Files - - -def run_code_generation( - source_dir: str, - toolchain: str, - verbose: bool -) -> None: - print("** Running code generation **") - - swift_exec = os.path.join(toolchain, "bin", "swift") - - swiftpm_call = [ - swift_exec, 'run', - "--package-path", CODE_GENERATION_DIR, - "generate-swift-syntax", source_dir - ] - - if verbose: - swiftpm_call.extend(["--verbose"]) - - env = dict(os.environ) - env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" - env["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" - env["SWIFTCI_USE_LOCAL_DEPS"] = "1" - check_call(swiftpm_call, env=env, verbose=verbose) - - -# ----------------------------------------------------------------------------- -# Building SwiftSyntax - - -def get_swiftpm_invocation( - toolchain: str, action: str, package_dir: str, build_dir: Optional[str], - multiroot_data_file: Optional[str], release: bool -) -> List[str]: - swift_exec = os.path.join(toolchain, "bin", "swift") - - swiftpm_call = [swift_exec, action] - swiftpm_call.extend(["--package-path", package_dir]) - if platform.system() != "Darwin": - swiftpm_call.extend(["--enable-test-discovery"]) - if release: - swiftpm_call.extend(["--configuration", "release"]) - if build_dir: - swiftpm_call.extend(["--scratch-path", build_dir]) - if multiroot_data_file: - swiftpm_call.extend(["--multiroot-data-file", multiroot_data_file]) - - return swiftpm_call - - -class Builder(object): - verbose: bool - toolchain: str - build_dir: Optional[str] - multiroot_data_file: Optional[str] - release: bool - enable_rawsyntax_validation: bool - enable_test_fuzzing: bool - disable_sandbox: bool - - def __init__( - self, - toolchain: str, - build_dir: Optional[str], - multiroot_data_file: Optional[str], - release: bool, - enable_rawsyntax_validation: bool, - enable_test_fuzzing: bool, - verbose: bool, - disable_sandbox: bool = False, - ) -> None: - self.build_dir = build_dir - self.multiroot_data_file = multiroot_data_file - self.release = release - self.enable_rawsyntax_validation = enable_rawsyntax_validation - self.enable_test_fuzzing = enable_test_fuzzing - self.disable_sandbox = disable_sandbox - self.verbose = verbose - self.toolchain = toolchain - - def __get_swiftpm_invocation(self, package_dir: str) -> List[str]: - invocation = get_swiftpm_invocation( - self.toolchain, - "build", - package_dir, - self.build_dir, - self.multiroot_data_file, - self.release - ) - if self.disable_sandbox: - invocation.append("--disable-sandbox") - if self.verbose: - invocation.append("--verbose") - return invocation - - def buildProduct(self, product_name: str) -> None: - print("** Building product " + product_name + " **") - self.__build(PACKAGE_DIR, product_name, is_product=True) - - def buildTarget(self, package_dir: str, target_name: str) -> None: - print("** Building target " + target_name + " **") - self.__build(package_dir, target_name, is_product=False) - - def buildExample(self, example_name: str) -> None: - print("** Building example " + example_name + " **") - self.__build(EXAMPLES_DIR, example_name, is_product=True) - - def __build(self, package_dir: str, name: str, is_product: bool) -> None: - command = list(self.__get_swiftpm_invocation(package_dir)) - command.extend(["--product" if is_product else "--target", name]) - - env = dict(os.environ) - env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" - if self.enable_rawsyntax_validation: - env["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" - if self.enable_test_fuzzing: - env["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1" - # Tell other projects in the unified build to use local dependencies - env["SWIFTCI_USE_LOCAL_DEPS"] = "1" - env["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = \ - os.path.join(self.toolchain, "lib", "swift", "macosx") - - check_call(command, env=env, verbose=self.verbose) - - -# ----------------------------------------------------------------------------- -# Testing - - -def verify_code_generated_files( - toolchain: str, verbose: bool -) -> None: - self_temp_dir = tempfile.mkdtemp() - - try: - run_code_generation( - source_dir=self_temp_dir, - toolchain=toolchain, - verbose=verbose - ) - except subprocess.CalledProcessError as e: - fail_for_called_process_error( - "Source generation using SwiftSyntaxBuilder failed", - e - ) - - print("** Verifing code generated files **") - - for module in ["SwiftParser", "SwiftParserDiagnostics", \ - "SwiftSyntax", "SwiftSyntaxBuilder"]: - self_generated_dir = os.path.join(self_temp_dir, module, "generated") - user_generated_dir = os.path.join(SOURCES_DIR, module, "generated") - check_generated_files_match(self_generated_dir, user_generated_dir) - - -def check_generated_files_match(self_generated_dir: str, - user_generated_dir: str) -> None: - command = [ - "diff", - "--recursive", - "--exclude", - ".*", # Exclude dot files like .DS_Store - "--context=0", - self_generated_dir, - user_generated_dir, - ] - check_call(command) - - -def run_code_generation_tests( - toolchain: str, - verbose: bool -) -> None: - print("** Running CodeGeneration tests **") - - swift_exec = os.path.join(toolchain, "bin", "swift") - - swiftpm_call = [ - swift_exec, 'test', - "--package-path", CODE_GENERATION_DIR - ] - - if verbose: - swiftpm_call.extend(["--verbose"]) - - env = dict(os.environ) - env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" - env["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" - env["SWIFTCI_USE_LOCAL_DEPS"] = "1" - check_call(swiftpm_call, env=env, verbose=verbose) - - -def run_tests( - toolchain: str, - build_dir: Optional[str], - multiroot_data_file: Optional[str], - release: bool, - enable_rawsyntax_validation: bool, - enable_test_fuzzing: bool, - filecheck_exec: Optional[str], - skip_lit_tests: bool, - verbose: bool -) -> None: - print("** Running SwiftSyntax Tests **") - - if not skip_lit_tests: - run_lit_tests( - toolchain=toolchain, - build_dir=build_dir, - release=release, - filecheck_exec=filecheck_exec, - verbose=verbose, - ) - - run_xctests( - package_dir=PACKAGE_DIR, - test_product="swift-syntaxPackageTests", - toolchain=toolchain, - build_dir=build_dir, - multiroot_data_file=multiroot_data_file, - release=release, - enable_rawsyntax_validation=enable_rawsyntax_validation, - enable_test_fuzzing=enable_test_fuzzing, - verbose=verbose, - ) - - run_code_generation_tests( - toolchain=toolchain, - verbose=verbose, - ) - -# ----------------------------------------------------------------------------- -# Lit Tests - - -def check_lit_exec() -> None: - if not os.path.exists(LIT_EXEC): - fatal_error( - """ -Error: Could not find lit.py. -Looking at '%s'. - -Make sure you have the llvm repo checked out next to the swift-syntax repo. -Refer to README.md for more information. -""" - % LIT_EXEC - ) - - -def find_swiftpm_bin_path( - package_dir: str, toolchain: str, build_dir: Optional[str], release: bool -) -> str: - swiftpm_call = get_swiftpm_invocation( - toolchain=toolchain, - action="build", - package_dir=package_dir, - build_dir=build_dir, - multiroot_data_file=None, - release=release, - ) - swiftpm_call.extend(["--show-bin-path"]) - - bin_dir = subprocess.check_output(swiftpm_call) - return bin_dir.strip().decode('utf-8') - - -def find_product_bin_path( - toolchain: str, build_dir: Optional[str], release: bool -) -> str: - return find_swiftpm_bin_path(PACKAGE_DIR, toolchain, build_dir, release) - - -def find_examples_bin_path( - toolchain: str, build_dir: Optional[str], release: bool -) -> str: - return find_swiftpm_bin_path(EXAMPLES_DIR, toolchain, build_dir, release) - - -def run_lit_tests(toolchain: str, build_dir: Optional[str], release: bool, - filecheck_exec: Optional[str], verbose: bool) -> None: - print("** Running lit-based tests **") - - check_lit_exec() - - product_bin_path = find_product_bin_path( - toolchain=toolchain, build_dir=build_dir, release=release) - examples_bin_path = find_examples_bin_path( - toolchain=toolchain, build_dir=build_dir, release=release) - - lit_test_helper_exec = os.path.join(product_bin_path, "lit-test-helper") - - lit_call = ["python3", LIT_EXEC] - lit_call.append(os.path.join(PACKAGE_DIR, "lit_tests")) - - if filecheck_exec: - lit_call.extend(["--param", "FILECHECK=" + filecheck_exec]) - if lit_test_helper_exec: - lit_call.extend(["--param", "LIT_TEST_HELPER=" + lit_test_helper_exec]) - lit_call.extend(["--param", "EXAMPLES_BIN_PATH=" + examples_bin_path]) - lit_call.extend(["--param", "TOOLCHAIN=" + toolchain]) - - # Print all failures - lit_call.extend(["--verbose"]) - # Don't show all commands if verbose is not enabled - if not verbose: - lit_call.extend(["--succinct"]) - check_call(lit_call, verbose=verbose) - - -# ----------------------------------------------------------------------------- -# XCTest Tests - - -def run_xctests( - package_dir: str, - test_product: str, - toolchain: str, - build_dir: Optional[str], - multiroot_data_file: Optional[str], - release: bool, - enable_rawsyntax_validation: bool, - enable_test_fuzzing: bool, - verbose: bool -) -> None: - print("** Running XCTests **") - swiftpm_call = get_swiftpm_invocation( - toolchain=toolchain, - action="test", - package_dir=package_dir, - build_dir=build_dir, - multiroot_data_file=multiroot_data_file, - release=release, - ) - - if verbose: - swiftpm_call.extend(["--verbose"]) - - swiftpm_call.extend(["--test-product", test_product]) - - env = dict(os.environ) - env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" - if enable_rawsyntax_validation: - env["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION"] = "1" - if enable_test_fuzzing: - env["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1" - # Tell other projects in the unified build to use local dependencies - env["SWIFTCI_USE_LOCAL_DEPS"] = "1" - env["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = \ - os.path.join(toolchain, "lib", "swift", "macosx") - - check_call(swiftpm_call, env=env, verbose=verbose) - -# ----------------------------------------------------------------------------- -# Arugment Parsing functions - - -def generate_xcodeproj(args: argparse.Namespace) -> None: - xcode_gen(config=args.xcconfig_path) - - -def generate_source_code_command(args: argparse.Namespace) -> None: - try: - run_code_generation( - source_dir=SOURCES_DIR, - toolchain=args.toolchain, - verbose=args.verbose - ) - except subprocess.CalledProcessError as e: - fail_for_called_process_error( - "Source generation using SwiftSyntaxBuilder failed", e) - - -def verify_source_code_command(args: argparse.Namespace) -> None: - try: - verify_code_generated_files( - toolchain=args.toolchain, - verbose=args.verbose, - ) - except subprocess.CalledProcessError: - printerr( - "FAIL: code-generated files committed to repository do " + - "not match generated ones. Please re-generate the " + - "code-generated-files using the following command, open a PR to the " + - "SwiftSyntax project and merge it alongside the main PR." + - "$ swift-syntax/build-script.py generate-source-code " + - "--toolchain /path/to/toolchain.xctoolchain/usr" - ) - raise SystemExit(1) - - -def build_command(args: argparse.Namespace) -> None: - try: - builder = Builder( - toolchain=realpath(args.toolchain), # pyright: ignore - build_dir=realpath(args.build_dir), - multiroot_data_file=args.multiroot_data_file, - release=args.release, - enable_rawsyntax_validation=args.enable_rawsyntax_validation, - enable_test_fuzzing=args.enable_test_fuzzing, - verbose=args.verbose, - disable_sandbox=args.disable_sandbox, - ) - builder.buildTarget(PACKAGE_DIR, "SwiftSyntax-all") - builder.buildTarget(EXAMPLES_DIR, "Examples-all") - except subprocess.CalledProcessError as e: - fail_for_called_process_error("Building SwiftSyntax failed", e) - - -def test_command(args: argparse.Namespace) -> None: - try: - builder = Builder( - toolchain=realpath(args.toolchain), # pyright: ignore - build_dir=realpath(args.build_dir), - multiroot_data_file=args.multiroot_data_file, - release=args.release, - enable_rawsyntax_validation=args.enable_rawsyntax_validation, - enable_test_fuzzing=args.enable_test_fuzzing, - verbose=args.verbose, - disable_sandbox=args.disable_sandbox, - ) - - builder.buildProduct("lit-test-helper") - builder.buildExample("ExamplePlugin") - - run_tests( - toolchain=realpath(args.toolchain), # pyright: ignore - build_dir=realpath(args.build_dir), - multiroot_data_file=args.multiroot_data_file, - release=args.release, - enable_rawsyntax_validation=args.enable_rawsyntax_validation, - enable_test_fuzzing=args.enable_test_fuzzing, - filecheck_exec=realpath(args.filecheck_exec), - skip_lit_tests=args.skip_lit_tests, - verbose=args.verbose, - ) - print("** All tests passed **") - except subprocess.CalledProcessError as e: - fail_for_called_process_error("Running tests failed", e) - - -# ----------------------------------------------------------------------------- -# Argument Parsing - -_DESCRIPTION = """ -Build and test script for SwiftSyntax. - -The build script can also drive the test suite included in the SwiftSyntax -repo. This requires a custom build of the compiler project since it accesses -test utilities that are not shipped as part of the toolchains. See the Testing -section for arguments that need to be specified for this. -""" - - -def parse_args() -> argparse.Namespace: - def add_default_build_arguments(parser: argparse.ArgumentParser) -> None: - parser.add_argument( - "-r", "--release", action="store_true", help="Build in release mode." - ) - - parser.add_argument( - "--build-dir", - default=None, - help=""" - The directory in which build products shall be put. If omitted - a directory named ".build" will be put in the swift-syntax - directory. - """, - ) - - parser.add_argument( - "--disable-sandbox", - action="store_true", - help="Disable sandboxes when building with SwiftPM", - ) - - parser.add_argument( - "--multiroot-data-file", - help=""" - Path to an Xcode workspace to create a unified build of SwiftSyntax with - other projects. - """, - ) - - parser.add_argument( - "--enable-rawsyntax-validation", - action="store_true", - help=""" - When constructing RawSyntax nodes validate that their layout matches that - defined in `CodeGeneration` and that TokenSyntax nodes have a `tokenKind` - matching the ones specified in `CodeGeneration`. - """ - ) - - parser.add_argument( - "--enable-test-fuzzing", - action="store_true", - help=""" - For each `assertParse` test, perform mutations of the test case based on - alternate token choices that the parser checks, validating that there are - no round-trip or assertion failures. - """ - ) - - parser.add_argument( - "--toolchain", - required=True, - help="The path to the toolchain that shall be used to build SwiftSyntax.", - ) - - parser.add_argument( - "-v", "--verbose", action="store_true", help="Enable verbose logging." - ) - - def add_generate_source_code_args(parser: argparse.ArgumentParser) -> None: - parser.add_argument( - "--toolchain", - required=True, - help="The path to the toolchain that shall be used to build SwiftSyntax.", - ) - - parser.add_argument( - "-v", "--verbose", action="store_true", help="Enable verbose logging." - ) - - parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, description=_DESCRIPTION - ) - - # ------------------------------------------------------------------------- - # Shared arguments - - sub_parsers = parser.add_subparsers() - - # ------------------------------------------------------------------------- - generate_xcodeproj_parser = sub_parsers.add_parser( - "generate-xcodeproj", - help="Generate an Xcode project for SwiftSyntax." - ) - generate_xcodeproj_parser.set_defaults(func=generate_xcodeproj) - - generate_xcodeproj_parser.add_argument( - "--xcconfig-path", - help="The path to an xcconfig file for generating Xcode projct.", - ) - - generate_xcodeproj_parser.add_argument( - "-v", "--verbose", action="store_true", help="Enable verbose logging." - ) - - # ------------------------------------------------------------------------- - generate_source_code_parser = sub_parsers.add_parser("generate-source-code") - generate_source_code_parser.set_defaults(func=generate_source_code_command) - - add_generate_source_code_args(generate_source_code_parser) - - generate_source_code_parser.add_argument( - "--add-source-locations", - action="store_true", - help=""" - Insert ###sourceLocation comments in generated code for line-directive. - """, - ) - - # ------------------------------------------------------------------------- - build_parser = sub_parsers.add_parser("build") - build_parser.set_defaults(func=build_command) - - add_default_build_arguments(build_parser) - - # ------------------------------------------------------------------------- - test_parser = sub_parsers.add_parser("test") - test_parser.set_defaults(func=test_command) - - add_default_build_arguments(test_parser) - - test_parser.add_argument( - "--skip-lit-tests", action="store_true", - help="Don't run lit-based tests" - ) - - test_parser.add_argument( - "--filecheck-exec", - default=None, - help=""" - Path to the FileCheck executable that was built as part of the LLVM repository. - If not specified, it will be looked up from PATH. - """, - ) - - # ------------------------------------------------------------------------- - verify_source_code_parser = sub_parsers.add_parser("verify-source-code") - verify_source_code_parser.set_defaults(func=verify_source_code_command) - - add_generate_source_code_args(verify_source_code_parser) - - return parser.parse_args() - - -# ----------------------------------------------------------------------------- - - -def main() -> None: - args = parse_args() - args.func(args) - - -if __name__ == "__main__": - main()