Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
waltflanagan committed Nov 21, 2023
1 parent 3d1731f commit 9d1d96b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 36 deletions.
50 changes: 28 additions & 22 deletions Sources/ProjectDescription/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct Target: Codable, Equatable {

/// The destinations this target supports
public let destinations: Destinations

/// The type of build product this target will output.
public let product: Product

Expand All @@ -19,7 +19,7 @@ public struct Target: Codable, Equatable {

/// The minimum deployment target your product will support.
public let deploymentTargets: DeploymentTargets?

/// The Info.plist representation.
public let infoPlist: InfoPlist?

Expand Down Expand Up @@ -144,7 +144,7 @@ public struct Target: Codable, Equatable {
mergeable: Bool = false
) {
self.name = name
self.destinations = Destinations.from(platform: platform, deploymentTarget: deploymentTarget)
destinations = Destinations.from(platform: platform, deploymentTarget: deploymentTarget)
self.bundleId = bundleId
self.productName = productName
self.product = product
Expand All @@ -160,7 +160,7 @@ public struct Target: Codable, Equatable {
self.coreDataModels = coreDataModels
self.environmentVariables = environmentVariables
self.launchArguments = launchArguments
self.deploymentTargets = DeploymentTargets.from(manifest: deploymentTarget)
deploymentTargets = DeploymentTargets.from(manifest: deploymentTarget)
self.additionalFiles = additionalFiles
self.buildRules = buildRules
self.mergedBinaryType = mergedBinaryType
Expand Down Expand Up @@ -193,7 +193,7 @@ public struct Target: Codable, Equatable {
mergeable: Bool = false
) {
self.name = name
self.destinations = Destinations.from(platform: platform, deploymentTarget: deploymentTarget)
destinations = Destinations.from(platform: platform, deploymentTarget: deploymentTarget)
self.bundleId = bundleId
self.productName = productName
self.product = product
Expand All @@ -211,45 +211,53 @@ public struct Target: Codable, Equatable {
EnvironmentVariable(value: value, isEnabled: true)
}
self.launchArguments = launchArguments
self.deploymentTargets = DeploymentTargets.from(manifest: deploymentTarget)
deploymentTargets = DeploymentTargets.from(manifest: deploymentTarget)
self.additionalFiles = additionalFiles
self.buildRules = buildRules
self.mergedBinaryType = mergedBinaryType
self.mergeable = mergeable
}
}


extension Target {
@available(*, deprecated, renamed: "Destinations", message: "Targets are no longer constrained to a single platform")
var platform: Platform {
destinations.platforms.first ?? .iOS
}

@available(*, deprecated, renamed: "DeploymentTargets", message: "Device support is now defined in Destinations. Minimum Deployment Version is defined in DeploymentTargets")
@available(
*,
deprecated,
renamed: "DeploymentTargets",
message: "Device support is now defined in Destinations. Minimum Deployment Version is defined in DeploymentTargets"
)
var deploymentTarget: DeploymentTarget? {
switch platform {
case .iOS:
guard let version = deploymentTargets?.iOS else { return nil }
var devices = DeploymentDevice()

if destinations.contains(.iPhone) {
devices.insert(.iphone)
}

if destinations.contains(.iPad) {
devices.insert(.ipad)
}

if destinations.contains(.macCatalyst) {
devices.insert(.mac)
}

if destinations.contains(.appleVisionWithiPadDesign) {
devices.insert(.vision)
}

return .iOS(targetVersion: version, devices: devices, supportsMacDesignedForIOS: destinations.contains(.macWithiPadDesign))

return .iOS(
targetVersion: version,
devices: devices,
supportsMacDesignedForIOS: destinations.contains(.macWithiPadDesign)
)
case .macOS:
guard let version = deploymentTargets?.macOS else { return nil }
return .macOS(targetVersion: version)
Expand All @@ -266,9 +274,7 @@ extension Target {
}
}


extension Destinations {

/// Maps a ProjectDescription.Package instance into a TuistGraph.Package model.
/// - Parameters:
/// - manifest: Manifest representation of Package.
Expand All @@ -282,27 +288,27 @@ extension Destinations {
return [.mac]
case let (.iOS, .some(.iOS(_, devices, supportsMacDesignedForIOS: supportsMacDesignedForIOS))):
var destinations: [Destination] = []

if devices.contains(.iphone) {
destinations.append(.iPhone)
}

if devices.contains(.ipad) {
destinations.append(.iPad)
}

if devices.contains(.mac) {
destinations.append(.macCatalyst)
}

if devices.contains(.vision) {
destinations.append(.appleVisionWithiPadDesign)
}

if supportsMacDesignedForIOS {
destinations.append(.macWithiPadDesign)
}

return Set(destinations)
case (.iOS, _): // an iOS platform, but `nil` deployment target.
return .iOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ public final class PackageInfoMapper: PackageInfoMapping {
case let .xcframework(path, platformFilters):
return .xcframework(path: path, platformFilters: platformFilters)
case let .target(name, filters):
return .project(target: name, path: Path(packageToFolder[packageInfo.key]!.pathString), platformFilters: filters)
return .project(
target: name,
path: Path(packageToFolder[packageInfo.key]!.pathString),
platformFilters: filters
)
case .externalTarget:
throw PackageInfoMapperError.unknownProductTarget(
package: packageInfo.key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ final class InfoPlistContentProvider: InfoPlistContentProviding {
"WKExtensionDelegateClassName": "$(PRODUCT_MODULE_NAME).ExtensionDelegate",
]
}

/// Given a dictionary, it extends it with another dictionary.
///
/// - Parameters:
Expand All @@ -240,7 +240,7 @@ final class InfoPlistContentProvider: InfoPlistContentProviding {
fileprivate func extend(_ base: inout [String: Any], with: [String: Any]) {
with.forEach { base[$0.key] = $0.value }
}

private func hostTarget(for target: Target, in project: Project) -> Target? {
project.targets.first {
$0.dependencies.contains(where: { dependency in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2988,7 +2988,7 @@ final class PackageInfoMapperTests: TuistUnitTestCase {
.test(
"Dependency1",
basePath: basePath,
destinations: [.iPhone, .iPad, .macWithiPadDesign, .appleVisionWithiPadDesign, .appleTv],
destinations: [.iPhone, .iPad, .macWithiPadDesign, .appleVisionWithiPadDesign, .appleTv],
customProductName: "Dependency1",
customBundleID: "Dependency1",
deploymentTargets: .init(iOS: "11.0", tvOS: "11.0"),
Expand Down Expand Up @@ -3070,7 +3070,7 @@ final class PackageInfoMapperTests: TuistUnitTestCase {
.test(
"Target1",
basePath: basePath,
destinations: [.iPhone, .iPad, .macWithiPadDesign, .appleVisionWithiPadDesign, .appleTv],
destinations: [.iPhone, .iPad, .macWithiPadDesign, .appleVisionWithiPadDesign, .appleTv],
customProductName: "Target1",
customBundleID: "Target1",
deploymentTargets: .init(iOS: "11.0", tvOS: "11.0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ final class ResourcesProjectMapperTests: TuistUnitTestCase {
XCTAssertEqual(gotTarget.sources.first?.path, expectedPath)
XCTAssertNotNil(gotTarget.sources.first?.contentHash)
XCTAssertEqual(gotTarget.dependencies.count, 1)
XCTAssertEqual(gotTarget.dependencies.first, TargetDependency.target(name: "\(project.name)_\(target.name)", platformFilters: [.ios]))
XCTAssertEqual(
gotTarget.dependencies.first,
TargetDependency.target(name: "\(project.name)_\(target.name)", platformFilters: [.ios])
)

let resourcesTarget = try XCTUnwrap(gotProject.targets.last)
XCTAssertEqual(resourcesTarget.name, "\(project.name)_\(target.name)")
Expand Down Expand Up @@ -136,7 +139,10 @@ final class ResourcesProjectMapperTests: TuistUnitTestCase {
XCTAssertEqual(gotTarget.sources.first?.path, expectedPath)
XCTAssertNotNil(gotTarget.sources.first?.contentHash)
XCTAssertEqual(gotTarget.dependencies.count, 1)
XCTAssertEqual(gotTarget.dependencies.first, TargetDependency.target(name: "\(project.name)_\(target.name)", platformFilters: [.ios]))
XCTAssertEqual(
gotTarget.dependencies.first,
TargetDependency.target(name: "\(project.name)_\(target.name)", platformFilters: [.ios])
)

let resourcesTarget = try XCTUnwrap(gotProject.targets.last)
XCTAssertEqual(resourcesTarget.name, "\(project.name)_\(target.name)")
Expand Down
10 changes: 5 additions & 5 deletions Tests/TuistGraphTests/Models/TargetDependencyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ final class TargetDependencyTests: TuistUnitTestCase {
// Then
XCTAssertCodable(subject)
}

func test_filtering() {
let expected: PlatformFilters = [.macos]

let subjects: [TargetDependency] = [
.framework(path: "/", status: .required, platformFilters: expected),
.library(path: "/", publicHeaders: "/", swiftModuleMap: "/", platformFilters: expected),
.sdk(name: "", status: .required, platformFilters: expected),
.package(product: "", type: .plugin, platformFilters: expected),
.target(name: "", platformFilters: expected),
.xcframework(path: "/", status: .required, platformFilters: expected),
.project(target: "", path: "/", platformFilters: expected)
.project(target: "", path: "/", platformFilters: expected),
]

for subject in subjects {
XCTAssertEqual(subject.platformFilters, expected)
XCTAssertEqual(subject.withFilters([.catalyst]).platformFilters, Set([.catalyst]))
}
}
}

func test_xctest_platformFilters_alwaysReturnAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private func == (
_ lhs: TuistGraph.Destinations,
_ rhs: ProjectDescription.Destinations
) -> Bool {
return lhs.map(\.rawValue).sorted() == rhs.map(\.rawValue).sorted()
lhs.map(\.rawValue).sorted() == rhs.map(\.rawValue).sorted()
}

private func == (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import TuistGraphTesting
import TuistSupport
import XCTest

@testable import ProjectDescription
@testable import TuistLoader
@testable import TuistSupportTesting
@testable import ProjectDescription

final class DeploymentTargetsManifestMapperTests: TuistUnitTestCase {
func test_deploymentTarget() throws {
Expand Down

0 comments on commit 9d1d96b

Please sign in to comment.