Skip to content

Commit

Permalink
Add acceptance test and add ability to run multiplatform targets via …
Browse files Browse the repository at this point in the history
…`test` and `build`
  • Loading branch information
waltflanagan committed Nov 21, 2023
1 parent 92d956b commit 378a581
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Sources/TuistKit/Commands/BuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ struct BuildCommand: AsyncParsableCommand {
)
var device: String?

@Option(
name: .long,
help: "Build for a specific platform."
)
var platform: String?

@Option(
name: .shortAndLong,
help: "Build with a specific version of the OS."
Expand Down Expand Up @@ -86,6 +92,7 @@ struct BuildCommand: AsyncParsableCommand {
derivedDataPath: derivedDataPath,
path: absolutePath,
device: device,
platform: platform,
osVersion: os,
rosetta: rosetta
)
Expand Down
7 changes: 7 additions & 0 deletions Sources/TuistKit/Commands/TestCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public struct TestCommand: AsyncParsableCommand, HasTrackableParameters {
help: "Test on a specific device."
)
var device: String?

@Option(
name: .shortAndLong,
help: "Test on a specific platform."
)
var platform: String?

@Option(
name: .shortAndLong,
Expand Down Expand Up @@ -140,6 +146,7 @@ public struct TestCommand: AsyncParsableCommand, HasTrackableParameters {
configuration: configuration,
path: absolutePath,
deviceName: device,
platform: platform,
osVersion: os,
rosetta: rosetta,
skipUITests: skipUITests,
Expand Down
23 changes: 20 additions & 3 deletions Sources/TuistKit/Services/BuildService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ final class BuildService {
derivedDataPath: String?,
path: AbsolutePath,
device: String?,
platform: String?,
osVersion: String?,
rosetta: Bool
) async throws {
Expand Down Expand Up @@ -96,10 +97,18 @@ final class BuildService {
guard let graphTarget = buildGraphInspector.buildableTarget(scheme: scheme, graphTraverser: graphTraverser) else {
throw TargetBuilderError.schemeWithoutBuildableTargets(scheme: scheme.name)
}


let buildPlatform: TuistGraph.Platform

if let platform, let inputPlatform = TuistGraph.Platform(rawValue: platform) {
buildPlatform = inputPlatform
} else {
buildPlatform = try graphTarget.target.servicePlatform
}

try await targetBuilder.buildTarget(
graphTarget,
platform: try graphTarget.target.servicePlatform,
platform: buildPlatform,
workspacePath: workspacePath,
scheme: scheme,
clean: clean,
Expand All @@ -119,10 +128,18 @@ final class BuildService {
guard let graphTarget = buildGraphInspector.buildableTarget(scheme: scheme, graphTraverser: graphTraverser) else {
throw TargetBuilderError.schemeWithoutBuildableTargets(scheme: scheme.name)
}

let buildPlatform: TuistGraph.Platform

if let platform, let inputPlatform = TuistGraph.Platform(rawValue: platform) {
buildPlatform = inputPlatform
} else {
buildPlatform = try graphTarget.target.servicePlatform
}

try await targetBuilder.buildTarget(
graphTarget,
platform: try graphTarget.target.servicePlatform,
platform: buildPlatform,
workspacePath: workspacePath,
scheme: scheme,
clean: !cleaned && clean,
Expand Down
15 changes: 13 additions & 2 deletions Sources/TuistKit/Services/TestService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public final class TestService { // swiftlint:disable:this type_body_length
configuration: String?,
path: AbsolutePath,
deviceName: String?,
platform: String?,
osVersion: String?,
rosetta: Bool,
skipUITests: Bool,
Expand Down Expand Up @@ -245,6 +246,7 @@ public final class TestService { // swiftlint:disable:this type_body_length
configuration: configuration,
version: version,
deviceName: deviceName,
platform: platform,
rosetta: rosetta,
resultBundlePath: resultBundlePath,
derivedDataPath: derivedDataPath,
Expand Down Expand Up @@ -273,6 +275,7 @@ public final class TestService { // swiftlint:disable:this type_body_length
configuration: configuration,
version: version,
deviceName: deviceName,
platform: platform,
rosetta: rosetta,
resultBundlePath: resultBundlePath,
derivedDataPath: derivedDataPath,
Expand Down Expand Up @@ -315,6 +318,7 @@ public final class TestService { // swiftlint:disable:this type_body_length
configuration: String?,
version: Version?,
deviceName: String?,
platform: String?,
rosetta: Bool,
resultBundlePath: AbsolutePath?,
derivedDataPath: AbsolutePath?,
Expand Down Expand Up @@ -343,11 +347,18 @@ public final class TestService { // swiftlint:disable:this type_body_length
throw TestServiceError.schemeWithoutTestableTargets(scheme: scheme.name, testPlan: testPlanConfiguration?.testPlan)
}

let platform = try buildableTarget.target.servicePlatform
let buildPlatform: TuistGraph.Platform

if let platform, let inputPlatform = TuistGraph.Platform(rawValue: platform) {
buildPlatform = inputPlatform
} else {
buildPlatform = try buildableTarget.target.servicePlatform
}


let destination = try await XcodeBuildDestination.find(
for: buildableTarget.target,
on: platform,
on: buildPlatform,
scheme: scheme,
version: version,
deviceName: deviceName,
Expand Down
9 changes: 9 additions & 0 deletions Tests/TuistBuildAcceptanceTests/BuildAcceptanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ final class BuildAcceptanceTestFrameworkWithSwiftMacroIntegratedWithXcodeProjPri
try await run(BuildCommand.self, "Framework")
}
}

final class BuildAcceptanceTestMultiplatformAppWithSDK: TuistAcceptanceTestCase {
func test() async throws {
try setUpFixture("multiplatform_app_with_sdk")
try await run(FetchCommand.self)
try await run(BuildCommand.self, "App", "--platform", "macos")
try await run(BuildCommand.self, "App", "--platform", "ios")
}
}
4 changes: 3 additions & 1 deletion Tests/TuistKitTests/Services/BuildServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ extension BuildService {
derivedDataPath: String? = nil,
path: AbsolutePath,
device: String? = nil,
platform: String? = nil,
osVersion: String? = nil,
rosetta: Bool = false
) async throws {
Expand All @@ -319,7 +320,8 @@ extension BuildService {
buildOutputPath: buildOutputPath,
derivedDataPath: derivedDataPath,
path: path,
device: device,
device: device,
platform: platform,
osVersion: osVersion,
rosetta: rosetta
)
Expand Down
2 changes: 2 additions & 0 deletions Tests/TuistKitTests/Services/TestServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ extension TestService {
configuration: String? = nil,
path: AbsolutePath,
deviceName: String? = nil,
platform: String? = nil,
osVersion: String? = nil,
rosetta: Bool = false,
skipUiTests: Bool = false,
Expand All @@ -645,6 +646,7 @@ extension TestService {
configuration: configuration,
path: path,
deviceName: deviceName,
platform: platform,
osVersion: osVersion,
rosetta: rosetta,
skipUITests: skipUiTests,
Expand Down

0 comments on commit 378a581

Please sign in to comment.