Skip to content

Commit

Permalink
Move useBinaries to build option
Browse files Browse the repository at this point in the history
  • Loading branch information
chuganzy committed Feb 3, 2018
1 parent 9f518dc commit 4dbae49
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 70 deletions.
6 changes: 5 additions & 1 deletion Source/CarthageKit/BuildOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ public struct BuildOptions {
/// Rebuild even if cached builds exist.
public var cacheBuilds: Bool

public init(configuration: String, platforms: Set<Platform> = [], toolchain: String? = nil, derivedDataPath: String? = nil, cacheBuilds: Bool = true) {
public var useBinaries: Bool

public init(configuration: String, platforms: Set<Platform> = [], toolchain: String? = nil,
derivedDataPath: String? = nil, cacheBuilds: Bool = true, useBinaries: Bool = true) {
self.configuration = configuration
self.platforms = platforms
self.toolchain = toolchain
self.derivedDataPath = derivedDataPath
self.cacheBuilds = cacheBuilds
self.useBinaries = useBinaries
}
}
77 changes: 33 additions & 44 deletions Source/CarthageKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ public final class Project { // swiftlint:disable:this type_body_length
/// working directories.
public var useSubmodules = false

/// Whether to download binaries for dependencies, or just check out their
/// repositories.
public var useBinaries = false

/// Sends each event that occurs to a project underneath the receiver (or
/// the receiver itself).
public let projectEvents: Signal<ProjectEvent, NoError>
Expand Down Expand Up @@ -579,49 +575,42 @@ public final class Project { // swiftlint:disable:this type_body_length
///
/// Sends a boolean indicating whether binaries were installed.
private func installBinaries(for dependency: Dependency, pinnedVersion: PinnedVersion, toolchain: String?) -> SignalProducer<Bool, CarthageError> {
return SignalProducer<Bool, CarthageError>(value: self.useBinaries)
.flatMap(.merge) { useBinaries -> SignalProducer<Bool, CarthageError> in
if !useBinaries {
return SignalProducer(value: false)
}

let checkoutDirectoryURL = self.directoryURL.appendingPathComponent(dependency.relativePath, isDirectory: true)

switch dependency {
case let .gitHub(server, repository):
let client = Client(server: server)
return self.downloadMatchingBinaries(for: dependency, pinnedVersion: pinnedVersion, fromRepository: repository, client: client)
.flatMapError { error -> SignalProducer<URL, CarthageError> in
if !client.isAuthenticated {
return SignalProducer(error: error)
}
return self.downloadMatchingBinaries(
for: dependency,
pinnedVersion: pinnedVersion,
fromRepository: repository,
client: Client(server: server, isAuthenticated: false)
)
}
.flatMap(.concat) {
return self.unarchiveAndCopyBinaryFrameworks(zipFile: $0, projectName: dependency.name, pinnedVersion: pinnedVersion, toolchain: toolchain)
.on(value: { _ in
// Trash the checkouts folder when we've successfully copied binaries, to avoid building unnecessarily
_ = try? FileManager.default.trashItem(at: checkoutDirectoryURL, resultingItemURL: nil)
})
}
.flatMap(.concat) { self.removeItem(at: $0) }
.map { true }
.flatMapError { error in
self._projectEventsObserver.send(value: .skippedInstallingBinaries(dependency: dependency, error: error))
return SignalProducer(value: false)
}
.concat(value: false)
.take(first: 1)
let checkoutDirectoryURL = self.directoryURL.appendingPathComponent(dependency.relativePath, isDirectory: true)

case .git, .binary:
switch dependency {
case let .gitHub(server, repository):
let client = Client(server: server)
return self.downloadMatchingBinaries(for: dependency, pinnedVersion: pinnedVersion, fromRepository: repository, client: client)
.flatMapError { error -> SignalProducer<URL, CarthageError> in
if !client.isAuthenticated {
return SignalProducer(error: error)
}
return self.downloadMatchingBinaries(
for: dependency,
pinnedVersion: pinnedVersion,
fromRepository: repository,
client: Client(server: server, isAuthenticated: false)
)
}
.flatMap(.concat) {
return self.unarchiveAndCopyBinaryFrameworks(zipFile: $0, projectName: dependency.name, pinnedVersion: pinnedVersion, toolchain: toolchain)
.on(value: { _ in
// Trash the checkouts folder when we've successfully copied binaries, to avoid building unnecessarily
_ = try? FileManager.default.trashItem(at: checkoutDirectoryURL, resultingItemURL: nil)
})
}
.flatMap(.concat) { self.removeItem(at: $0) }
.map { true }
.flatMapError { error in
self._projectEventsObserver.send(value: .skippedInstallingBinaries(dependency: dependency, error: error))
return SignalProducer(value: false)
}
}
.concat(value: false)
.take(first: 1)

case .git, .binary:
return SignalProducer(value: false)
}
}

/// Downloads any binaries and debug symbols that may be able to be used
Expand Down
1 change: 1 addition & 0 deletions Source/carthage/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extension BuildOptions: OptionsProtocol {
<*> mode <| Option<String?>(key: "toolchain", defaultValue: nil, usage: "the toolchain to build with")
<*> mode <| Option<String?>(key: "derived-data", defaultValue: nil, usage: "path to the custom derived data folder")
<*> mode <| Option(key: "cache-builds", defaultValue: false, usage: "use cached builds when possible")
<*> mode <| Option(key: "use-binaries", defaultValue: true, usage: "use cached builds when possible")
}
}

Expand Down
16 changes: 2 additions & 14 deletions Source/carthage/Checkout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,31 @@ public struct CheckoutCommand: CommandProtocol {
public struct Options: OptionsProtocol {
public let useSSH: Bool
public let useSubmodules: Bool
public let useBinaries: Bool
public let colorOptions: ColorOptions
public let directoryPath: String
public let dependenciesToCheckout: [String]?

private init(useSSH: Bool,
useSubmodules: Bool,
useBinaries: Bool,
colorOptions: ColorOptions,
directoryPath: String,
dependenciesToCheckout: [String]?
) {
// Disable binary downloads when using submodules.
// See https://github.com/Carthage/Carthage/issues/419.
let shouldUseBinaries = useSubmodules ? false : useBinaries

self.useSSH = useSSH
self.useSubmodules = useSubmodules
self.useBinaries = shouldUseBinaries
self.colorOptions = colorOptions
self.directoryPath = directoryPath
self.dependenciesToCheckout = dependenciesToCheckout
}

public static func evaluate(_ mode: CommandMode) -> Result<Options, CommandantError<CarthageError>> {
return evaluate(mode, useBinariesAddendum: "", dependenciesUsage: "the dependency names to checkout")
return evaluate(mode, dependenciesUsage: "the dependency names to checkout")
}

public static func evaluate(_ mode: CommandMode, useBinariesAddendum: String, dependenciesUsage: String) -> Result<Options, CommandantError<CarthageError>> {
var useBinariesUsage = "check out dependency repositories even when prebuilt frameworks exist, disabled if --use-submodules option is present"
useBinariesUsage += useBinariesAddendum

public static func evaluate(_ mode: CommandMode, dependenciesUsage: String) -> Result<Options, CommandantError<CarthageError>> {
return curry(self.init)
<*> mode <| Option(key: "use-ssh", defaultValue: false, usage: "use SSH for downloading GitHub repositories")
<*> mode <| Option(key: "use-submodules", defaultValue: false, usage: "add dependencies as Git submodules")
<*> mode <| Option(key: "use-binaries", defaultValue: true, usage: useBinariesUsage)
<*> ColorOptions.evaluate(mode)
<*> mode <| Option(key: "project-directory", defaultValue: FileManager.default.currentDirectoryPath, usage: "the directory containing the Carthage project")
<*> (mode <| Argument(defaultValue: [], usage: dependenciesUsage)).map { $0.isEmpty ? nil : $0 }
Expand All @@ -58,7 +47,6 @@ public struct CheckoutCommand: CommandProtocol {
let project = Project(directoryURL: directoryURL)
project.preferHTTPS = !self.useSSH
project.useSubmodules = self.useSubmodules
project.useBinaries = self.useBinaries

var eventSink = ProjectEventSink(colorOptions: colorOptions)
project.projectEvents.observeValues { eventSink.put($0) }
Expand Down
12 changes: 1 addition & 11 deletions Source/carthage/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public struct UpdateCommand: CommandProtocol {
public static func evaluate(_ mode: CommandMode) -> Result<Options, CommandantError<CarthageError>> {
let buildDescription = "skip the building of dependencies after updating\n(ignored if --no-checkout option is present)"

let binariesAddendum = "\n(ignored if --no-build or --toolchain option is present)"
let dependenciesUsage = "the dependency names to update, checkout and build"

return curry(self.init)
Expand All @@ -73,22 +72,13 @@ public struct UpdateCommand: CommandProtocol {
<*> mode <| Option(key: "log-path", defaultValue: nil, usage: "path to the xcode build output. A temporary file is used by default")
<*> mode <| Option(key: "new-resolver", defaultValue: false, usage: "use the new resolver codeline when calculating dependencies. Default is false")
<*> BuildOptions.evaluate(mode, addendum: "\n(ignored if --no-build option is present)")
<*> CheckoutCommand.Options.evaluate(mode, useBinariesAddendum: binariesAddendum, dependenciesUsage: dependenciesUsage)
<*> CheckoutCommand.Options.evaluate(mode, dependenciesUsage: dependenciesUsage)
}

/// Attempts to load the project referenced by the options, and configure it
/// accordingly.
public func loadProject() -> SignalProducer<Project, CarthageError> {
return checkoutOptions.loadProject()
.on(value: { project in
// Never check out binaries if
// 1. we're skipping the build step, or
// 2. `--toolchain` option is given
// because that means users may need the repository checkout.
if !self.buildAfterUpdate || self.buildOptions.toolchain != nil {
project.useBinaries = false
}
})
}
}

Expand Down

0 comments on commit 4dbae49

Please sign in to comment.