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

Allow setting deployment target devices #541

Merged
merged 26 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
14fe176
Create `DeploymentTarget` descriptor
mollyIV Oct 9, 2019
ef67e4c
Add `DeploymentTarget` to `Target` description
mollyIV Oct 9, 2019
fb0252b
Fix formatting issues
mollyIV Oct 10, 2019
d1ef2ea
Add `DeploymentTarget` to `TuistGenerator.Target`
mollyIV Oct 10, 2019
7486e0d
Update `TARGETED_DEVICE_FAMILY`
mollyIV Oct 10, 2019
cc9f231
Fix formatting
mollyIV Oct 10, 2019
a37720d
Update `*_DEPLOYMENT_TARGET` in Build Settings
mollyIV Oct 11, 2019
37ee400
Fix linter issue
mollyIV Oct 11, 2019
4e851d3
Make sure `platform` and `deploymentTarget` manifest parameters are c…
mollyIV Oct 11, 2019
0e2086d
Move updating a deployment target to `updateTargetDervied` method
mollyIV Oct 11, 2019
c9de8b3
Validate os version of deployment target
mollyIV Oct 11, 2019
8f5ecc2
Update Changelog
mollyIV Oct 11, 2019
5fc3300
Add tests to generator models
mollyIV Oct 11, 2019
440fea8
Mark a breaking change in a changelog entry
mollyIV Oct 12, 2019
9aabecc
Move a regex utility function to `TuistCore`
mollyIV Oct 12, 2019
bcab6cb
Make changes in public API of deployment target
mollyIV Oct 12, 2019
93909c0
Fix unit tests of string regex
mollyIV Oct 13, 2019
f400cc1
Expose `version` property on deployment target
mollyIV Oct 14, 2019
2221d1e
Update Target documenatation
mollyIV Oct 14, 2019
8f2c178
Update acceptance tests
mollyIV Oct 14, 2019
7d3c7a0
Fix formatting
mollyIV Oct 14, 2019
83c1faf
Support mac device for iOS deployment target
mollyIV Oct 15, 2019
30e915a
Fix lint formatting
mollyIV Oct 15, 2019
d9e82b7
Enable catalyst support only if ipad is enabled for iOS deployment ta…
mollyIV Oct 15, 2019
f408af8
Add deployment target tests to `ConfigGenerator`
mollyIV Oct 16, 2019
86d1980
Merge branch 'master' into allow-setting-deployment-target-devices
mollyIV Oct 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Sources/ProjectDescription/DeploymentDevice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

// MARK: - DeploymentDevice

public struct DeploymentDevice: OptionSet, Codable {
public static let iphone = DeploymentDevice(rawValue: 1 << 0)
public static let ipad = DeploymentDevice(rawValue: 1 << 1)
public static let mac = DeploymentDevice(rawValue: 1 << 2)

public let rawValue: UInt

public init(rawValue: UInt) {
self.rawValue = rawValue
}
}
47 changes: 47 additions & 0 deletions Sources/ProjectDescription/DeploymentTarget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Foundation

// MARK: - DeploymentTarget

