Skip to content

Commit 863f261

Browse files
committed
Add one script to run them all
Add the script to the swift-syntax dev utils package to allow developers run all necessary actions before submitting a PR
1 parent 2186cc6 commit 863f261

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/SwiftSyntaxDevUtils.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct SwiftSyntaxDevUtils: ParsableCommand {
2828
Build.self,
2929
Format.self,
3030
GenerateSourceCode.self,
31+
LocalPrPrecheck.self,
3132
Test.self,
3233
VerifyDocumentation.self,
3334
VerifySourceCode.self,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}

SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/SwiftPMBuilder.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct SwiftPMBuilder {
3838
/// no round-trip or assertion failures.
3939
let enableTestFuzzing: Bool
4040

41+
/// A flag indicating whether to use local dependencies during the build process.
42+
let useLocalDeps: Bool
43+
4144
/// Treat all warnings as errors.
4245
let warningsAsErrors: Bool
4346

@@ -51,6 +54,7 @@ struct SwiftPMBuilder {
5154
release: Bool = false,
5255
enableRawSyntaxValidation: Bool = false,
5356
enableTestFuzzing: Bool = false,
57+
useLocalDeps: Bool = true,
5458
warningsAsErrors: Bool = false,
5559
verbose: Bool = false
5660
) {
@@ -60,6 +64,7 @@ struct SwiftPMBuilder {
6064
self.release = release
6165
self.enableRawSyntaxValidation = enableRawSyntaxValidation
6266
self.enableTestFuzzing = enableTestFuzzing
67+
self.useLocalDeps = useLocalDeps
6368
self.warningsAsErrors = warningsAsErrors
6469
self.verbose = verbose
6570
}
@@ -139,8 +144,10 @@ struct SwiftPMBuilder {
139144
additionalEnvironment["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1"
140145
}
141146

142-
// Tell other projects in the unified build to use local dependencies
143-
additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1"
147+
if useLocalDeps {
148+
// Tell other projects in the unified build to use local dependencies
149+
additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1"
150+
}
144151

145152
return additionalEnvironment
146153
}

0 commit comments

Comments
 (0)