Skip to content

Commit

Permalink
Use the Scheme type
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Oct 3, 2017
1 parent 606d93d commit 21dbcda
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Source/CarthageKit/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public struct BuildSettings {
///
/// If an SDK is unrecognized or could not be determined, an error will be
/// sent on the returned signal.
public static func SDKsForScheme(_ scheme: String, inProject project: ProjectLocator) -> SignalProducer<SDK, CarthageError> {
public static func SDKsForScheme(_ scheme: Scheme, inProject project: ProjectLocator) -> SignalProducer<SDK, CarthageError> {
return load(with: BuildArguments(project: project, scheme: scheme))
.take(first: 1)
.flatMap(.merge) { $0.buildSDKs }
Expand Down
7 changes: 5 additions & 2 deletions Source/CarthageKit/XCDBLDExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension ProjectLocator {
}

/// Sends each scheme found in the receiver.
public func schemes() -> SignalProducer<String, CarthageError> {
public func schemes() -> SignalProducer<Scheme, CarthageError> {
let task = xcodebuildTask("-list", BuildArguments(project: self))

return task.launch()
Expand Down Expand Up @@ -86,7 +86,10 @@ extension ProjectLocator {
.skip { line in !line.hasSuffix("Schemes:") }
.skip(first: 1)
.take { line in !line.isEmpty }
.map { line in line.trimmingCharacters(in: .whitespaces) }
.map { line in
let trimmed = line.trimmingCharacters(in: .whitespaces)
return Scheme(trimmed)
}
}
}

Expand Down
36 changes: 18 additions & 18 deletions Source/CarthageKit/Xcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ public func buildableSchemesInDirectory(
_ directoryURL: URL,
withConfiguration configuration: String,
forPlatforms platforms: Set<Platform> = []
) -> SignalProducer<(ProjectLocator, [String]), CarthageError> {
) -> SignalProducer<(ProjectLocator, [Scheme]), CarthageError> {
precondition(directoryURL.isFileURL)

return ProjectLocator
.locate(in: directoryURL)
.flatMap(.concat) { project -> SignalProducer<(ProjectLocator, [String]), CarthageError> in
.flatMap(.concat) { project -> SignalProducer<(ProjectLocator, [Scheme]), CarthageError> in
return project
.schemes()
.flatMap(.merge) { scheme -> SignalProducer<String, CarthageError> in
.flatMap(.merge) { scheme -> SignalProducer<Scheme, CarthageError> in
let buildArguments = BuildArguments(project: project, scheme: scheme, configuration: configuration)

return shouldBuildScheme(buildArguments, platforms)
Expand All @@ -136,17 +136,17 @@ public func buildableSchemesInDirectory(

/// Sends pairs of a scheme and a project, the scheme actually resides in
/// the project.
public func schemesInProjects(_ projects: [(ProjectLocator, [String])]) -> SignalProducer<[(String, ProjectLocator)], CarthageError> {
return SignalProducer<(ProjectLocator, [String]), CarthageError>(projects)
.map { (project: ProjectLocator, schemes: [String]) in
public func schemesInProjects(_ projects: [(ProjectLocator, [Scheme])]) -> SignalProducer<[(Scheme, ProjectLocator)], CarthageError> {
return SignalProducer<(ProjectLocator, [Scheme]), CarthageError>(projects)
.map { (project: ProjectLocator, schemes: [Scheme]) in
// Only look for schemes that actually reside in the project
let containedSchemes = schemes.filter { (scheme: String) -> Bool in
let containedSchemes = schemes.filter { scheme -> Bool in
let schemePath = project.fileURL.appendingPathComponent("xcshareddata/xcschemes/\(scheme).xcscheme").path
return FileManager.default.fileExists(atPath: schemePath)
}
return (project, containedSchemes)
}
.filter { (project: ProjectLocator, schemes: [String]) in
.filter { (project: ProjectLocator, schemes: [Scheme]) in
switch project {
case .projectFile where !schemes.isEmpty:
return true
Expand All @@ -156,7 +156,7 @@ public func schemesInProjects(_ projects: [(ProjectLocator, [String])]) -> Signa
}
}
.flatMap(.concat) { project, schemes in
return SignalProducer<(String, ProjectLocator), CarthageError>(schemes.map { ($0, project) })
return SignalProducer<(Scheme, ProjectLocator), CarthageError>(schemes.map { ($0, project) })
}
.collect()
}
Expand Down Expand Up @@ -396,14 +396,14 @@ private func mergeBuildProducts(
}

/// A callback function used to determine whether or not an SDK should be built
public typealias SDKFilterCallback = (_ sdks: [SDK], _ scheme: String, _ configuration: String, _ project: ProjectLocator) -> Result<[SDK], CarthageError>
public typealias SDKFilterCallback = (_ sdks: [SDK], _ scheme: Scheme, _ configuration: String, _ project: ProjectLocator) -> Result<[SDK], CarthageError>

/// Builds one scheme of the given project, for all supported SDKs.
///
/// Returns a signal of all standard output from `xcodebuild`, and a signal
/// which will send the URL to each product successfully built.
public func buildScheme( // swiftlint:disable:this function_body_length cyclomatic_complexity
_ scheme: String,
_ scheme: Scheme,
withOptions options: BuildOptions,
inProject project: ProjectLocator,
workingDirectoryURL: URL,
Expand Down Expand Up @@ -684,7 +684,7 @@ public func createDebugInformation(_ builtProductURL: URL) -> SignalProducer<Tas
///
/// A producer of this type will send the project and scheme name when building
/// begins, then complete or error when building terminates.
public typealias BuildSchemeProducer = SignalProducer<TaskEvent<(ProjectLocator, String)>, CarthageError>
public typealias BuildSchemeProducer = SignalProducer<TaskEvent<(ProjectLocator, Scheme)>, CarthageError>

/// Attempts to build the dependency, then places its build product into the
/// root directory given.
Expand Down Expand Up @@ -780,17 +780,17 @@ public func buildInDirectory(
// Allow dependencies which have no projects, not to error out with
// `.noSharedFrameworkSchemes`.
.filter { projects in !projects.isEmpty }
.flatMap(.merge) { (projects: [(ProjectLocator, [String])]) -> SignalProducer<(String, ProjectLocator), CarthageError> in
.flatMap(.merge) { (projects: [(ProjectLocator, [Scheme])]) -> SignalProducer<(Scheme, ProjectLocator), CarthageError> in
return schemesInProjects(projects)
.flatMap(.merge) { (schemes: [(String, ProjectLocator)]) -> SignalProducer<(String, ProjectLocator), CarthageError> in
.flatMap(.merge) { (schemes: [(Scheme, ProjectLocator)]) -> SignalProducer<(Scheme, ProjectLocator), CarthageError> in
if !schemes.isEmpty {
return .init(schemes)
} else {
return .init(error: .noSharedFrameworkSchemes(.git(GitURL(directoryURL.path)), options.platforms))
}
}
}
.flatMap(.merge) { scheme, project -> SignalProducer<(String, ProjectLocator), CarthageError> in
.flatMap(.merge) { scheme, project -> SignalProducer<(Scheme, ProjectLocator), CarthageError> in
return locator
// This scheduler hop is required to avoid disallowed recursive signals.
// See https://github.com/ReactiveCocoa/ReactiveCocoa/pull/2042.
Expand All @@ -811,7 +811,7 @@ public func buildInDirectory(
.take(first: 1)
.map { project, _ in (scheme, project) }
}
.flatMap(.concat) { (scheme: String, project: ProjectLocator) -> SignalProducer<TaskEvent<URL>, CarthageError> in
.flatMap(.concat) { (scheme: Scheme, project: ProjectLocator) -> SignalProducer<TaskEvent<URL>, CarthageError> in
let initialValue = (project, scheme)

let wrappedSDKFilter: SDKFilterCallback = { sdks, scheme, configuration, project in
Expand Down Expand Up @@ -851,8 +851,8 @@ public func buildInDirectory(
// Discard any Success values, since we want to
// use our initial value instead of waiting for
// completion.
.map { taskEvent -> TaskEvent<(ProjectLocator, String)> in
let ignoredValue = (ProjectLocator.workspace(URL(string: ".")!), "")
.map { taskEvent -> TaskEvent<(ProjectLocator, Scheme)> in
let ignoredValue = (ProjectLocator.workspace(URL(string: ".")!), Scheme(""))
return taskEvent.map { _ in ignoredValue }
}
.filter { taskEvent in
Expand Down
14 changes: 10 additions & 4 deletions Source/XCDBLD/BuildArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public struct BuildArguments {
public let project: ProjectLocator

/// The scheme to build in the project.
public var scheme: String?
public var scheme: Scheme?

/// The configuration to use when building the project.
public var configuration: String?
Expand All @@ -56,8 +56,14 @@ public struct BuildArguments {
/// The build setting whether full bitcode should be embedded in the binary.
public var bitcodeGenerationMode: BitcodeGenerationMode?

public init(project: ProjectLocator, scheme: String? = nil, configuration: String? = nil,
derivedDataPath: String? = nil, sdk: SDK? = nil, toolchain: String? = nil) {
public init(
project: ProjectLocator,
scheme: Scheme? = nil,
configuration: String? = nil,
derivedDataPath: String? = nil,
sdk: SDK? = nil,
toolchain: String? = nil
) {
self.project = project
self.scheme = scheme
self.configuration = configuration
Expand All @@ -79,7 +85,7 @@ public struct BuildArguments {
}

if let scheme = scheme {
args += [ "-scheme", scheme ]
args += [ "-scheme", scheme.name ]
}

if let configuration = configuration {
Expand Down
4 changes: 2 additions & 2 deletions Source/carthage/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public struct ArchiveCommand: CommandProtocol {
let directoryURL = URL(fileURLWithPath: options.directoryPath, isDirectory: true)
frameworks = buildableSchemesInDirectory(directoryURL, withConfiguration: "Release", forPlatforms: [])
.collect()
.flatMap(.merge) { projects -> SignalProducer<(String, ProjectLocator), CarthageError> in
.flatMap(.merge) { projects -> SignalProducer<(Scheme, ProjectLocator), CarthageError> in
return schemesInProjects(projects)
.flatMap(.merge) { (schemes: [(String, ProjectLocator)]) -> SignalProducer<(String, ProjectLocator), CarthageError> in
.flatMap(.merge) { (schemes: [(Scheme, ProjectLocator)]) -> SignalProducer<(Scheme, ProjectLocator), CarthageError> in
if !schemes.isEmpty {
return .init(schemes)
} else {
Expand Down
2 changes: 1 addition & 1 deletion Source/carthage/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public struct BuildCommand: CommandProtocol {
stderrHandle.write(data)

case let .success(project, scheme):
carthage.println(formatting.bullets + "Building scheme " + formatting.quote(scheme) + " in " + formatting.projectName(project.description))
carthage.println(formatting.bullets + "Building scheme " + formatting.quote(scheme.name) + " in " + formatting.projectName(project.description))
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CarthageKitTests/ProjectSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProjectSpec: QuickSpec {
.single()!
expect(result.error).to(beNil())

return result.value!
return result.value!.map { $0.name }
}

beforeEach {
Expand Down
2 changes: 1 addition & 1 deletion Tests/XCDBLDTests/BuildArgumentsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BuildArgumentsSpec: QuickSpec {
itCreatesBuildArguments("has a default set of arguments", arguments: []) { _ in }

itCreatesBuildArguments("includes the scheme if one is given", arguments: ["-scheme", "exampleScheme"]) { subject in
subject.scheme = "exampleScheme"
subject.scheme = Scheme("exampleScheme")
}

itCreatesBuildArguments("includes the configuration if one is given", arguments: ["-configuration", "exampleConfiguration"]) { subject in
Expand Down

0 comments on commit 21dbcda

Please sign in to comment.