Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if(FIND_PM_DEPS)
find_package(SwiftCertificates CONFIG REQUIRED)
find_package(SwiftCrypto CONFIG REQUIRED)
find_package(SwiftBuild CONFIG REQUIRED)
find_package(SwiftSubprocess CONFIG REQUIRED)
endif()

find_package(dispatch QUIET)
Expand Down
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ let package = Package(
dependencies: [
"_AsyncFileSystem",
.target(name: "SPMSQLite3", condition: .when(platforms: [.macOS, .iOS, .tvOS, .watchOS, .visionOS, .macCatalyst, .linux, .openbsd, .custom("freebsd")])),
.product(name: "Subprocess", package: "swift-subprocess"),
.product(name: "SwiftToolchainCSQLite", package: "swift-toolchain-sqlite", condition: .when(platforms: [.windows, .android])),
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "OrderedCollections", package: "swift-collections"),
Expand Down Expand Up @@ -575,6 +576,7 @@ let package = Package(
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "OrderedCollections", package: "swift-collections"),
.product(name: "Subprocess", package: "swift-subprocess"),
"Basics",
"BinarySymbols",
"Build",
Expand Down Expand Up @@ -1113,6 +1115,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(url: "https://github.com/apple/swift-system.git", revision: "1.5.0"),
.package(url: "https://github.com/apple/swift-collections.git", revision: "1.1.6"),
.package(url: "https://github.com/apple/swift-certificates.git", revision: "1.10.1"),
.package(url: "https://github.com/swiftlang/swift-subprocess.git", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/swiftlang/swift-toolchain-sqlite.git", revision: "1.0.7"),
// Not in toolchain, used for use in previewing documentation
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.1.0"),
Expand All @@ -1131,6 +1134,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(path: "../swift-system"),
.package(path: "../swift-collections"),
.package(path: "../swift-certificates"),
.package(path: "../swift-subprocess"),
.package(path: "../swift-toolchain-sqlite"),
]
if !swiftDriverDeps.isEmpty {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ add_library(Basics
Serialization/SerializedJSON.swift
SwiftVersion.swift
SQLiteBackedCache.swift
Subprocess+Extensions.swift
TestingLibrary.swift
Triple+Basics.swift
URL.swift
Expand All @@ -83,6 +84,7 @@ add_library(Basics
target_link_libraries(Basics PUBLIC
_AsyncFileSystem
SwiftCollections::OrderedCollections
SwiftSubprocess::Subprocess
TSCBasic
TSCUtility)
target_link_libraries(Basics PRIVATE
Expand Down
11 changes: 11 additions & 0 deletions Sources/Basics/Cancellator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ public final class Cancellator: Cancellable, Sendable {
}
}

extension Cancellator {
public func run<T: Sendable>(name: String, _ block: @escaping @Sendable () async throws -> T) async throws -> T {
let task = Task { try await block() }
let token = register(name: name, handler: { _ in task.cancel() })
defer {
token.map { deregister($0) }
}
return try await task.value
}
}

public protocol Cancellable {
func cancel(deadline: DispatchTime) throws -> Void
}
Expand Down
39 changes: 39 additions & 0 deletions Sources/Basics/Subprocess+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Subprocess
import TSCBasic

#if canImport(System)
import System
#else
import SystemPackage
#endif

extension Subprocess.Environment {
public init(_ env: Basics.Environment) {
var newEnv: [Subprocess.Environment.Key: String] = [:]
for (key, value) in env {
newEnv[.init(rawValue: key.rawValue)!] = value
}
self = Subprocess.Environment.custom(newEnv)
}
}

extension Subprocess.Configuration {
public init(commandLine: [String], environment: Subprocess.Environment) throws {
guard let arg0 = commandLine.first else {
throw StringError("command line was unexpectedly empty")
}
self.init(.path(FilePath(arg0)), arguments: .init(Array(commandLine.dropFirst())), environment: environment)
}
}
1 change: 1 addition & 0 deletions Sources/Commands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_library(Commands
target_link_libraries(Commands PUBLIC
SwiftCollections::OrderedCollections
SwiftSyntax::SwiftRefactor
SwiftSubprocess::Subprocess
ArgumentParser
Basics
BinarySymbols
Expand Down
Loading