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

Support modifying Tuist's directories with environment variables #765

Merged
merged 2 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
Expand Up @@ -31,6 +31,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
- Add cache command https://github.com/tuist/tuist/pull/762 by @pepibumur.
- Utility to build xcframeworks https://github.com/tuist/tuist/pull/759 by @pepibumur.
- Add `CacheStoraging` protocol and a implementation for a local cache https://github.com/tuist/tuist/pull/763 by @pepibumur.
- Add support for changing the cache and versions directory using environment variables https://github.com/tuist/tuist/pull/765 by @pepibumur.

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions Sources/TuistSupport/Constants.swift
Expand Up @@ -16,6 +16,8 @@ public struct Constants {

public struct EnvironmentVariables {
public static let colouredOutput = "TUIST_COLOURED_OUTPUT"
public static let versionsDirectory = "TUIST_VERSIONS_DIRECTORY"
public static let cacheDirectory = "TUIST_CACHE_DIRECTORY"
}

public struct GoogleCloud {
Expand Down
22 changes: 11 additions & 11 deletions Sources/TuistSupport/Utils/Environment.swift
Expand Up @@ -11,9 +11,6 @@ public protocol Environmenting: AnyObject {
/// Returns the path to the settings.
var settingsPath: AbsolutePath { get }

/// Returns the directory where all the derived projects are generated.
var derivedProjectsDirectory: AbsolutePath { get }

/// Returns true if the output of Tuist should be coloured.
var shouldOutputBeColoured: Bool { get }

Expand Down Expand Up @@ -63,7 +60,7 @@ public class Environment: Environmenting {

/// Sets up the local environment.
private func setup() {
[directory, versionsDirectory, derivedProjectsDirectory].forEach {
[directory, versionsDirectory, cacheDirectory].forEach {
if !fileHandler.exists($0) {
// swiftlint:disable:next force_try
try! fileHandler.createFolder($0)
Expand All @@ -87,7 +84,11 @@ public class Environment: Environmenting {

/// Returns the directory where all the versions are.
public var versionsDirectory: AbsolutePath {
directory.appending(component: "Versions")
if let envVariable = ProcessInfo.processInfo.environment[Constants.EnvironmentVariables.versionsDirectory] {
return AbsolutePath(envVariable)
} else {
return directory.appending(component: "Versions")
}
}

/// Returns the directory where the xcframeworks are cached.
Expand All @@ -102,12 +103,11 @@ public class Environment: Environmenting {

/// Returns the cache directory
public var cacheDirectory: AbsolutePath {
directory.appending(component: "Cache")
}

/// Returns the directory where all the derived projects are generated.
public var derivedProjectsDirectory: AbsolutePath {
directory.appending(component: "DerivedProjects")
if let envVariable = ProcessInfo.processInfo.environment[Constants.EnvironmentVariables.cacheDirectory] {
return AbsolutePath(envVariable)
} else {
return directory.appending(component: "Cache")
}
}

/// Settings path.
Expand Down
4 changes: 0 additions & 4 deletions Sources/TuistSupportTesting/Utils/MockEnvironment.swift
Expand Up @@ -22,10 +22,6 @@ public class MockEnvironment: Environmenting {
directory.path.appending(component: "Versions")
}

public var derivedProjectsDirectory: AbsolutePath {
directory.path.appending(component: "DerivedProjects")
}

public var settingsPath: AbsolutePath {
directory.path.appending(component: "settings.json")
}
Expand Down