|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import ArgumentParser |
| 14 | +import Foundation |
| 15 | + |
| 16 | +struct LocalPrPrecheck: ParsableCommand { |
| 17 | + static let configuration = CommandConfiguration( |
| 18 | + abstract: """ |
| 19 | + Ensure changes are fully tested, formatted, and validated before pull request submission. |
| 20 | + """ |
| 21 | + ) |
| 22 | + |
| 23 | + @OptionGroup |
| 24 | + var arguments: SourceCodeGeneratorArguments |
| 25 | + |
| 26 | + func run() throws { |
| 27 | + let executor = LocalPrPrecheckExecutor( |
| 28 | + toolchain: try arguments.toolchain, |
| 29 | + verbose: arguments.verbose |
| 30 | + ) |
| 31 | + try executor.run() |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +struct LocalPrPrecheckExecutor { |
| 36 | + private let formatExecutor: FormatExecutor |
| 37 | + private let generateSourceCodeExecutor: GenerateSourceCodeExecutor |
| 38 | + private let buildExecutor: BuildExecutor |
| 39 | + private let testExecutor: TestExecutor |
| 40 | + |
| 41 | + /// Creates an executor |
| 42 | + /// - Parameters: |
| 43 | + /// - toolchain: The path to the toolchain that shall be used to build SwiftSyntax. |
| 44 | + /// - verbose: Enable verbose logging. |
| 45 | + init(toolchain: URL, verbose: Bool = false) { |
| 46 | + self.formatExecutor = FormatExecutor(update: false, verbose: verbose) |
| 47 | + self.generateSourceCodeExecutor = GenerateSourceCodeExecutor(toolchain: toolchain, verbose: verbose) |
| 48 | + self.buildExecutor = BuildExecutor(swiftPMBuilder: SwiftPMBuilder(toolchain: toolchain, useLocalDeps: false, verbose: verbose)) |
| 49 | + self.testExecutor = TestExecutor(swiftPMBuilder: SwiftPMBuilder(toolchain: toolchain, useLocalDeps: false, verbose: verbose)) |
| 50 | + } |
| 51 | + |
| 52 | + func run() throws { |
| 53 | + try formatExecutor.run() |
| 54 | + try generateSourceCodeExecutor.run(sourceDir: Paths.sourcesDir) |
| 55 | + try buildExecutor.run() |
| 56 | + try testExecutor.run() |
| 57 | + } |
| 58 | +} |
0 commit comments