public enum DeploymentTarget: Codable {
case iOS(String, [DeploymentDevice])
mollyIV marked this conversation as resolved.
Show resolved Hide resolved
case macOS(String)
// TODO: πŸ™ˆ Add `watchOS` and `tvOS` support
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, what platforms should we support in this PR? πŸ€”

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I leave this TODO or is it possible to support watchOS and tvOS right now?


private enum Kind: String, Codable {
case iOS
case macOS
}

enum CodingKeys: String, CodingKey {
case kind
case version
case deploymentDevices
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let kind = try container.decode(Kind.self, forKey: .kind)
switch kind {
case .iOS:
let version = try container.decode(String.self, forKey: .version)
let deploymentDevices = try container.decode([DeploymentDevice].self, forKey: .deploymentDevices)
self = .iOS(version, deploymentDevices)
case .macOS:
let version = try container.decode(String.self, forKey: .version)
self = .macOS(version)
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case let .iOS(version, deploymentDevices):
try container.encode(Kind.iOS.self, forKey: .kind)
try container.encode(version, forKey: .version)
try container.encode(deploymentDevices, forKey: .deploymentDevices)
case let .macOS(version):
try container.encode(Kind.macOS.self, forKey: .kind)
try container.encode(version, forKey: .version)
}
}
}
6 changes: 6 additions & 0 deletions Sources/ProjectDescription/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class Target: Codable {
/// this value to the name of the target.
public let productName: String?

/// Deployment target.
public let deploymentTarget: DeploymentTarget?

/// Relative path to the Info.plist file.
public let infoPlist: InfoPlist

Expand Down Expand Up @@ -66,6 +69,7 @@ public class Target: Codable {
case coreDataModels = "core_data_models"
case actions
case environment
case deploymentTarget
}

/// Initializes the target.
Expand All @@ -90,6 +94,7 @@ public class Target: Codable {
product: Product,
productName: String? = nil,
bundleId: String,
deploymentTarget: DeploymentTarget? = nil,
infoPlist: InfoPlist,
sources: SourceFilesList? = nil,
resources: [FileElement]? = nil,
Expand All @@ -115,5 +120,6 @@ public class Target: Codable {
self.actions = actions
self.coreDataModels = coreDataModels
self.environment = environment
self.deploymentTarget = deploymentTarget
}
}
16 changes: 16 additions & 0 deletions Sources/TuistGenerator/Generator/ConfigGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ final class ConfigGenerator: ConfigGenerating {
let settingsHelper = SettingsHelper()
var settings = try defaultSettingsProvider.targetSettings(target: target,
buildConfiguration: buildConfiguration)
update(buildSettings: &settings, byApplying: target)
settingsHelper.extend(buildSettings: &settings, with: target.settings?.base ?? [:])
settingsHelper.extend(buildSettings: &settings, with: configuration?.settings ?? [:])

Expand All @@ -148,6 +149,21 @@ final class ConfigGenerator: ConfigGenerating {
pbxproj.add(object: variantBuildConfiguration)
configurationList.buildConfigurations.append(variantBuildConfiguration)
}

private func update(buildSettings settings: inout [String: SettingValue], byApplying manifest: Target) {
mollyIV marked this conversation as resolved.
Show resolved Hide resolved
if let deploymentTarget = manifest.deploymentTarget {
switch deploymentTarget {
case let .iOS(_, devices):
if manifest.platform == .iOS {
settings["TARGETED_DEVICE_FAMILY"] = .string(devices.map { "\($0.rawValue)" }.joined(separator: ","))
mollyIV marked this conversation as resolved.
Show resolved Hide resolved
}
case .macOS:
if manifest.platform == .macOS {
settings["TARGETED_DEVICE_FAMILY"] = .string("\(DeploymentDevice.mac.rawValue)")
mollyIV marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}

private func updateTargetDerived(buildSettings settings: inout [String: SettingValue],
target: Target,
Expand Down
15 changes: 15 additions & 0 deletions Sources/TuistGenerator/Models/DeploymentDevice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

// MARK: - DeploymentDevice

public struct DeploymentDevice: OptionSet {
public static let iphone = DeploymentDevice(rawValue: 1 << 0)
public static let ipad = DeploymentDevice(rawValue: 1 << 1)
public static let mac = DeploymentDevice(rawValue: 1 << 2)

public let rawValue: UInt

public init(rawValue: UInt) {
self.rawValue = rawValue
}
}
9 changes: 9 additions & 0 deletions Sources/TuistGenerator/Models/DeploymentTarget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

// MARK: - DeploymentTarget

public enum DeploymentTarget {
case iOS(String, [DeploymentDevice])
case macOS(String)
// TODO: πŸ™ˆ Add `watchOS` and `tvOS` support
pepicrft marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 3 additions & 0 deletions Sources/TuistGenerator/Models/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Target: Equatable, Hashable {
public let product: Product
public let bundleId: String
public let productName: String
public let deploymentTarget: DeploymentTarget?

// An info.plist file is needed for (dynamic) frameworks, applications and executables
// however is not needed for other products such as static libraries.
Expand All @@ -39,6 +40,7 @@ public class Target: Equatable, Hashable {
product: Product,
productName: String?,
bundleId: String,
deploymentTarget: DeploymentTarget? = nil,
infoPlist: InfoPlist? = nil,
entitlements: AbsolutePath? = nil,
settings: Settings? = nil,
Expand All @@ -55,6 +57,7 @@ public class Target: Equatable, Hashable {
self.platform = platform
self.bundleId = bundleId
self.productName = productName ?? name.replacingOccurrences(of: "-", with: "_")
self.deploymentTarget = deploymentTarget
self.infoPlist = infoPlist
self.entitlements = entitlements
self.settings = settings
Expand Down
13 changes: 13 additions & 0 deletions Sources/TuistKit/Generator/GeneratorModelLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ extension TuistGenerator.Target {

let bundleId = manifest.bundleId
let productName = manifest.productName
let deploymentTarget = manifest.deploymentTarget.map { TuistGenerator.DeploymentTarget.from(manifest: $0) }

let dependencies = manifest.dependencies.map { TuistGenerator.Dependency.from(manifest: $0) }

Expand Down Expand Up @@ -336,6 +337,7 @@ extension TuistGenerator.Target {
product: product,
productName: productName,
bundleId: bundleId,
deploymentTarget: deploymentTarget,
infoPlist: infoPlist,
entitlements: entitlements,
settings: settings,
Expand Down Expand Up @@ -699,3 +701,14 @@ extension TuistGenerator.SDKStatus {
}
}
}

extension TuistGenerator.DeploymentTarget {
static func from(manifest: ProjectDescription.DeploymentTarget) -> TuistGenerator.DeploymentTarget {
switch manifest {
case let .iOS(version, devices):
return .iOS(version, devices.map { DeploymentDevice(rawValue: $0.rawValue) })
case let .macOS(version):
return .macOS(version)
}
}
}
19 changes: 19 additions & 0 deletions Tests/ProjectDescriptionTests/DeploymentTargetTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation
import TuistCoreTesting
import XCTest

@testable import ProjectDescription

final class DeploymentTargetTests: XCTestCase {
func test_toJSON_whenIOS() {
let subject = DeploymentTarget.iOS("13.1", [.iphone, .ipad])
let expected = "{\"kind\":\"iOS\",\"version\":\"13.1\",\"deploymentDevices\":[1,2]}"
XCTAssertCodableEqualToJson(subject, expected)
}

func test_toJSON_whenMacOS() {
let subject = DeploymentTarget.macOS("10.15")
let expected = "{\"kind\":\"macOS\",\"version\":\"10.15\"}"
XCTAssertCodableEqualToJson(subject, expected)
}
}
6 changes: 6 additions & 0 deletions Tests/ProjectDescriptionTests/TargetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final class TargetTests: XCTestCase {
product: .app,
productName: "product_name",
bundleId: "bundle_id",
deploymentTarget: .iOS("13.1", [.iphone, .ipad]),
infoPlist: "info.plist",
sources: "sources/*",
resources: "resources/*",
Expand All @@ -37,6 +38,11 @@ final class TargetTests: XCTestCase {

let expected = """
{
"deploymentTarget": {
"kind": "iOS",
"version": "13.1",
"deploymentDevices": [1, 2]
},
"headers": {
"public": { "globs": ["public\\/*"] },
"private": { "globs": ["private\\/*"] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extension Target {
product: Product = .app,
productName: String? = nil,
bundleId: String = "com.test.bundle_id",
deploymentTarget: DeploymentTarget? = .iOS("13.1", [.iphone, .ipad]),
infoPlist: InfoPlist? = .file(path: AbsolutePath("/Info.plist")),
entitlements: AbsolutePath? = AbsolutePath("/Test.entitlements"),
settings: Settings? = Settings.test(),
Expand Down Expand Up @@ -45,6 +46,7 @@ extension Target {
product: Product = .app,
productName: String? = nil,
bundleId: String = "com.test.bundleId",
deploymentTarget: DeploymentTarget? = nil,
infoPlist: InfoPlist? = nil,
entitlements: AbsolutePath? = nil,
settings: Settings? = nil,
Expand Down