Skip to content

Commit

Permalink
Support PRODUCT_NAME in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieatkinson committed Jul 3, 2019
1 parent f584917 commit 958e4d2
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 21 deletions.
8 changes: 8 additions & 0 deletions Sources/ProjectDescription/Target.swift
Expand Up @@ -14,6 +14,11 @@ public class Target: Codable {

/// Bundle identifier.
public let bundleId: String

/// The name of the product output by this target.
/// passing nil in the initialiser will default
/// this value to the name of the target.
public let productName: String

/// Relative path to the Info.plist file.
public let infoPlist: InfoPlist
Expand Down Expand Up @@ -49,6 +54,7 @@ public class Target: Codable {
case name
case platform
case product
case productName = "product_name"
case bundleId = "bundle_id"
case infoPlist = "info_plist"
case entitlements
Expand Down Expand Up @@ -82,6 +88,7 @@ public class Target: Codable {
public init(name: String,
platform: Platform,
product: Product,
productName: String? = nil,
bundleId: String,
infoPlist: InfoPlist,
sources: FileList? = nil,
Expand All @@ -96,6 +103,7 @@ public class Target: Codable {
self.name = name
self.platform = platform
self.bundleId = bundleId
self.productName = productName ?? name
self.product = product
self.infoPlist = infoPlist
self.entitlements = entitlements
Expand Down
6 changes: 4 additions & 2 deletions Sources/TuistGenerator/Generator/ConfigGenerator.swift
Expand Up @@ -174,17 +174,19 @@ final class ConfigGenerator: ConfigGenerating {
if target.product == .staticFramework {
settings["MACH_O_TYPE"] = "staticlib"
}

settings["PRODUCT_NAME"] = target.productName

if target.product.testsBundle {
let appDependency = graph.targetDependencies(path: sourceRootPath, name: target.name).first { targetNode in
targetNode.target.product == .app
}

if let app = appDependency {
settings["TEST_TARGET_NAME"] = "\(app.target.name)"
settings["TEST_TARGET_NAME"] = "\(app.target.productName)"

if target.product == .unitTests {
settings["TEST_HOST"] = "$(BUILT_PRODUCTS_DIR)/\(app.target.productNameWithExtension)/\(app.target.name)"
settings["TEST_HOST"] = "$(BUILT_PRODUCTS_DIR)/\(app.target.productNameWithExtension)/\(app.target.productName)"
settings["BUNDLE_LOADER"] = "$(TEST_HOST)"
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/TuistGenerator/Generator/SchemesGenerator.swift
Expand Up @@ -53,7 +53,7 @@ final class SchemesGenerator: SchemesGenerating {
buildAction: BuildAction(targets: [target.name]),
testAction: TestAction(targets: [target.name]),
runAction: RunAction(config: .debug,
executable: target.name,
executable: target.productName,
arguments: Arguments(environment: target.environment)))

try generateScheme(scheme: scheme,
Expand Down
8 changes: 4 additions & 4 deletions Sources/TuistGenerator/Graph/GraphLoader.swift
Expand Up @@ -38,8 +38,8 @@ class GraphLoader: GraphLoading {
let cache = GraphLoaderCache()
let circularDetector = GraphCircularDetector()
let project = try Project.at(path, cache: cache, circularDetector: circularDetector, modelLoader: modelLoader)
let entryNodes: [GraphNode] = try project.targets.map { $0.name }.map { targetName in
try TargetNode.read(name: targetName, path: path, cache: cache, circularDetector: circularDetector, modelLoader: modelLoader)
let entryNodes: [GraphNode] = try project.targets.map { target in
try TargetNode.read(name: target.name, path: path, cache: cache, circularDetector: circularDetector, modelLoader: modelLoader)
}
let graph = Graph(name: project.name,
entryPath: path,
Expand All @@ -57,8 +57,8 @@ class GraphLoader: GraphLoading {
try (projectPath, Project.at(projectPath, cache: cache, circularDetector: circularDetector, modelLoader: modelLoader))
}
let entryNodes = try projects.flatMap { (project) -> [TargetNode] in
try project.1.targets.map { $0.name }.map { targetName in
try TargetNode.read(name: targetName, path: project.0, cache: cache, circularDetector: circularDetector, modelLoader: modelLoader)
try project.1.targets.map { target in
try TargetNode.read(name: target.name, path: project.0, cache: cache, circularDetector: circularDetector, modelLoader: modelLoader)
}
}
let graph = Graph(name: workspace.name,
Expand Down
8 changes: 6 additions & 2 deletions Sources/TuistGenerator/Models/Target.swift
Expand Up @@ -16,6 +16,7 @@ public class Target: Equatable {
public let platform: Platform
public let product: Product
public let bundleId: String
public let productName: String

// 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 @@ -36,6 +37,7 @@ public class Target: Equatable {
public init(name: String,
platform: Platform,
product: Product,
productName: String,
bundleId: String,
infoPlist: InfoPlist? = nil,
entitlements: AbsolutePath? = nil,
Expand All @@ -52,6 +54,7 @@ public class Target: Equatable {
self.product = product
self.platform = platform
self.bundleId = bundleId
self.productName = productName
self.infoPlist = infoPlist
self.entitlements = entitlements
self.settings = settings
Expand Down Expand Up @@ -79,9 +82,9 @@ public class Target: Equatable {
var productNameWithExtension: String {
switch product {
case .staticLibrary, .dynamicLibrary:
return "lib\(name).\(product.xcodeValue.fileExtension!)"
return "lib\(productName).\(product.xcodeValue.fileExtension!)"
case _:
return "\(name).\(product.xcodeValue.fileExtension!)"
return "\(productName).\(product.xcodeValue.fileExtension!)"
}
}

Expand Down Expand Up @@ -125,6 +128,7 @@ public class Target: Equatable {
lhs.platform == rhs.platform &&
lhs.product == rhs.product &&
lhs.bundleId == rhs.bundleId &&
lhs.productName == rhs.productName &&
lhs.infoPlist == rhs.infoPlist &&
lhs.entitlements == rhs.entitlements &&
lhs.settings == rhs.settings &&
Expand Down
3 changes: 3 additions & 0 deletions Sources/TuistKit/Generator/GeneratorModelLoader.swift
Expand Up @@ -203,6 +203,8 @@ extension TuistGenerator.Target {
let product = TuistGenerator.Product.from(manifest: manifest.product)

let bundleId = manifest.bundleId
let productName = manifest.productName

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

let infoPlist = TuistGenerator.InfoPlist.from(manifest: manifest.infoPlist, path: path)
Expand Down Expand Up @@ -236,6 +238,7 @@ extension TuistGenerator.Target {
return TuistGenerator.Target(name: name,
platform: platform,
product: product,
productName: productName,
bundleId: bundleId,
infoPlist: infoPlist,
entitlements: entitlements,
Expand Down
1 change: 1 addition & 0 deletions Sources/TuistKit/Generator/ManifestTargetGenerator.swift
Expand Up @@ -26,6 +26,7 @@ class ManifestTargetGenerator: ManifestTargetGenerating {
return Target(name: "\(project)-Manifest",
platform: .macOS,
product: .staticFramework,
productName: "\(project)-Manifest",
bundleId: "io.tuist.manifests.${PRODUCT_NAME:rfc1034identifier}",
settings: settings,
sources: [(path: manifest, compilerFlags: nil)],
Expand Down
4 changes: 4 additions & 0 deletions Tests/ProjectDescriptionTests/TargetTests.swift
Expand Up @@ -9,6 +9,7 @@ final class TargetTests: XCTestCase {
let subject = Target(name: "name",
platform: .iOS,
product: .app,
productName: "product_name",
bundleId: "bundle_id",
infoPlist: "info.plist",
sources: "sources/*",
Expand Down Expand Up @@ -59,6 +60,7 @@ final class TargetTests: XCTestCase {
}
],
"product": "app",
"product_name": "product_name",
"sources": [
{
"glob": "sources\\/*"
Expand Down Expand Up @@ -128,6 +130,7 @@ final class TargetTests: XCTestCase {
let subject = Target(name: "name",
platform: .iOS,
product: .app,
productName: "product_name",
bundleId: "bundle_id",
infoPlist: "info.plist",
sources: FileList(globs: ["sources/*"]),
Expand Down Expand Up @@ -178,6 +181,7 @@ final class TargetTests: XCTestCase {
}
],
"product": "app",
"product_name": "product_name",
"sources": [
{
"glob": "sources\\/*"
Expand Down
Expand Up @@ -273,8 +273,8 @@ final class BuildPhaseGeneratorTests: XCTestCase {
func test_generateResourceBundle() throws {
// Given
let path = AbsolutePath("/path")
let bundle1 = Target.test(name: "Bundle1", product: .bundle)
let bundle2 = Target.test(name: "Bundle2", product: .bundle)
let bundle1 = Target.test(name: "Bundle1", product: .bundle, productName: "Bundle1")
let bundle2 = Target.test(name: "Bundle2", product: .bundle, productName: "Bundle2")
let app = Target.test(name: "App", product: .app)
let graph = Graph.create(project: .test(path: path),
dependencies: [
Expand Down
Expand Up @@ -64,7 +64,7 @@ final class TargetGeneratorTests: XCTestCase {
graph: graph)

// Then
XCTAssertEqual(generatedTarget.productName, "MyFramework")
XCTAssertEqual(generatedTarget.name, "MyFramework")
XCTAssertEqual(generatedTarget.productNameWithExtension(), "MyFramework.framework")
XCTAssertEqual(generatedTarget.productType, .framework)

Expand Down
Expand Up @@ -8,6 +8,7 @@ extension Target {
static func test(name: String = "Target",
platform: Platform = .iOS,
product: Product = .app,
productName: String? = nil,
bundleId: String = "com.test.bundle_id",
infoPlist: InfoPlist? = .file(path: AbsolutePath("/Info.plist")),
entitlements: AbsolutePath? = AbsolutePath("/Test.entitlements"),
Expand All @@ -23,6 +24,7 @@ extension Target {
return Target(name: name,
platform: platform,
product: product,
productName: productName ?? name,
bundleId: bundleId,
infoPlist: infoPlist,
entitlements: entitlements,
Expand All @@ -41,6 +43,7 @@ extension Target {
static func empty(name: String = "Target",
platform: Platform = .iOS,
product: Product = .app,
productName: String? = nil,
bundleId: String = "com.test.bundleId",
infoPlist: InfoPlist? = nil,
entitlements: AbsolutePath? = nil,
Expand All @@ -56,6 +59,7 @@ extension Target {
return Target(name: name,
platform: platform,
product: product,
productName: productName ?? name,
bundleId: bundleId,
infoPlist: infoPlist,
entitlements: entitlements,
Expand Down
Expand Up @@ -336,6 +336,7 @@ final class MultipleConfigurationsIntegrationTests: XCTestCase {
return Target(name: "AppTarget",
platform: .iOS,
product: .app,
productName: "AppTarget",
bundleId: "test.bundle",
settings: settings,
sources: [(path: pathTo("App/Sources/AppDelegate.swift"), compilerFlags: nil)],
Expand Down
Expand Up @@ -110,6 +110,7 @@ final class StableXcodeProjIntegrationTests: XCTestCase {
return Target(name: "AppTarget",
platform: .iOS,
product: .app,
productName: "AppTarget",
bundleId: "test.bundle",
settings: settings,
sources: createSources(),
Expand Down Expand Up @@ -186,6 +187,7 @@ final class StableXcodeProjIntegrationTests: XCTestCase {
return Target(name: name,
platform: .iOS,
product: .framework,
productName: name,
bundleId: "test.bundle.\(name)",
settings: nil,
sources: [],
Expand Down
Expand Up @@ -14,6 +14,7 @@ final class MockManifestTargetGenerator: ManifestTargetGenerating {
return Target(name: name,
platform: .iOS,
product: .framework,
productName: name,
bundleId: "io.tuist.testing",
infoPlist: nil,
filesGroup: .group(name: "Manifest"))
Expand Down
4 changes: 2 additions & 2 deletions fixtures/ios_app_with_frameworks/App/Project.swift
Expand Up @@ -13,8 +13,8 @@ let project = Project(name: "MainApp",
infoPlist: "Config/App-Info.plist",
sources: "Sources/**",
dependencies: [
.project(target: "Framework1", path: "../Framework1"),
.project(target: "Framework2", path: "../Framework2"),
.project(target: "Framework1-iOS", path: "../Framework1"),
.project(target: "Framework2-iOS", path: "../Framework2"),
]),
Target(name: "AppTests",
platform: .iOS,
Expand Down
19 changes: 15 additions & 4 deletions fixtures/ios_app_with_frameworks/Framework1/Project.swift
Expand Up @@ -2,23 +2,34 @@ import ProjectDescription

let project = Project(name: "Framework1",
targets: [
Target(name: "Framework1",
Target(name: "Framework1-iOS",
platform: .iOS,
product: .framework,
productName: "Framework1",
bundleId: "io.tuist.Framework1",
infoPlist: "Config/Framework1-Info.plist",
sources: "Sources/**",
dependencies: [
.project(target: "Framework2", path: "../Framework2"),
.project(target: "Framework2-iOS", path: "../Framework2"),
]),

Target(name: "Framework1-macOS",
platform: .macOS,
product: .framework,
productName: "Framework1",
bundleId: "io.tuist.Framework1",
infoPlist: "Config/Framework1-Info.plist",
sources: "Sources/**",
dependencies: [
.project(target: "Framework2-macOS", path: "../Framework2"),
]),
Target(name: "Framework1Tests",
platform: .iOS,
product: .unitTests,
productName: "Framework1Tests",
bundleId: "io.tuist.Framework1Tests",
infoPlist: "Config/Framework1Tests-Info.plist",
sources: "Tests/**",
dependencies: [
.target(name: "Framework1"),
.target(name: "Framework1-iOS"),
]),
])
17 changes: 14 additions & 3 deletions fixtures/ios_app_with_frameworks/Framework2/Project.swift
Expand Up @@ -2,24 +2,35 @@ import ProjectDescription

let project = Project(name: "Framework2",
targets: [
Target(name: "Framework2",
Target(name: "Framework2-iOS",
platform: .iOS,
product: .framework,
productName: "Framework2",
bundleId: "io.tuist.Framework2",
infoPlist: "Config/Framework2-Info.plist",
sources: "Sources/**",
headers: Headers(public: "Sources/Public/**",
private: "Sources/Private/**",
project: "Sources/Project/**"),
dependencies: []),

Target(name: "Framework2-macOS",
platform: .macOS,
product: .framework,
productName: "Framework2",
bundleId: "io.tuist.Framework2",
infoPlist: "Config/Framework2-Info.plist",
sources: "Sources/**",
headers: Headers(public: "Sources/Public/**",
private: "Sources/Private/**",
project: "Sources/Project/**"),
dependencies: []),
Target(name: "Framework2Tests",
platform: .iOS,
product: .unitTests,
bundleId: "io.tuist.Framework2Tests",
infoPlist: "Config/Framework2Tests-Info.plist",
sources: "Tests/**",
dependencies: [
.target(name: "Framework2"),
.target(name: "Framework2-iOS"),
]),
])

0 comments on commit 958e4d2

Please sign in to comment.