Skip to content

Commit

Permalink
Merge pull request #2096 from thedavidharris/dh--runnable-watch
Browse files Browse the repository at this point in the history
fix: make watch targets runnable to fix schemes in Xcode 12
  • Loading branch information
Pedro Piñera Buendía committed Dec 3, 2020
2 parents 8bc5a8b + e66df79 commit d6fcc68
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/TuistCore/Models/Product.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public enum Product: String, CustomStringConvertible, CaseIterable, Encodable {
/// Returns true if the target can be ran.
public var runnable: Bool {
switch self {
case .app, .appClip, .commandLineTool:
case .app, .appClip, .commandLineTool, .watch2App:
return true
default:
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public final class AutogeneratedSchemesProjectMapper: ProjectMapping {
switch target.product {
case .appExtension, .messagesExtension:
return hostAppTargetReferences(for: target, project: project).first
case .watch2Extension:
return hostWatchAppTargetReferences(for: target, project: project).first
default:
return targetReference
}
Expand All @@ -109,4 +111,13 @@ public final class AutogeneratedSchemesProjectMapper: ProjectMapping {
.sorted(by: { $0.name < $1.name })
.map { TargetReference(projectPath: project.path, name: $0.name) }
}

private func hostWatchAppTargetReferences(for target: Target,
project: Project) -> [TargetReference]
{
project.targets
.filter { $0.product == .watch2App && $0.dependencies.contains(.target(name: target.name)) }
.sorted(by: { $0.name < $1.name })
.map { TargetReference(projectPath: project.path, name: $0.name) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class ProductTests: XCTestCase {

func test_runnable() {
Product.allCases.forEach { product in
if [.app, .appClip, .commandLineTool].contains(product) {
if [.app, .appClip, .commandLineTool, .watch2App].contains(product) {
XCTAssertTrue(product.runnable)
} else {
XCTAssertFalse(product.runnable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,38 @@ final class AutogeneratedSchemesProjectMapperTests: TuistUnitTestCase {
])
}

func test_map_watch2() throws {
// Given
let path = AbsolutePath("/test")
let app = Target.test(name: "App",
product: .app,
dependencies: [
.target(name: "WatchApp"),
])
let watchApp = Target.test(name: "WatchApp", product: .watch2App, dependencies: [.target(name: "WatchExtension")])
let watchAppExtension = Target.test(name: "WatchExtension", product: .watch2Extension)

let project = Project.test(path: path, targets: [app, watchApp, watchAppExtension])

// When
let (got, _) = try subject.map(project: project)

// Then
let buildActions = got.schemes.map(\.buildAction?.targets)
XCTAssertEqual(buildActions, [
[TargetReference(projectPath: path, name: "App")],
[TargetReference(projectPath: path, name: "WatchApp")],
[TargetReference(projectPath: path, name: "WatchExtension")],
])

let runActions = got.schemes.map(\.runAction?.executable)
XCTAssertEqual(runActions, [
TargetReference(projectPath: path, name: "App"),
TargetReference(projectPath: path, name: "WatchApp"),
TargetReference(projectPath: path, name: "WatchApp"),
])
}

func test_map_enables_test_coverage_on_generated_schemes() throws {
// Given
subject = AutogeneratedSchemesProjectMapper(enableCodeCoverage: true)
Expand Down

0 comments on commit d6fcc68

Please sign in to comment.