Skip to content

Commit

Permalink
Added ability to name the executable target in schemes. (#866)
Browse files Browse the repository at this point in the history
```
schemes:
  MyScheme:
    build:
      executable: MyExecutable
      targets:
      ...
```

Co-authored-by: Igor Ranieri Elland <igor.ranieri@de.bosch.com>
  • Loading branch information
elland and Igor Ranieri Elland authored May 20, 2020
1 parent 474d8f6 commit 92aaebb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
- Add an ability to set an order of groups with `options.groupOrdering` [#613](https://github.com/yonaskolb/XcodeGen/pull/613) @Beniamiiin
- Add `staticBinary` linkType for Carthage dependency [#847](https://github.com/yonaskolb/XcodeGen/pull/847) @d-date
- Add the ability to output a dependency graph in graphviz format [#852](https://github.com/yonaskolb/XcodeGen/pull/852) @jeffctown
- Adds uncluttering the project manifest dumped to YAML from empty values [#858](https://github.com/yonaskolb/XcodeGen/pull/858) @paciej00

- Adds uncluttering the project manifest dumped to YAML from empty values [#858](https://github.com/yonaskolb/XcodeGen/pull/858) @paciej00
- Added ability to name the executable target when declaring schemes. [#866](https://github.com/yonaskolb/XcodeGen/pull/866) @elland


#### Fixed
Expand Down
5 changes: 5 additions & 0 deletions Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,23 @@ public struct Scheme: Equatable {
public static let parallelizeBuildDefault = true
public static let buildImplicitDependenciesDefault = true

public var executableName: String?
public var targets: [BuildTarget]
public var parallelizeBuild: Bool
public var buildImplicitDependencies: Bool
public var preActions: [ExecutionAction]
public var postActions: [ExecutionAction]

public init(
targets: [BuildTarget],
executableName: String? = nil,
parallelizeBuild: Bool = parallelizeBuildDefault,
buildImplicitDependencies: Bool = buildImplicitDependenciesDefault,
preActions: [ExecutionAction] = [],
postActions: [ExecutionAction] = []
) {
self.targets = targets
self.executableName = executableName
self.parallelizeBuild = parallelizeBuild
self.buildImplicitDependencies = buildImplicitDependencies
self.preActions = preActions
Expand Down Expand Up @@ -605,6 +609,7 @@ extension Scheme.Build: JSONObjectConvertible {
targets.append(Scheme.BuildTarget(target: target, buildTypes: buildTypes))
}
self.targets = targets.sorted { $0.target.name < $1.target.name }
self.executableName = jsonDictionary.json(atKeyPath: "executable")
preActions = try jsonDictionary.json(atKeyPath: "preActions")?.map(Scheme.ExecutionAction.init) ?? []
postActions = try jsonDictionary.json(atKeyPath: "postActions")?.map(Scheme.ExecutionAction.init) ?? []
parallelizeBuild = jsonDictionary.json(atKeyPath: "parallelizeBuild") ?? Scheme.Build.parallelizeBuildDefault
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ public class PBXProjGenerator {
var packageDependencies: [XCSwiftPackageProductDependency] = []
var extensions: [PBXBuildFile] = []
var carthageFrameworksToEmbed: [String] = []
var localPackageReferences: [String] = project.packages.compactMap { $0.value.isLocal ? $0.key : nil }
let localPackageReferences: [String] = project.packages.compactMap { $0.value.isLocal ? $0.key : nil }

let targetDependencies = (target.transitivelyLinkDependencies ?? project.options.transitivelyLinkDependencies) ?
getAllDependenciesPlusTransitiveNeedingEmbedding(target: target) : target.dependencies
Expand Down
11 changes: 9 additions & 2 deletions Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,17 @@ public class SchemeGenerator {
return XCScheme.ExecutionAction(scriptText: action.script, title: action.name, environmentBuildable: environmentBuildable)
}

let schemeTarget = target ?? project.getTarget(scheme.build.targets.first!.target.name)
let schemeTarget: Target?

if let targetName = scheme.build.executableName {
schemeTarget = project.getTarget(targetName)
} else {
schemeTarget = target ?? project.getTarget(scheme.build.targets.first!.target.name)
}

let shouldExecuteOnLaunch = schemeTarget?.shouldExecuteOnLaunch == true

let buildableReference = buildActionEntries.first!.buildableReference
let buildableReference = buildActionEntries.first(where: { $0.buildableReference.blueprintName == schemeTarget?.name })?.buildableReference ?? buildActionEntries.first!.buildableReference
let runnables = makeProductRunnables(for: schemeTarget, buildableReference: buildableReference)

let buildAction = XCScheme.BuildAction(
Expand Down

0 comments on commit 92aaebb

Please sign in to comment.