Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make watch targets runnable to fix schemes in Xcode 12 #2096

Merged
merged 1 commit into from
Dec 3, 2020
Merged
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
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