File: TaskResult.swift

package info (click to toggle)
swiftlang 6.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,856,264 kB
  • sloc: cpp: 9,995,718; ansic: 2,234,019; asm: 1,092,167; python: 313,940; objc: 82,726; f90: 80,126; lisp: 38,373; pascal: 25,580; sh: 20,378; ml: 5,058; perl: 4,751; makefile: 4,725; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (87 lines) | stat: -rw-r--r-- 2,782 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 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
//
//===----------------------------------------------------------------------===//

public import SWBUtil

/// `TaskResult` represents the result of either a command or a command process.
public enum TaskResult: Hashable, Sendable {
    /// The task ran and exited with the given status
    case exit(exitStatus: Processes.ExitStatus, metrics: CommandMetrics?)

    /// The task could not run due to a set up failure like missing inputs
    case failedSetup

    /// The task got skipped by the build engine
    case skipped

    public static func succeeded(metrics: CommandMetrics? = nil) -> TaskResult {
        .exit(exitStatus: .exit(0), metrics: metrics)
    }

    public var isSuccess: Bool {
        switch self {
        case .exit(let exitStatus, _):
            return exitStatus.isSuccess
        case .failedSetup:
            return false
        case .skipped:
            return true
        }
    }

    public var isCancelled: Bool {
        switch self {
        case .exit(let exitStatus, _):
            return exitStatus.wasCanceled
        case .failedSetup:
            return false
        case .skipped:
            return false
        }
    }

    public var metrics: CommandMetrics? {
        guard case let .exit(_, metrics) = self else {
            return nil
        }
        return metrics
    }

}

public extension Optional where Wrapped == TaskResult {
    /// Indicates that a task failed in a way that parsers reading diagnostics should be skipped.
    ///
    /// **NOTE**: This applies to crashed or cancelled tasks
    var shouldSkipParsingDiagnostics: Bool {
        switch self {
        case .exit(exitStatus: let status, metrics: _):
            return status.wasCanceled
        case .skipped: return false
        case .failedSetup, nil: return true
        }
    }
}

public struct CommandMetrics: Hashable, Sendable {
    public let utime: UInt64         /// User time (in μs)
    public let stime: UInt64         /// Sys time (in μs)
    public let maxRSS: UInt64        /// Max RSS (in bytes)
    public let wcDuration: ElapsedTimerInterval? /// Wall time duration (in μs).

    public init(utime: UInt64, stime: UInt64, maxRSS: UInt64, wcDuration: ElapsedTimerInterval?) {
        self.utime = utime
        self.stime = stime
        self.maxRSS = maxRSS
        self.wcDuration = wcDuration
    }
}