From c750b0824f39fe23b85258eca77e36f93da9a0da Mon Sep 17 00:00:00 2001 From: Vyacheslav Khorkov Date: Sat, 18 Nov 2023 15:27:29 +0500 Subject: [PATCH 1/4] Rename feature toggles service to environment --- Sources/Rugby/Commands/Utils/Env.swift | 2 +- .../Environment.swift} | 5 +++-- .../Core/RunnableCommand/RunnableCommand.swift | 2 +- Sources/Rugby/Rugby.swift | 5 +++-- .../RugbyFoundation/Core/Build/BuildManager.swift | 8 ++++---- .../{IFeatureToggles.swift => IEnvironment.swift} | 6 +++--- .../Vault/Commands/Build/Vault+Build.swift | 2 +- Sources/RugbyFoundation/Vault/Vault.swift | 14 +++++++------- 8 files changed, 23 insertions(+), 21 deletions(-) rename Sources/Rugby/Core/Dependencies/{FeatureToggles/FeatureToggles.swift => Environment/Environment.swift} (92%) rename Sources/RugbyFoundation/Core/Common/{IFeatureToggles.swift => IEnvironment.swift} (63%) diff --git a/Sources/Rugby/Commands/Utils/Env.swift b/Sources/Rugby/Commands/Utils/Env.swift index 9ddf10a5..b3465b37 100644 --- a/Sources/Rugby/Commands/Utils/Env.swift +++ b/Sources/Rugby/Commands/Utils/Env.swift @@ -11,7 +11,7 @@ struct Env: AsyncParsableCommand { func run() async throws { try await dependencies.environmentCollector.env( rugbyVersion: Rugby.configuration.version, - rugbyEnvironment: dependencies.featureToggles.all + rugbyEnvironment: dependencies.env.all ).forEach { print($0) } } } diff --git a/Sources/Rugby/Core/Dependencies/FeatureToggles/FeatureToggles.swift b/Sources/Rugby/Core/Dependencies/Environment/Environment.swift similarity index 92% rename from Sources/Rugby/Core/Dependencies/FeatureToggles/FeatureToggles.swift rename to Sources/Rugby/Core/Dependencies/Environment/Environment.swift index 4cd0cba1..7ea60ee2 100644 --- a/Sources/Rugby/Core/Dependencies/FeatureToggles/FeatureToggles.swift +++ b/Sources/Rugby/Core/Dependencies/Environment/Environment.swift @@ -1,14 +1,15 @@ +import Fish import Foundation import RugbyFoundation -final class FeatureToggles { +final class Environment { // swiftlint:disable identifier_name private let RUGBY_KEEP_HASH_YAMLS = "RUGBY_KEEP_HASH_YAMLS" private let RUGBY_PRINT_MISSING_BINARIES = "RUGBY_PRINT_MISSING_BINARIES" // swiftlint:enable identifier_name } -extension FeatureToggles: IFeatureToggles { +extension Environment: IEnvironment { var all: [String: String] { [ RUGBY_KEEP_HASH_YAMLS: keepHashYamls.yesNo, diff --git a/Sources/Rugby/Core/RunnableCommand/RunnableCommand.swift b/Sources/Rugby/Core/RunnableCommand/RunnableCommand.swift index 25e995c0..04ecaf6e 100644 --- a/Sources/Rugby/Core/RunnableCommand/RunnableCommand.swift +++ b/Sources/Rugby/Core/RunnableCommand/RunnableCommand.swift @@ -29,7 +29,7 @@ extension RunnableCommand { try await dependencies.environmentCollector.write( rugbyVersion: Rugby.configuration.version, command: self, - rugbyEnvironment: dependencies.featureToggles.all + rugbyEnvironment: dependencies.env.all ) let name = Self.configuration.commandName?.capitalized ?? "Unknown" diff --git a/Sources/Rugby/Rugby.swift b/Sources/Rugby/Rugby.swift index 5eb585bc..6346df96 100644 --- a/Sources/Rugby/Rugby.swift +++ b/Sources/Rugby/Rugby.swift @@ -70,8 +70,9 @@ struct Rugby: AsyncParsableCommand { // MARK: - Private private static func prepareDependencies() { - Vault.setupShared( - featureToggles: FeatureToggles(), + let env = Environment() + return Vault.setupShared( + env: env, logger: Logger(clock: Clock()), router: Router( workingDirectory: Folder.current, diff --git a/Sources/RugbyFoundation/Core/Build/BuildManager.swift b/Sources/RugbyFoundation/Core/Build/BuildManager.swift index b1920325..904b93bb 100644 --- a/Sources/RugbyFoundation/Core/Build/BuildManager.swift +++ b/Sources/RugbyFoundation/Core/Build/BuildManager.swift @@ -43,7 +43,7 @@ final class BuildManager: Loggable { private let useBinariesManager: IUseBinariesManager private let binariesCleaner: BinariesCleaner private let environmentCollector: IEnvironmentCollector - private let featureToggles: IFeatureToggles + private let env: IEnvironment private let targetTreePainter: ITargetTreePainter init(logger: ILogger, @@ -59,7 +59,7 @@ final class BuildManager: Loggable { useBinariesManager: IUseBinariesManager, binariesCleaner: BinariesCleaner, environmentCollector: IEnvironmentCollector, - featureToggles: IFeatureToggles, + env: IEnvironment, targetTreePainter: ITargetTreePainter) { self.logger = logger self.buildTargetsManager = buildTargetsManager @@ -74,7 +74,7 @@ final class BuildManager: Loggable { self.useBinariesManager = useBinariesManager self.binariesCleaner = binariesCleaner self.environmentCollector = environmentCollector - self.featureToggles = featureToggles + self.env = env self.targetTreePainter = targetTreePainter } @@ -99,7 +99,7 @@ final class BuildManager: Loggable { return nil } - if featureToggles.printMissingBinaries { + if env.printMissingBinaries { let tree = targetTreePainter.paint(targets: buildTargets) await logPlain( "\(".".yellow) \("Missing Binaries (\(buildTargets.count))".green)\n\(tree)" diff --git a/Sources/RugbyFoundation/Core/Common/IFeatureToggles.swift b/Sources/RugbyFoundation/Core/Common/IEnvironment.swift similarity index 63% rename from Sources/RugbyFoundation/Core/Common/IFeatureToggles.swift rename to Sources/RugbyFoundation/Core/Common/IEnvironment.swift index 8303e7ef..21162f38 100644 --- a/Sources/RugbyFoundation/Core/Common/IFeatureToggles.swift +++ b/Sources/RugbyFoundation/Core/Common/IEnvironment.swift @@ -1,6 +1,6 @@ -/// The protocol describing a service providing the feature toggles. -public protocol IFeatureToggles: AnyObject { - /// The feature names and their values. +/// The protocol describing a service providing the environment variables. +public protocol IEnvironment: AnyObject { + /// The variable names and their values. var all: [String: String] { get } /// A flag to keep yaml files with target hash in the binaries folder. diff --git a/Sources/RugbyFoundation/Vault/Commands/Build/Vault+Build.swift b/Sources/RugbyFoundation/Vault/Commands/Build/Vault+Build.swift index 9345b026..275e76ff 100644 --- a/Sources/RugbyFoundation/Vault/Commands/Build/Vault+Build.swift +++ b/Sources/RugbyFoundation/Vault/Commands/Build/Vault+Build.swift @@ -42,7 +42,7 @@ extension Vault { useBinariesManager: useBinariesManager, binariesCleaner: binariesCleaner, environmentCollector: environmentCollector, - featureToggles: featureToggles, + env: env, targetTreePainter: TargetTreePainter()) } } diff --git a/Sources/RugbyFoundation/Vault/Vault.swift b/Sources/RugbyFoundation/Vault/Vault.swift index f63edcf1..282286e5 100644 --- a/Sources/RugbyFoundation/Vault/Vault.swift +++ b/Sources/RugbyFoundation/Vault/Vault.swift @@ -11,17 +11,17 @@ public final class Vault { /// - logger: The service collecting information about Rugby execution. /// - router: The service providing all paths for Rugby infrastructure. public static func setupShared( - featureToggles: IFeatureToggles, + env: IEnvironment, logger: ILogger, router: IRouter ) { - shared = Vault(featureToggles: featureToggles, logger: logger, router: router) + shared = Vault(env: env, logger: logger, router: router) } // MARK: - Init - /// The service providing feature toggles. - public let featureToggles: IFeatureToggles + /// The service providing environment variables. + public let env: IEnvironment /// The general Rugby settings. public let settings = Settings() /// The service collecting information about Rugby execution. @@ -30,11 +30,11 @@ public final class Vault { public let router: IRouter private init( - featureToggles: IFeatureToggles, + env: IEnvironment, logger: ILogger, router: IRouter ) { - self.featureToggles = featureToggles + self.env = env self.logger = logger self.router = router } @@ -95,7 +95,7 @@ public final class Vault { private(set) lazy var binariesManager = BinariesStorage( logger: logger, sharedPath: router.binFolderPath, - keepHashYamls: featureToggles.keepHashYamls + keepHashYamls: env.keepHashYamls ) func targetsHasher() -> TargetsHasher { let foundationHasher = SHA1Hasher() From 8e614d69718e555474a6ba2c9ef217c6b1e2f72f Mon Sep 17 00:00:00 2001 From: Vyacheslav Khorkov Date: Sat, 18 Nov 2023 15:27:52 +0500 Subject: [PATCH 2/4] Update Env command docs --- Docs/commands-help/env.md | 45 ++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/Docs/commands-help/env.md b/Docs/commands-help/env.md index 65016357..201ecb50 100644 --- a/Docs/commands-help/env.md +++ b/Docs/commands-help/env.md @@ -18,11 +18,46 @@ ## Discussion -Rugby supports these environment variables: +This command prints the Rugby environment. For example: +```yml +Rugby version: 2.3.0 +Swift: 5.9 +CLT: Xcode 15.0.1 (Build version 15A507) +CPU: Apple M1 (arm64) +Project: Example +Git branch: main +RUGBY_KEEP_HASH_YAMLS: NO +RUGBY_PRINT_MISSING_BINARIES: NO +``` + +You can find the same environment output in the head of each Rugby log file. + +
+ +### Keep hash YML files + +A flag to keep yaml files with target hash in the binaries folder. ```objc -# A flag to keep yaml files with target hash in the binaries folder. -RUGBY_KEEP_HASH_YAMLS = NO +RUGBY_KEEP_HASH_YAMLS=YES rugby +``` +```sh +.rugby +└─ bin + └─ Debug-iphonesimulator-arm64 + └─ 85d4367 + ├─ 85d4367.yml # Hash yml file + └─ Alamofire.framework +``` + +### Print missing binaries as a tree -# A flag to print missing binaries as a tree during an analysing process. -RUGBY_PRINT_MISSING_BINARIES = NO +A flag to print missing binaries as a tree during an analysing process. +```objc +RUGBY_PRINT_MISSING_BINARIES=YES rugby +``` +``` +. Missing Binaries (3) +┣━ Kingfisher-framework (1a1f878) +┗━ Moya-framework (a4a42b2) + ┗━ Alamofire-framework (85d4367) ``` From f6fb8a124beee86549b78bd2d768c886f48026d4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Khorkov Date: Sat, 18 Nov 2023 15:33:00 +0500 Subject: [PATCH 3/4] Add ability to set shared folder root path --- Docs/commands-help/env.md | 28 +++++++++++++++++++ .../Environment/Environment.swift | 8 +++++- Sources/Rugby/Rugby.swift | 2 +- .../Core/Common/IEnvironment.swift | 3 ++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Docs/commands-help/env.md b/Docs/commands-help/env.md index 201ecb50..323d8171 100644 --- a/Docs/commands-help/env.md +++ b/Docs/commands-help/env.md @@ -28,6 +28,7 @@ Project: Example Git branch: main RUGBY_KEEP_HASH_YAMLS: NO RUGBY_PRINT_MISSING_BINARIES: NO +RUGBY_SHARED_PARENT_DIR: /Users/swiftyfinch ``` You can find the same environment output in the head of each Rugby log file. @@ -61,3 +62,30 @@ RUGBY_PRINT_MISSING_BINARIES=YES rugby ┗━ Moya-framework (a4a42b2) ┗━ Alamofire-framework (85d4367) ``` + +### Set a custom path to shared folder root + +A path to the root of shared folder (without `.rugby` folder name). +By default: +```objc +RUGBY_SHARED_DIR_ROOT=$HOME rugby +``` +```sh +~ +└─ .rugby # shared folder + ├─ bin + └─ logs +``` + +You can set a different one. For example, a current directory: +```objc +RUGBY_SHARED_DIR_ROOT=`pwd` rugby +``` +```sh +pwd +└─ .rugby # shared folder combined with local one + ├─ backup + ├─ bin + ├─ build + └─ logs +``` diff --git a/Sources/Rugby/Core/Dependencies/Environment/Environment.swift b/Sources/Rugby/Core/Dependencies/Environment/Environment.swift index 7ea60ee2..4859cb0d 100644 --- a/Sources/Rugby/Core/Dependencies/Environment/Environment.swift +++ b/Sources/Rugby/Core/Dependencies/Environment/Environment.swift @@ -6,6 +6,7 @@ final class Environment { // swiftlint:disable identifier_name private let RUGBY_KEEP_HASH_YAMLS = "RUGBY_KEEP_HASH_YAMLS" private let RUGBY_PRINT_MISSING_BINARIES = "RUGBY_PRINT_MISSING_BINARIES" + private let RUGBY_SHARED_DIR_ROOT = "RUGBY_SHARED_DIR_ROOT" // swiftlint:enable identifier_name } @@ -13,7 +14,8 @@ extension Environment: IEnvironment { var all: [String: String] { [ RUGBY_KEEP_HASH_YAMLS: keepHashYamls.yesNo, - RUGBY_PRINT_MISSING_BINARIES: printMissingBinaries.yesNo + RUGBY_PRINT_MISSING_BINARIES: printMissingBinaries.yesNo, + RUGBY_SHARED_DIR_ROOT: sharedFolderParentPath ] } @@ -24,6 +26,10 @@ extension Environment: IEnvironment { var printMissingBinaries: Bool { ProcessInfo.processInfo.environment[RUGBY_PRINT_MISSING_BINARIES].isEnabled } + + var sharedFolderParentPath: String { + ProcessInfo.processInfo.environment[RUGBY_SHARED_DIR_ROOT] ?? Folder.home.path + } } private extension String? { diff --git a/Sources/Rugby/Rugby.swift b/Sources/Rugby/Rugby.swift index 6346df96..ef87d8cc 100644 --- a/Sources/Rugby/Rugby.swift +++ b/Sources/Rugby/Rugby.swift @@ -76,7 +76,7 @@ struct Rugby: AsyncParsableCommand { logger: Logger(clock: Clock()), router: Router( workingDirectory: Folder.current, - sharedFolderPath: Folder.home.path + sharedFolderPath: env.sharedFolderParentPath ) ) } diff --git a/Sources/RugbyFoundation/Core/Common/IEnvironment.swift b/Sources/RugbyFoundation/Core/Common/IEnvironment.swift index 21162f38..6600af68 100644 --- a/Sources/RugbyFoundation/Core/Common/IEnvironment.swift +++ b/Sources/RugbyFoundation/Core/Common/IEnvironment.swift @@ -8,4 +8,7 @@ public protocol IEnvironment: AnyObject { /// A flag to print missing binaries as a tree during an analysing process. var printMissingBinaries: Bool { get } + + /// A path to the root of shared folder (without `.rugby` folder name). + var sharedFolderParentPath: String { get } } From dce3bc6610813b2318417fcc8a95317e8521019c Mon Sep 17 00:00:00 2001 From: Vyacheslav Khorkov Date: Mon, 20 Nov 2023 20:36:57 +0500 Subject: [PATCH 4/4] Update env.md --- Docs/commands-help/env.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/commands-help/env.md b/Docs/commands-help/env.md index 323d8171..31cbe839 100644 --- a/Docs/commands-help/env.md +++ b/Docs/commands-help/env.md @@ -28,7 +28,7 @@ Project: Example Git branch: main RUGBY_KEEP_HASH_YAMLS: NO RUGBY_PRINT_MISSING_BINARIES: NO -RUGBY_SHARED_PARENT_DIR: /Users/swiftyfinch +RUGBY_SHARED_DIR_ROOT: /Users/swiftyfinch ``` You can find the same environment output in the head of each Rugby log file.