Skip to content

Commit

Permalink
Add support to declare actions for which a target should be built
Browse files Browse the repository at this point in the history
  • Loading branch information
pepicrft committed Sep 23, 2024
1 parent 9235c33 commit 93e776b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
52 changes: 50 additions & 2 deletions Sources/XcodeGraph/Models/BuildAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,70 @@ import Foundation
import Path

public struct BuildAction: Equatable, Codable, Sendable {
/// It represents the reference to a target from a build action, along with the actions when the target
/// should be built.
public struct Target: Equatable, Codable, Sendable {
/// Xcode project actions when a build scheme action can build a target.
public enum BuildFor: Codable, CaseIterable, Sendable {
case running, testing, profiling, archiving, analyzing
}

/// The target reference.
public var reference: TargetReference

/// A list of Xcode actions when a target should build.
public var buildFor: [BuildFor]?

public init(_ reference: TargetReference, buildFor: [BuildFor]?) {
self.reference = reference
self.buildFor = buildFor
}
}

// MARK: - Attributes

public var targets: [TargetReference]
public var targetsWithBuildFor: [Target]
@available(
*,
deprecated,
renamed: "targetsWithBuildFor",
message: "Use the initializer that takes targets as instances of BuildAction.Target"
)
public var targets: [TargetReference] {
get {
targetsWithBuildFor.map(\.reference)
}
set {
targetsWithBuildFor = newValue.map { Target($0, buildFor: nil) }
}
}

public var preActions: [ExecutionAction]
public var postActions: [ExecutionAction]
public var runPostActionsOnFailure: Bool

// MARK: - Init

@available(*, deprecated, message: "Use the initializer that takes targets as instances of BuildAction.Target")
public init(
targets: [TargetReference] = [],
preActions: [ExecutionAction] = [],
postActions: [ExecutionAction] = [],
runPostActionsOnFailure: Bool = false
) {
self.targets = targets
targetsWithBuildFor = targets.map { Target($0, buildFor: nil) }
self.preActions = preActions
self.postActions = postActions
self.runPostActionsOnFailure = runPostActionsOnFailure
}

public init(
targetsWithBuildFor: [BuildAction.Target] = [],
preActions: [ExecutionAction] = [],
postActions: [ExecutionAction] = [],
runPostActionsOnFailure: Bool = false
) {
self.targetsWithBuildFor = targetsWithBuildFor
self.preActions = preActions
self.postActions = postActions
self.runPostActionsOnFailure = runPostActionsOnFailure
Expand Down
6 changes: 3 additions & 3 deletions Tests/XcodeGraphTests/Models/BuildActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ final class BuildActionTests: XCTestCase {
func test_codable() {
// Given
let subject = BuildAction(
targets: [
.init(
targetsWithBuildFor: [
BuildAction.Target(TargetReference(
projectPath: try! AbsolutePath(validating: "/path/to/project"),
name: "name"
),
), buildFor: [.running]),
],
preActions: [
.init(
Expand Down

0 comments on commit 93e776b

Please sign in to comment.