Skip to content

Commit 9e6c764

Browse files
authored
Fixup several warnings (#9009)
- Remove unnecessary `try` statements for function calls that do not throw - Remove unnecessary `#expect` checks for values that cannot be `nil`
1 parent 0cef64a commit 9e6c764

File tree

14 files changed

+61
-66
lines changed

14 files changed

+61
-66
lines changed

Sources/Commands/Utilities/PluginDelegate.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ final class PluginDelegate: PluginInvocationDelegate {
423423
func lookupDescription(
424424
for moduleName: String,
425425
destination: BuildParameters.Destination
426-
) throws -> ModuleBuildDescription? {
427-
try buildPlan.buildModules.first {
426+
) -> ModuleBuildDescription? {
427+
buildPlan.buildModules.first {
428428
$0.module.name == moduleName && $0.buildParameters.destination == destination
429429
}
430430
}
@@ -434,9 +434,9 @@ final class PluginDelegate: PluginInvocationDelegate {
434434
// historically how this was setup. Ideally we should be building for both "host"
435435
// and "target" if module is configured for them but that would require changing
436436
// `PluginInvocationSymbolGraphResult` to carry multiple directories.
437-
let description = if let targetDescription = try lookupDescription(for: targetName, destination: .target) {
437+
let description = if let targetDescription = lookupDescription(for: targetName, destination: .target) {
438438
targetDescription
439-
} else if let hostDescription = try lookupDescription(for: targetName, destination: .host) {
439+
} else if let hostDescription = lookupDescription(for: targetName, destination: .host) {
440440
hostDescription
441441
} else {
442442
throw InternalError("could not find a target named: \(targetName)")

Sources/Workspace/Workspace+Delegation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ extension WorkspaceDelegate {
216216
}
217217
}
218218

219-
struct WorkspaceManifestLoaderDelegate: ManifestLoader.Delegate {
219+
struct WorkspaceManifestLoaderDelegate: ManifestLoader.Delegate, @unchecked Sendable {
220220
private weak var workspaceDelegate: Workspace.Delegate?
221221

222222
init(workspaceDelegate: Workspace.Delegate) {
@@ -279,7 +279,7 @@ struct WorkspaceManifestLoaderDelegate: ManifestLoader.Delegate {
279279
}
280280
}
281281

282-
struct WorkspaceRepositoryManagerDelegate: RepositoryManager.Delegate {
282+
struct WorkspaceRepositoryManagerDelegate: RepositoryManager.Delegate, @unchecked Sendable {
283283
private weak var workspaceDelegate: Workspace.Delegate?
284284

285285
init(workspaceDelegate: Workspace.Delegate) {
@@ -335,7 +335,7 @@ struct WorkspaceRepositoryManagerDelegate: RepositoryManager.Delegate {
335335
}
336336
}
337337

338-
struct WorkspaceRegistryDownloadsManagerDelegate: RegistryDownloadsManager.Delegate {
338+
struct WorkspaceRegistryDownloadsManagerDelegate: RegistryDownloadsManager.Delegate, @unchecked Sendable {
339339
private weak var workspaceDelegate: Workspace.Delegate?
340340

341341
init(workspaceDelegate: Workspace.Delegate) {

Sources/_InternalTestSupport/GitRepositoryExtensions.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import SourceControl
1414

1515
import class Basics.AsyncProcess
16+
import class TSCBasic.Process
1617

1718
import enum TSCUtility.Git
1819

@@ -21,7 +22,7 @@ import enum TSCUtility.Git
2122
package extension GitRepository {
2223
/// Create the repository using git init.
2324
func create() throws {
24-
try systemQuietly([Git.tool, "-C", self.path.pathString, "init"])
25+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "init")
2526
}
2627

2728
/// Returns current branch name. If HEAD is on a detached state, this returns HEAD.
@@ -38,36 +39,36 @@ package extension GitRepository {
3839

3940
/// Stage a file.
4041
func stage(file: String) throws {
41-
try systemQuietly([Git.tool, "-C", self.path.pathString, "add", file])
42+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "add", file)
4243
}
4344

4445
/// Stage multiple files.
4546
func stage(files: String...) throws {
46-
try systemQuietly([Git.tool, "-C", self.path.pathString, "add"] + files)
47+
try Process.checkNonZeroExit(arguments: [Git.tool, "-C", self.path.pathString, "add"] + files)
4748
}
4849

4950
/// Stage entire unstaged changes.
5051
func stageEverything() throws {
51-
try systemQuietly([Git.tool, "-C", self.path.pathString, "add", "."])
52+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "add", ".")
5253
}
5354

5455
/// Commit the staged changes. If the message is not provided a dummy message will be used for the commit.
5556
func commit(message: String? = nil) throws {
5657
// FIXME: We don't need to set these every time but we usually only commit once or twice for a test repo.
57-
try systemQuietly([Git.tool, "-C", self.path.pathString, "config", "user.email", "[email protected]"])
58-
try systemQuietly([Git.tool, "-C", self.path.pathString, "config", "user.name", "Example Example"])
59-
try systemQuietly([Git.tool, "-C", self.path.pathString, "config", "commit.gpgsign", "false"])
60-
try systemQuietly([Git.tool, "-C", self.path.pathString, "config", "tag.gpgsign", "false"])
61-
try systemQuietly([Git.tool, "-C", self.path.pathString, "commit", "-m", message ?? "Add some files."])
58+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "config", "user.email", "[email protected]")
59+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "config", "user.name", "Example Example")
60+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "config", "commit.gpgsign", "false")
61+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "config", "tag.gpgsign", "false")
62+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "commit", "-m", message ?? "Add some files.")
6263
}
6364

6465
/// Tag the git repo.
6566
func tag(name: String) throws {
66-
try systemQuietly([Git.tool, "-C", self.path.pathString, "tag", name])
67+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "tag", name)
6768
}
6869

6970
/// Push the changes to specified remote and branch.
7071
func push(remote: String, branch: String) throws {
71-
try systemQuietly([Git.tool, "-C", self.path.pathString, "push", remote, branch])
72+
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "push", remote, branch)
7273
}
7374
}

Sources/_InternalTestSupport/InMemoryGitRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ extension InMemoryGitRepository: WorkingCheckout {
396396
extension InMemoryGitRepository: @unchecked Sendable {}
397397

398398
/// This class implement provider for in memory git repository.
399-
public final class InMemoryGitRepositoryProvider: RepositoryProvider {
399+
public final class InMemoryGitRepositoryProvider: RepositoryProvider, @unchecked Sendable {
400400
/// Contains the repository added to this provider.
401401
public var specifierMap = ThreadSafeKeyValueStore<RepositorySpecifier, InMemoryGitRepository>()
402402

Sources/_InternalTestSupport/misc.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ import Testing
3232
import func XCTest.XCTFail
3333
import struct XCTest.XCTSkip
3434

35+
import class TSCBasic.Process
3536
import struct TSCBasic.ByteString
3637
import struct Basics.AsyncProcessResult
3738

3839
import enum TSCUtility.Git
3940

40-
@_exported import func TSCTestSupport.systemQuietly
4141
@_exported import enum TSCTestSupport.StringPattern
4242

4343
@available(*, deprecated, message: "Use CiEnvironment.runningInSmokeTestPipeline")
@@ -305,7 +305,7 @@ fileprivate func setup(
305305
#if os(Windows)
306306
try localFileSystem.copy(from: srcDir, to: dstDir)
307307
#else
308-
try systemQuietly("cp", "-R", "-H", srcDir.pathString, dstDir.pathString)
308+
try Process.checkNonZeroExit(args: "cp", "-R", "-H", srcDir.pathString, dstDir.pathString)
309309
#endif
310310

311311
// Ensure we get a clean test fixture.
@@ -361,17 +361,17 @@ public func initGitRepo(
361361
try localFileSystem.writeFileContents(file, bytes: "")
362362
}
363363

364-
try systemQuietly([Git.tool, "-C", dir.pathString, "init"])
365-
try systemQuietly([Git.tool, "-C", dir.pathString, "config", "user.email", "[email protected]"])
366-
try systemQuietly([Git.tool, "-C", dir.pathString, "config", "user.name", "Example Example"])
367-
try systemQuietly([Git.tool, "-C", dir.pathString, "config", "commit.gpgsign", "false"])
364+
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "init")
365+
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "config", "user.email", "[email protected]")
366+
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "config", "user.name", "Example Example")
367+
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "config", "commit.gpgsign", "false")
368368
let repo = GitRepository(path: dir)
369369
try repo.stageEverything()
370370
try repo.commit(message: "msg")
371371
for tag in tags {
372372
try repo.tag(name: tag)
373373
}
374-
try systemQuietly([Git.tool, "-C", dir.pathString, "branch", "-m", "main"])
374+
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "branch", "-m", "main")
375375
} catch {
376376
XCTFail("\(error.interpolationDescription)", file: file, line: line)
377377
}

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ final class MiscellaneousTestCase: XCTestCase {
277277
// Create a shared library.
278278
let input = systemModule.appending(components: "Sources", "SystemModule.c")
279279
let triple = try UserToolchain.default.targetTriple
280-
let output = systemModule.appending("libSystemModule\(triple.dynamicLibraryExtension)")
281-
try systemQuietly([executableName("clang"), "-shared", input.pathString, "-o", output.pathString])
280+
let output = systemModule.appending("libSystemModule\(triple.dynamicLibraryExtension)")
281+
try await AsyncProcess.checkNonZeroExit(args: executableName("clang"), "-shared", input.pathString, "-o", output.pathString)
282282

283283
let pcFile = fixturePath.appending("libSystemModule.pc")
284284

Tests/FunctionalTests/ModuleMapTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class ModuleMapsTestCase: XCTestCase {
3030
let outdir = fixturePath.appending(components: rootpkg, ".build", triple.platformBuildPathComponent, "debug")
3131
try makeDirectories(outdir)
3232
let output = outdir.appending("libfoo\(triple.dynamicLibraryExtension)")
33-
try systemQuietly([executableName("clang"), "-shared", input.pathString, "-o", output.pathString])
33+
try await AsyncProcess.checkNonZeroExit(args: executableName("clang"), "-shared", input.pathString, "-o", output.pathString)
3434

3535
var Xld = ["-L", outdir.pathString]
3636
#if os(Linux) || os(Android)

Tests/FunctionalTests/StaticBinaryLibrary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct StaticBinaryLibraryTests {
2424

2525
try await withKnownIssue {
2626
try await fixture(name: "BinaryLibraries") { fixturePath in
27-
let (stdout, stderr) = try await executeSwiftRun(
27+
let (stdout, _) = try await executeSwiftRun(
2828
fixturePath.appending("Static").appending("Package1"),
2929
"Example",
3030
extraArgs: ["--experimental-prune-unused-dependencies"],

Tests/IntegrationTests/SwiftPMTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import struct SPMBuildCore.BuildSystemProvider
2020
private struct SwiftPMTests {
2121
@Test(.requireHostOS(.macOS))
2222
func binaryTargets() async throws {
23-
try await withKnownIssue("error: the path does not point to a valid framework:") {
23+
await withKnownIssue("error: the path does not point to a valid framework:") {
2424
try await binaryTargetsFixture { fixturePath in
2525
do {
2626
await withKnownIssue("error: local binary target ... does not contain a binary artifact") {

Tests/PackageGraphTests/ModulesGraphTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ struct ModulesGraphTests {
22832283
let observability = try loadUnsafeModulesGraph(toolsVersion: .v6_1)
22842284

22852285
#expect(observability.diagnostics.count == 3)
2286-
try testDiagnostics(observability.diagnostics) { result in
2286+
testDiagnostics(observability.diagnostics) { result in
22872287
var expectedMetadata = ObservabilityMetadata()
22882288
expectedMetadata.moduleName = "Foo2"
22892289
let diagnostic1 = try #require(result.checkUnordered(

0 commit comments

Comments
 (0)