Skip to content

Commit b1941ab

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 098b177 commit b1941ab

File tree

8 files changed

+88
-8
lines changed

8 files changed

+88
-8
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+
IntegrityCheck.self,
3132
Test.self,
3233
VerifySourceCode.self,
3334
]

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,13 @@ struct Format: ParsableCommand {
114114
/// Ensure that we have an up-to-date checkout of swift-format in `.swift-format-build`.
115115
private func cloneOrUpdateSwiftFormat() throws {
116116
if FileManager.default.fileExists(atPath: Paths.swiftFormatBuildDir.appendingPathComponent(".git").path) {
117+
logSection("Updating swift-format")
118+
117119
try runGitCommand("checkout", Self.swiftFormatBranch)
118120
try runGitCommand("pull")
119121
} else {
122+
logSection("Cloning swift-format")
123+
120124
try FileManager.default.createDirectory(atPath: Paths.swiftFormatBuildDir.path, withIntermediateDirectories: true)
121125
try runGitCommand("clone", "https://github.com/apple/swift-format.git", ".")
122126
try runGitCommand("checkout", Self.swiftFormatBranch)
@@ -170,6 +174,8 @@ struct Format: ParsableCommand {
170174

171175
/// Format all files in the repo using the locally-built swift-format.
172176
private func formatFilesInRepo() throws {
177+
logSection("Formatting code with swift-format")
178+
173179
let swiftFormatExecutable = try findSwiftFormatExecutable()
174180

175181
let filesToFormat = self.filesToFormat()
@@ -191,6 +197,8 @@ struct Format: ParsableCommand {
191197

192198
/// Lint all files in the repo using the locally-built swift-format.
193199
private func lintFilesInRepo() throws {
200+
logSection("Running swift-format linter")
201+
194202
let swiftFormatExecutable = try findSwiftFormatExecutable()
195203

196204
let filesToFormat = self.filesToFormat()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 IntegrityCheck: ParsableCommand {
17+
static var configuration: CommandConfiguration {
18+
return CommandConfiguration(
19+
abstract: """
20+
Ensure changes are fully tested, formatted, and validated before pull request submission.
21+
"""
22+
)
23+
}
24+
25+
@Flag(help: "Enable verbose logging.")
26+
var verbose: Bool = false
27+
28+
func run() throws {
29+
try runCommand("format")
30+
31+
try runCommand("generate-source-code")
32+
33+
try runCommand("test", "--use-remote-deps")
34+
35+
try runCommand("build", "--use-remote-deps")
36+
}
37+
38+
private func runCommand(_ command: String...) throws {
39+
try ProcessRunner(
40+
executableURL: Paths.swiftExec,
41+
arguments: [
42+
"run",
43+
"--package-path",
44+
Paths.devUtilsDir.path,
45+
"--package-path",
46+
"SwiftSyntaxDevUtils",
47+
"swift-syntax-dev-utils",
48+
] + command
49+
)
50+
.run(
51+
captureStdout: false,
52+
captureStderr: false,
53+
verbose: verbose
54+
)
55+
}
56+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct BuildArguments: ParsableArguments {
1818
help: "The path to the toolchain that shall be used to build SwiftSyntax.",
1919
transform: URL.init(fileURLWithPath:)
2020
)
21-
var toolchain: URL
21+
var toolchain: URL?
2222

2323
@Option(
2424
help: """
@@ -62,6 +62,14 @@ struct BuildArguments: ParsableArguments {
6262
)
6363
var enableTestFuzzing: Bool = false
6464

65+
@Flag(
66+
help: """
67+
Switch to using remote dependencies instead of local ones in the unified build process. \
68+
When not set, local dependencies are utilized by default.
69+
"""
70+
)
71+
var useRemoteDeps: Bool = false
72+
6573
@Flag(help: "Treat all warnings as errors.")
6674
var warningsAsErrors: Bool = false
6775

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ extension BuildCommand {
6868

6969
args += additionalArguments
7070

71-
let processRunner = ProcessRunner(
72-
executableURL: arguments.toolchain.appendingPathComponent("bin").appendingPathComponent("swift"),
71+
let processRunner = try ProcessRunner(
72+
executableURL: arguments.toolchain?.appendingPathComponent("bin").appendingPathComponent("swift") ?? Paths.swiftExec,
7373
arguments: args,
7474
additionalEnvironment: additionalEnvironment
7575
)
@@ -116,8 +116,10 @@ extension BuildCommand {
116116
additionalEnvironment["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1"
117117
}
118118

119-
// Tell other projects in the unified build to use local dependencies
120-
additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1"
119+
if !arguments.useRemoteDeps {
120+
// Tell other projects in the unified build to use local dependencies
121+
additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1"
122+
}
121123

122124
return additionalEnvironment
123125
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ enum Paths {
4242
.appendingPathComponent("CodeGeneration")
4343
}
4444

45+
static var devUtilsDir: URL {
46+
packageDir
47+
.appendingPathComponent("swift-syntax-dev-utils")
48+
}
49+
4550
static var editorExtensionProjectPath: URL {
4651
packageDir
4752
.appendingPathComponent("EditorExtension")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct SourceCodeGeneratorArguments: ParsableArguments {
1818
help: "The path to the toolchain that shall be used to build SwiftSyntax.",
1919
transform: URL.init(fileURLWithPath:)
2020
)
21-
var toolchain: URL
21+
var toolchain: URL?
2222

2323
@Flag(help: "Enable verbose logging.")
2424
var verbose: Bool = false

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ extension SourceCodeGeneratorCommand {
3838
"SWIFTCI_USE_LOCAL_DEPS": nil,
3939
]
4040

41-
let process = ProcessRunner(
42-
executableURL: arguments.toolchain.appendingPathComponent("bin").appendingPathComponent("swift"),
41+
let process = try ProcessRunner(
42+
executableURL: arguments.toolchain?.appendingPathComponent("bin").appendingPathComponent("swift") ?? Paths.swiftExec,
4343
arguments: args,
4444
additionalEnvironment: additionalEnvironment
4545
)

0 commit comments

Comments
 (0)