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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache command #762

Merged
merged 3 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
- Make scheme generation methods more generic by @adamkhazi @kwridan.
- `SimulatorController` with method to fetch the runtimes https://github.com/tuist/tuist/pull/746 by @pepibumur.
- Add RxSwift as a dependency of `TuistKit` https://github.com/tuist/tuist/pull/760 by @pepibumur.
- Add cache command https://github.com/tuist/tuist/pull/762 by @pepibumur.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
.package(url: "https://github.com/tuist/XcodeProj", .upToNextMajor(from: "7.5.0")),
.package(url: "https://github.com/apple/swift-package-manager", .upToNextMajor(from: "0.5.0")),
.package(url: "https://github.com/IBM-Swift/BlueSignals", .upToNextMajor(from: "1.0.21")),
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.1"))
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.1")),
pepicrft marked this conversation as resolved.
Show resolved Hide resolved
],
targets: [
.target(
Expand Down
6 changes: 3 additions & 3 deletions Sources/TuistCore/Graph/Graph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ extension Graph {

// swiftlint:disable:next line_length
func frameworkUsesDynamicLinking(frameworkMetadataProvider: FrameworkMetadataProviding = FrameworkMetadataProvider()) -> (_ frameworkNode: PrecompiledNode) -> Bool { { frameworkNode in
let isDynamicLink = try? frameworkMetadataProvider.linking(precompiled: frameworkNode) == .dynamic
return isDynamicLink ?? false
}
let isDynamicLink = try? frameworkMetadataProvider.linking(precompiled: frameworkNode) == .dynamic
return isDynamicLink ?? false
}
}
}

Expand Down
52 changes: 52 additions & 0 deletions Sources/TuistKit/Commands/CacheCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Basic
import Foundation
import SPMUtility
import TuistSupport

/// Command to cache frameworks as .xcframeworks and speed up your and others' build times.
class CacheCommand: NSObject, Command {
// MARK: - Attributes

/// Name of the command.
static let command = "cache"

/// Description of the command.
static let overview = "Cache frameworks as .xcframeworks to speed up build times in generated projects"

/// Path to the project directory.
let pathArgument: OptionArgument<String>

// MARK: - Init

/// Initializes the command with the CLI parser.
///
/// - Parameter parser: CLI parser where the command should register itself.
public required init(parser: ArgumentParser) {
let subParser = parser.add(subparser: CacheCommand.command, overview: CacheCommand.overview)
pathArgument = subParser.add(option: "--path",
shortName: "-p",
kind: String.self,
usage: "The path to the directory that contains the project whose frameworks will be cached.",
completion: .filename)
}

/// Runs the command using the result from parsing the command line arguments.
///
/// - Throws: An error if the the configuration of the environment fails.
func run(with _: ArgumentParser.Result) throws {
let twitterHandle = "@\(Constants.twitterHandle)"
Printer.shared.print("This feature is being worked on. Follow us on Twitter \(.bold(.raw(twitterHandle))) or join our Slack channel to stay up to date: \(.bold(.raw(Constants.joinSlackURL)))")
}

/// Parses the arguments and returns the path to the directory where
/// the up command should be ran.
///
/// - Parameter arguments: Result from parsing the command line arguments.
/// - Returns: Path to be used for the up command.
private func path(arguments: ArgumentParser.Result) -> AbsolutePath {
guard let path = arguments.get(pathArgument) else {
return FileHandler.shared.currentPath
}
return AbsolutePath(path, relativeTo: FileHandler.shared.currentPath)
}
}
1 change: 1 addition & 0 deletions Sources/TuistKit/Commands/CommandRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public final class CommandRegistry {
register(command: UpCommand.self)
register(command: GraphCommand.self)
register(command: EditCommand.self)
register(command: CacheCommand.self)
register(rawCommand: BuildCommand.self)
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/TuistSupport/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public struct Constants {
public static let trueValues: [String] = ["1", "true", "TRUE", "yes", "YES"]
public static let tuistDirectoryName: String = "Tuist"
public static let helpersDirectoryName: String = "ProjectDescriptionHelpers"
public static let twitterHandle: String = "tuistio"
public static let joinSlackURL: String = "https://slack.tuist.io/"

public struct EnvironmentVariables {
public static let colouredOutput = "TUIST_COLOURED_OUTPUT"
Expand Down
33 changes: 33 additions & 0 deletions Tests/TuistKitTests/Commands/CacheCommandTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Basic
import Foundation
import SPMUtility
import TuistSupport
import XCTest

@testable import TuistKit
@testable import TuistSupportTesting

final class CacheCommandTests: TuistUnitTestCase {
var subject: CacheCommand!
var parser: ArgumentParser!

override func setUp() {
super.setUp()
parser = ArgumentParser.test()
subject = CacheCommand(parser: parser)
}

override func tearDown() {
parser = nil
subject = nil
super.tearDown()
}

func test_name() {
XCTAssertEqual(CacheCommand.command, "cache")
}

func test_overview() {
XCTAssertEqual(CacheCommand.overview, "Cache frameworks as .xcframeworks to speed up build times in generated projects")
}
}