From 2978c5f217ed36bf363b0149a7d1fc2a3fac0454 Mon Sep 17 00:00:00 2001 From: Gorbenko Roman <45801227+rofle100lvl@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:02:37 +0200 Subject: [PATCH] Move Configuration to separate module --- Package.swift | 22 ++++++ Sources/BaseLogger/BaseLogger.swift | 77 ++++++++++++++++++ .../Configuration.swift | 4 +- .../Commands/CheckUpdateCommand.swift | 3 +- .../Frontend/Commands/ClearCacheCommand.swift | 1 + .../Frontend/Commands/FrontendCommand.swift | 2 +- Sources/Frontend/Commands/ScanBehavior.swift | 2 + Sources/Frontend/Commands/ScanCommand.swift | 1 + Sources/Frontend/CommonSetupGuide.swift | 2 + Sources/Frontend/GuidedSetup.swift | 2 + Sources/Frontend/Project.swift | 1 + Sources/Frontend/SPMProjectSetupGuide.swift | 1 + Sources/Frontend/Scan.swift | 3 + Sources/Frontend/UpdateChecker.swift | 4 +- Sources/Frontend/main.swift | 2 +- Sources/Indexer/IndexPipeline.swift | 2 +- Sources/Indexer/Indexer.swift | 2 +- Sources/Indexer/InfoPlistIndexer.swift | 2 + Sources/Indexer/SourceFileCollector.swift | 2 + Sources/Indexer/SwiftIndexer.swift | 2 + Sources/Indexer/XCDataModelIndexer.swift | 2 + Sources/Indexer/XCMappingModelIndexer.swift | 2 + Sources/Indexer/XibIndexer.swift | 2 + .../Results/CheckstyleFormatter.swift | 1 + .../Results/CodeClimateFormatter.swift | 1 + .../PeripheryKit/Results/CsvFormatter.swift | 1 + .../Results/GitHubActionsFormatter.swift | 1 + .../PeripheryKit/Results/JsonFormatter.swift | 1 + .../Results/OutputDeclarationFilter.swift | 3 +- .../Results/OutputFormatter.swift | 2 + .../PeripheryKit/Results/XcodeFormatter.swift | 2 + .../ProjectDrivers/BazelProjectDriver.swift | 3 + .../ProjectDrivers/GenericProjectDriver.swift | 2 + Sources/ProjectDrivers/ProjectDriver.swift | 2 +- Sources/{Shared => ProjectDrivers}/SPM.swift | 3 + Sources/ProjectDrivers/SPMProjectDriver.swift | 3 + .../ProjectDrivers/XcodeProjectDriver.swift | 3 + Sources/Shared/OutputFormat.swift | 2 +- Sources/Shared/SetupGuide.swift | 1 + .../Mutators/AccessibilityCascader.swift | 2 +- .../AncestralReferenceEliminator.swift | 2 +- .../Mutators/AssetReferenceRetainer.swift | 2 +- ...ssignOnlyPropertyReferenceEliminator.swift | 2 +- .../CapitalSelfFunctionCallRetainer.swift | 4 +- .../Mutators/CodablePropertyRetainer.swift | 2 +- .../CodingKeyEnumReferenceBuilder.swift | 2 +- ...plexPropertyAccessorReferenceBuilder.swift | 2 +- .../DefaultConstructorReferenceBuilder.swift | 2 +- .../DynamicMemberLookupReferenceBuilder.swift | 2 +- .../EntryPointAttributeRetainer.swift | 2 +- .../Mutators/EnumCaseReferenceBuilder.swift | 2 +- .../Mutators/ExtensionReferenceBuilder.swift | 2 +- ...eProtocolConformanceReferenceRemover.swift | 2 +- ...AndStructConstructorReferenceBuilder.swift | 2 +- .../Mutators/ObjCAccessibleRetainer.swift | 2 +- .../Mutators/PropertyWrapperRetainer.swift | 2 +- .../ProtocolConformanceReferenceBuilder.swift | 2 +- .../ProtocolExtensionReferenceBuilder.swift | 2 +- .../Mutators/PubliclyAccessibleRetainer.swift | 2 +- ...antExplicitPublicAccessibilityMarker.swift | 1 + .../Mutators/RedundantProtocolMarker.swift | 2 +- .../Mutators/ResultBuilderRetainer.swift | 2 +- ...rpolationAppendInterpolationRetainer.swift | 2 +- ...tImplicitInitializerReferenceBuilder.swift | 2 +- .../Mutators/SwiftUIRetainer.swift | 2 +- .../Mutators/UnusedImportMarker.swift | 1 + .../Mutators/UnusedParameterRetainer.swift | 1 + .../Mutators/UsedDeclarationMarker.swift | 2 +- .../SourceGraph/Mutators/XCTestRetainer.swift | 1 + Sources/SourceGraph/SourceGraph.swift | 1 + Sources/SourceGraph/SourceGraphMutator.swift | 2 +- .../SourceGraphMutatorRunner.swift | 2 + .../Extensions => Utils}/FilePath+Glob.swift | 0 Sources/Utils/Logger+Configuration.swift | 11 +++ Sources/{Shared => Utils}/Logger.swift | 78 +------------------ Sources/{Shared => Utils}/Shell.swift | 2 + .../Extensions => Utils}/String+Version.swift | 0 Sources/{Shared => Utils}/SwiftVersion.swift | 1 + .../SwiftVersionParser.swift | 1 + Sources/XcodeSupport/XcodeProject.swift | 1 + .../XcodeSupport/XcodeProjectSetupGuide.swift | 2 + Sources/XcodeSupport/XcodeWorkspace.swift | 2 + Sources/XcodeSupport/Xcodebuild.swift | 1 + Tests/PeripheryTests/RetentionTest.swift | 2 +- Tests/PeripheryTests/ShellTest.swift | 2 +- .../SwiftVersionParserTest.swift | 2 +- Tests/Shared/SPMSourceGraphTestCase.swift | 1 + Tests/Shared/SourceGraphTestCase.swift | 2 + Tests/XcodeTests/ShellMock.swift | 2 +- .../XcodeTests/XcodeSourceGraphTestCase.swift | 1 + .../XcodebuildBuildProjectTest.swift | 1 - 91 files changed, 230 insertions(+), 119 deletions(-) create mode 100644 Sources/BaseLogger/BaseLogger.swift rename Sources/{Shared => Configuration}/Configuration.swift (99%) rename Sources/{Shared => ProjectDrivers}/SPM.swift (97%) rename Sources/{Shared/Extensions => Utils}/FilePath+Glob.swift (100%) create mode 100644 Sources/Utils/Logger+Configuration.swift rename Sources/{Shared => Utils}/Logger.swift (62%) rename Sources/{Shared => Utils}/Shell.swift (99%) rename Sources/{Shared/Extensions => Utils}/String+Version.swift (100%) rename Sources/{Shared => Utils}/SwiftVersion.swift (98%) rename Sources/{Shared => Utils}/SwiftVersionParser.swift (96%) diff --git a/Package.swift b/Package.swift index 6657cc911..ef7d457b9 100644 --- a/Package.swift +++ b/Package.swift @@ -64,6 +64,17 @@ var targets: [PackageDescription.Target] = [ .product(name: "SwiftIndexStore", package: "swift-indexstore"), ] ), + .target(name: "BaseLogger"), + .target( + name: "Configuration", + dependencies: [ + .product(name: "FilenameMatcher", package: "swift-filename-matcher"), + .product(name: "Yams", package: "Yams"), + .product(name: "SystemPackage", package: "swift-system"), + .target(name: "BaseLogger"), + .target(name: "Shared"), + ] + ), .target( name: "ProjectDrivers", dependencies: projectDriverDependencies @@ -82,6 +93,8 @@ var targets: [PackageDescription.Target] = [ dependencies: [ .product(name: "SwiftSyntax", package: "swift-syntax"), .target(name: "Shared"), + .target(name: "Configuration"), + .target(name: "Utils"), ] ), .target( @@ -92,6 +105,15 @@ var targets: [PackageDescription.Target] = [ .product(name: "FilenameMatcher", package: "swift-filename-matcher"), ] ), + .target( + name: "Utils", + dependencies: [ + .product(name: "Yams", package: "Yams"), + .product(name: "SystemPackage", package: "swift-system"), + .product(name: "FilenameMatcher", package: "swift-filename-matcher"), + .target(name: "Configuration"), + ] + ), .target( name: "TestShared", dependencies: [ diff --git a/Sources/BaseLogger/BaseLogger.swift b/Sources/BaseLogger/BaseLogger.swift new file mode 100644 index 000000000..10d93f4d0 --- /dev/null +++ b/Sources/BaseLogger/BaseLogger.swift @@ -0,0 +1,77 @@ +import Foundation + +public enum ANSIColor: String { + case bold = "\u{001B}[0;1m" + case red = "\u{001B}[0;31m" + case boldRed = "\u{001B}[0;1;31m" + case green = "\u{001B}[0;32m" + case boldGreen = "\u{001B}[0;1;32m" + case yellow = "\u{001B}[0;33m" + case boldYellow = "\u{001B}[0;1;33m" + case blue = "\u{001B}[0;34m" + case lightBlue = "\u{001B}[1;34m" + case magenta = "\u{001B}[0;35m" + case boldMagenta = "\u{001B}[0;1;35m" + case cyan = "\u{001B}[0;36m" + case white = "\u{001B}[0;37m" + case gray = "\u{001B}[0;1;30m" +} + +@usableFromInline var isColorOutputCapable: Bool = { + guard let term = ProcessInfo.processInfo.environment["TERM"], + term.lowercased() != "dumb", + isatty(fileno(stdout)) != 0 + else { + return false + } + + return true +}() + +@inlinable +public func colorize(_ text: String, _ color: ANSIColor) -> String { + guard isColorOutputCapable else { return text } + return "\(color.rawValue)\(text)\u{001B}[0;0m" +} + +public final class BaseLogger { + public static let shared = BaseLogger() + + @usableFromInline let outputQueue: DispatchQueue + + private init() { + outputQueue = DispatchQueue(label: "BaseLogger.outputQueue") + } + + @inlinable + public func info(_ text: String) { + log(text, output: stdout) + } + + @inlinable + public func debug(_ text: String) { + log(text, output: stdout) + } + + @inlinable + public func warn(_ text: String, newlinePrefix: Bool = false) { + if newlinePrefix { + log("", output: stderr) + } + let text = colorize("warning: ", .boldYellow) + text + log(text, output: stderr) + } + + @inlinable + public func error(_ text: String) { + let text = colorize("error: ", .boldRed) + text + log(text, output: stderr) + } + + // MARK: - Private + + @inlinable + func log(_ line: String, output: UnsafeMutablePointer) { + _ = outputQueue.sync { fputs(line + "\n", output) } + } +} diff --git a/Sources/Shared/Configuration.swift b/Sources/Configuration/Configuration.swift similarity index 99% rename from Sources/Shared/Configuration.swift rename to Sources/Configuration/Configuration.swift index de43a10ae..f6dcb1cce 100644 --- a/Sources/Shared/Configuration.swift +++ b/Sources/Configuration/Configuration.swift @@ -2,10 +2,12 @@ import FilenameMatcher import Foundation import SystemPackage import Yams +import Shared +import BaseLogger public final class Configuration { public static var defaultConfigurationFile = FilePath(".periphery.yml") - public static let shared = Configuration() + public static let shared = Configuration(logger: BaseLogger.shared) public init(logger: BaseLogger = .shared) { self.logger = logger diff --git a/Sources/Frontend/Commands/CheckUpdateCommand.swift b/Sources/Frontend/Commands/CheckUpdateCommand.swift index 6c222645e..4129b497d 100644 --- a/Sources/Frontend/Commands/CheckUpdateCommand.swift +++ b/Sources/Frontend/Commands/CheckUpdateCommand.swift @@ -1,6 +1,7 @@ import ArgumentParser import Foundation -import Shared +import Utils +import BaseLogger struct CheckUpdateCommand: FrontendCommand { static let configuration = CommandConfiguration( diff --git a/Sources/Frontend/Commands/ClearCacheCommand.swift b/Sources/Frontend/Commands/ClearCacheCommand.swift index 1309171a7..c58e11da8 100644 --- a/Sources/Frontend/Commands/ClearCacheCommand.swift +++ b/Sources/Frontend/Commands/ClearCacheCommand.swift @@ -1,6 +1,7 @@ import ArgumentParser import Foundation import Shared +import Utils struct ClearCacheCommand: FrontendCommand { static let configuration = CommandConfiguration( diff --git a/Sources/Frontend/Commands/FrontendCommand.swift b/Sources/Frontend/Commands/FrontendCommand.swift index 872d120eb..5f02a394a 100644 --- a/Sources/Frontend/Commands/FrontendCommand.swift +++ b/Sources/Frontend/Commands/FrontendCommand.swift @@ -1,5 +1,5 @@ import ArgumentParser -import Shared +import BaseLogger protocol FrontendCommand: ParsableCommand {} extension FrontendCommand { diff --git a/Sources/Frontend/Commands/ScanBehavior.swift b/Sources/Frontend/Commands/ScanBehavior.swift index aeb35809b..14fe57712 100644 --- a/Sources/Frontend/Commands/ScanBehavior.swift +++ b/Sources/Frontend/Commands/ScanBehavior.swift @@ -2,6 +2,8 @@ import Foundation import PeripheryKit import Shared import SystemPackage +import Configuration +import Utils final class ScanBehavior { private let configuration: Configuration diff --git a/Sources/Frontend/Commands/ScanCommand.swift b/Sources/Frontend/Commands/ScanCommand.swift index cd0bda347..66a17c7e3 100644 --- a/Sources/Frontend/Commands/ScanCommand.swift +++ b/Sources/Frontend/Commands/ScanCommand.swift @@ -2,6 +2,7 @@ import ArgumentParser import Foundation import Shared import SystemPackage +import Configuration struct ScanCommand: FrontendCommand { static let configuration = CommandConfiguration( diff --git a/Sources/Frontend/CommonSetupGuide.swift b/Sources/Frontend/CommonSetupGuide.swift index 421bc471c..dc9a39beb 100644 --- a/Sources/Frontend/CommonSetupGuide.swift +++ b/Sources/Frontend/CommonSetupGuide.swift @@ -1,5 +1,7 @@ import Foundation import Shared +import Configuration +import BaseLogger final class CommonSetupGuide: SetupGuideHelpers { private let configuration: Configuration diff --git a/Sources/Frontend/GuidedSetup.swift b/Sources/Frontend/GuidedSetup.swift index 7d618b4a3..e6768d4b4 100644 --- a/Sources/Frontend/GuidedSetup.swift +++ b/Sources/Frontend/GuidedSetup.swift @@ -1,5 +1,7 @@ import Foundation import Shared +import Configuration +import BaseLogger #if canImport(XcodeSupport) import XcodeSupport diff --git a/Sources/Frontend/Project.swift b/Sources/Frontend/Project.swift index 71df29625..506b2f066 100644 --- a/Sources/Frontend/Project.swift +++ b/Sources/Frontend/Project.swift @@ -2,6 +2,7 @@ import Foundation import ProjectDrivers import Shared import SystemPackage +import Configuration final class Project { static func identify() throws -> Self { diff --git a/Sources/Frontend/SPMProjectSetupGuide.swift b/Sources/Frontend/SPMProjectSetupGuide.swift index 8d2e7c5ec..8a00c220a 100644 --- a/Sources/Frontend/SPMProjectSetupGuide.swift +++ b/Sources/Frontend/SPMProjectSetupGuide.swift @@ -1,6 +1,7 @@ import Foundation import Shared import SystemPackage +import ProjectDrivers final class SPMProjectSetupGuide: SetupGuideHelpers, SetupGuide { static func detect() -> Self? { diff --git a/Sources/Frontend/Scan.swift b/Sources/Frontend/Scan.swift index 755e35648..d6fb7f2f3 100644 --- a/Sources/Frontend/Scan.swift +++ b/Sources/Frontend/Scan.swift @@ -4,6 +4,9 @@ import PeripheryKit import ProjectDrivers import Shared import SourceGraph +import Configuration +import Utils +import BaseLogger final class Scan { private let configuration: Configuration diff --git a/Sources/Frontend/UpdateChecker.swift b/Sources/Frontend/UpdateChecker.swift index 4e7de130d..11a9e3623 100644 --- a/Sources/Frontend/UpdateChecker.swift +++ b/Sources/Frontend/UpdateChecker.swift @@ -1,6 +1,8 @@ import Foundation import Shared - +import Configuration +import Utils +import BaseLogger #if canImport(FoundationNetworking) import FoundationNetworking #endif diff --git a/Sources/Frontend/main.swift b/Sources/Frontend/main.swift index 9e7ed7f38..5c23c60c1 100644 --- a/Sources/Frontend/main.swift +++ b/Sources/Frontend/main.swift @@ -1,6 +1,6 @@ import ArgumentParser import Foundation -import Shared +import Utils Logger.configureBuffering() diff --git a/Sources/Indexer/IndexPipeline.swift b/Sources/Indexer/IndexPipeline.swift index caa60b166..1dc9ca379 100644 --- a/Sources/Indexer/IndexPipeline.swift +++ b/Sources/Indexer/IndexPipeline.swift @@ -1,6 +1,6 @@ import Foundation -import Shared import SourceGraph +import Utils public struct IndexPipeline { private let plan: IndexPlan diff --git a/Sources/Indexer/Indexer.swift b/Sources/Indexer/Indexer.swift index 8bd993b43..5b3feb6dc 100644 --- a/Sources/Indexer/Indexer.swift +++ b/Sources/Indexer/Indexer.swift @@ -1,8 +1,8 @@ import FilenameMatcher import Foundation -import Shared import SourceGraph import SystemPackage +import Configuration class Indexer { private let configuration: Configuration diff --git a/Sources/Indexer/InfoPlistIndexer.swift b/Sources/Indexer/InfoPlistIndexer.swift index fd80244ad..f05aa4c4b 100644 --- a/Sources/Indexer/InfoPlistIndexer.swift +++ b/Sources/Indexer/InfoPlistIndexer.swift @@ -1,6 +1,8 @@ import Shared import SourceGraph import SystemPackage +import Utils +import Configuration final class InfoPlistIndexer: Indexer { private let infoPlistFiles: Set diff --git a/Sources/Indexer/SourceFileCollector.swift b/Sources/Indexer/SourceFileCollector.swift index d02a82095..7921786c3 100644 --- a/Sources/Indexer/SourceFileCollector.swift +++ b/Sources/Indexer/SourceFileCollector.swift @@ -3,6 +3,8 @@ import Shared import SourceGraph import SwiftIndexStore import SystemPackage +import Utils +import Configuration public struct SourceFileCollector { private let indexStorePaths: Set diff --git a/Sources/Indexer/SwiftIndexer.swift b/Sources/Indexer/SwiftIndexer.swift index 3231bc6ec..daffc9a7e 100644 --- a/Sources/Indexer/SwiftIndexer.swift +++ b/Sources/Indexer/SwiftIndexer.swift @@ -4,6 +4,8 @@ import SourceGraph import SwiftIndexStore import SyntaxAnalysis import SystemPackage +import Utils +import Configuration public struct IndexUnit { let store: IndexStore diff --git a/Sources/Indexer/XCDataModelIndexer.swift b/Sources/Indexer/XCDataModelIndexer.swift index f5311f03c..9560a53b2 100644 --- a/Sources/Indexer/XCDataModelIndexer.swift +++ b/Sources/Indexer/XCDataModelIndexer.swift @@ -1,6 +1,8 @@ import Shared import SourceGraph import SystemPackage +import Utils +import Configuration final class XCDataModelIndexer: Indexer { private let files: Set diff --git a/Sources/Indexer/XCMappingModelIndexer.swift b/Sources/Indexer/XCMappingModelIndexer.swift index 2c98181c2..12335ec98 100644 --- a/Sources/Indexer/XCMappingModelIndexer.swift +++ b/Sources/Indexer/XCMappingModelIndexer.swift @@ -1,6 +1,8 @@ import Shared import SourceGraph import SystemPackage +import Utils +import Configuration final class XCMappingModelIndexer: Indexer { private let files: Set diff --git a/Sources/Indexer/XibIndexer.swift b/Sources/Indexer/XibIndexer.swift index e6507e555..a7b05bed0 100644 --- a/Sources/Indexer/XibIndexer.swift +++ b/Sources/Indexer/XibIndexer.swift @@ -1,6 +1,8 @@ import Shared import SourceGraph import SystemPackage +import Utils +import Configuration final class XibIndexer: Indexer { private let xibFiles: Set diff --git a/Sources/PeripheryKit/Results/CheckstyleFormatter.swift b/Sources/PeripheryKit/Results/CheckstyleFormatter.swift index 706f76ed6..c69d18658 100644 --- a/Sources/PeripheryKit/Results/CheckstyleFormatter.swift +++ b/Sources/PeripheryKit/Results/CheckstyleFormatter.swift @@ -2,6 +2,7 @@ import Foundation import Shared import SourceGraph import SystemPackage +import Configuration final class CheckstyleFormatter: OutputFormatter { let configuration: Configuration diff --git a/Sources/PeripheryKit/Results/CodeClimateFormatter.swift b/Sources/PeripheryKit/Results/CodeClimateFormatter.swift index c3400ce79..5d07b452f 100644 --- a/Sources/PeripheryKit/Results/CodeClimateFormatter.swift +++ b/Sources/PeripheryKit/Results/CodeClimateFormatter.swift @@ -1,6 +1,7 @@ import Foundation import Shared import SystemPackage +import Configuration final class CodeClimateFormatter: OutputFormatter { let configuration: Configuration diff --git a/Sources/PeripheryKit/Results/CsvFormatter.swift b/Sources/PeripheryKit/Results/CsvFormatter.swift index 07d082279..a86f2f2e3 100644 --- a/Sources/PeripheryKit/Results/CsvFormatter.swift +++ b/Sources/PeripheryKit/Results/CsvFormatter.swift @@ -2,6 +2,7 @@ import Foundation import Shared import SourceGraph import SystemPackage +import Configuration final class CsvFormatter: OutputFormatter { let configuration: Configuration diff --git a/Sources/PeripheryKit/Results/GitHubActionsFormatter.swift b/Sources/PeripheryKit/Results/GitHubActionsFormatter.swift index b20af84d7..3719b2382 100644 --- a/Sources/PeripheryKit/Results/GitHubActionsFormatter.swift +++ b/Sources/PeripheryKit/Results/GitHubActionsFormatter.swift @@ -2,6 +2,7 @@ import Foundation import Shared import SourceGraph import SystemPackage +import Configuration final class GitHubActionsFormatter: OutputFormatter { let configuration: Configuration diff --git a/Sources/PeripheryKit/Results/JsonFormatter.swift b/Sources/PeripheryKit/Results/JsonFormatter.swift index 5e802d5a5..010511eab 100644 --- a/Sources/PeripheryKit/Results/JsonFormatter.swift +++ b/Sources/PeripheryKit/Results/JsonFormatter.swift @@ -1,6 +1,7 @@ import Foundation import Shared import SystemPackage +import Configuration final class JsonFormatter: OutputFormatter { let configuration: Configuration diff --git a/Sources/PeripheryKit/Results/OutputDeclarationFilter.swift b/Sources/PeripheryKit/Results/OutputDeclarationFilter.swift index 89379f492..983726e51 100644 --- a/Sources/PeripheryKit/Results/OutputDeclarationFilter.swift +++ b/Sources/PeripheryKit/Results/OutputDeclarationFilter.swift @@ -1,7 +1,8 @@ import FilenameMatcher import Foundation -import Shared import SystemPackage +import Configuration +import Utils public final class OutputDeclarationFilter { private let configuration: Configuration diff --git a/Sources/PeripheryKit/Results/OutputFormatter.swift b/Sources/PeripheryKit/Results/OutputFormatter.swift index d388f9c4f..0446f35bd 100644 --- a/Sources/PeripheryKit/Results/OutputFormatter.swift +++ b/Sources/PeripheryKit/Results/OutputFormatter.swift @@ -2,6 +2,8 @@ import Foundation import Shared import SourceGraph import SystemPackage +import Configuration +import BaseLogger public protocol OutputFormatter: AnyObject { var configuration: Configuration { get } diff --git a/Sources/PeripheryKit/Results/XcodeFormatter.swift b/Sources/PeripheryKit/Results/XcodeFormatter.swift index 674d1fcdd..20d8d7433 100644 --- a/Sources/PeripheryKit/Results/XcodeFormatter.swift +++ b/Sources/PeripheryKit/Results/XcodeFormatter.swift @@ -2,6 +2,8 @@ import Foundation import Shared import SourceGraph import SystemPackage +import Configuration +import BaseLogger final class XcodeFormatter: OutputFormatter { let configuration: Configuration diff --git a/Sources/ProjectDrivers/BazelProjectDriver.swift b/Sources/ProjectDrivers/BazelProjectDriver.swift index 02e045ef0..1a17e2356 100644 --- a/Sources/ProjectDrivers/BazelProjectDriver.swift +++ b/Sources/ProjectDrivers/BazelProjectDriver.swift @@ -1,6 +1,9 @@ import Foundation import Shared import SystemPackage +import Configuration +import Utils +import BaseLogger public class BazelProjectDriver: ProjectDriver { public static var isSupported: Bool { diff --git a/Sources/ProjectDrivers/GenericProjectDriver.swift b/Sources/ProjectDrivers/GenericProjectDriver.swift index 52ddab1d7..e36ede9fe 100644 --- a/Sources/ProjectDrivers/GenericProjectDriver.swift +++ b/Sources/ProjectDrivers/GenericProjectDriver.swift @@ -3,6 +3,8 @@ import Indexer import Shared import SwiftIndexStore import SystemPackage +import Configuration +import Utils public final class GenericProjectDriver { struct GenericConfig: Decodable { diff --git a/Sources/ProjectDrivers/ProjectDriver.swift b/Sources/ProjectDrivers/ProjectDriver.swift index 7a439ea96..c14421482 100644 --- a/Sources/ProjectDrivers/ProjectDriver.swift +++ b/Sources/ProjectDrivers/ProjectDriver.swift @@ -1,7 +1,7 @@ import Foundation import Indexer -import Shared import SwiftIndexStore +import Utils public protocol ProjectDriver { func build() throws diff --git a/Sources/Shared/SPM.swift b/Sources/ProjectDrivers/SPM.swift similarity index 97% rename from Sources/Shared/SPM.swift rename to Sources/ProjectDrivers/SPM.swift index 307c880df..7821ce116 100644 --- a/Sources/Shared/SPM.swift +++ b/Sources/ProjectDrivers/SPM.swift @@ -1,5 +1,8 @@ import Foundation +import Configuration import SystemPackage +import Utils +import Shared public enum SPM { static let packageFile = "Package.swift" diff --git a/Sources/ProjectDrivers/SPMProjectDriver.swift b/Sources/ProjectDrivers/SPMProjectDriver.swift index a462fd0a0..d613e3cd2 100644 --- a/Sources/ProjectDrivers/SPMProjectDriver.swift +++ b/Sources/ProjectDrivers/SPMProjectDriver.swift @@ -3,6 +3,9 @@ import Indexer import Shared import SwiftIndexStore import SystemPackage +import Configuration +import Utils +import BaseLogger public final class SPMProjectDriver { public static func build() throws -> Self { diff --git a/Sources/ProjectDrivers/XcodeProjectDriver.swift b/Sources/ProjectDrivers/XcodeProjectDriver.swift index 1e52b1c59..564b529a2 100644 --- a/Sources/ProjectDrivers/XcodeProjectDriver.swift +++ b/Sources/ProjectDrivers/XcodeProjectDriver.swift @@ -5,6 +5,9 @@ import SourceGraph import SystemPackage import XcodeSupport + import Utils + import Configuration + import BaseLogger public final class XcodeProjectDriver { public static func build(projectPath: FilePath) throws -> Self { diff --git a/Sources/Shared/OutputFormat.swift b/Sources/Shared/OutputFormat.swift index 0f550bedb..240e853bd 100644 --- a/Sources/Shared/OutputFormat.swift +++ b/Sources/Shared/OutputFormat.swift @@ -10,7 +10,7 @@ public enum OutputFormat: String, CaseIterable { public static let `default` = OutputFormat.xcode - init?(anyValue: Any) { + public init?(anyValue: Any) { if let format = anyValue as? OutputFormat { self = format return diff --git a/Sources/Shared/SetupGuide.swift b/Sources/Shared/SetupGuide.swift index 21e43b561..b8beaabc2 100644 --- a/Sources/Shared/SetupGuide.swift +++ b/Sources/Shared/SetupGuide.swift @@ -1,4 +1,5 @@ import Foundation +import BaseLogger public protocol SetupGuide { func perform() throws -> ProjectKind diff --git a/Sources/SourceGraph/Mutators/AccessibilityCascader.swift b/Sources/SourceGraph/Mutators/AccessibilityCascader.swift index 8b12bb580..2dceacfe9 100644 --- a/Sources/SourceGraph/Mutators/AccessibilityCascader.swift +++ b/Sources/SourceGraph/Mutators/AccessibilityCascader.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class AccessibilityCascader: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/AncestralReferenceEliminator.swift b/Sources/SourceGraph/Mutators/AncestralReferenceEliminator.swift index dccc97cdf..0a9a2701d 100644 --- a/Sources/SourceGraph/Mutators/AncestralReferenceEliminator.swift +++ b/Sources/SourceGraph/Mutators/AncestralReferenceEliminator.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class AncestralReferenceEliminator: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/AssetReferenceRetainer.swift b/Sources/SourceGraph/Mutators/AssetReferenceRetainer.swift index 3d96aef5a..2d3f87d24 100644 --- a/Sources/SourceGraph/Mutators/AssetReferenceRetainer.swift +++ b/Sources/SourceGraph/Mutators/AssetReferenceRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration /// Retains references from non-Swift assets, such as interface builder, Info.plist and CoreData models. final class AssetReferenceRetainer: SourceGraphMutator { diff --git a/Sources/SourceGraph/Mutators/AssignOnlyPropertyReferenceEliminator.swift b/Sources/SourceGraph/Mutators/AssignOnlyPropertyReferenceEliminator.swift index 64f1d58a7..29cf8e3c7 100644 --- a/Sources/SourceGraph/Mutators/AssignOnlyPropertyReferenceEliminator.swift +++ b/Sources/SourceGraph/Mutators/AssignOnlyPropertyReferenceEliminator.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class AssignOnlyPropertyReferenceEliminator: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/CapitalSelfFunctionCallRetainer.swift b/Sources/SourceGraph/Mutators/CapitalSelfFunctionCallRetainer.swift index 8c3093ae9..aadea037a 100644 --- a/Sources/SourceGraph/Mutators/CapitalSelfFunctionCallRetainer.swift +++ b/Sources/SourceGraph/Mutators/CapitalSelfFunctionCallRetainer.swift @@ -1,6 +1,6 @@ import Foundation -import Shared - +import Configuration +import Utils /// Retains all constructors on types instantiated via `Self(...)` to workaround false positives caused by a bug in Swift. /// https://github.com/apple/swift/issues/64686 /// https://github.com/peripheryapp/periphery/issues/264 diff --git a/Sources/SourceGraph/Mutators/CodablePropertyRetainer.swift b/Sources/SourceGraph/Mutators/CodablePropertyRetainer.swift index fa67174ac..1d9b56a04 100644 --- a/Sources/SourceGraph/Mutators/CodablePropertyRetainer.swift +++ b/Sources/SourceGraph/Mutators/CodablePropertyRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class CodablePropertyRetainer: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/CodingKeyEnumReferenceBuilder.swift b/Sources/SourceGraph/Mutators/CodingKeyEnumReferenceBuilder.swift index 163d7864a..8fe61b203 100644 --- a/Sources/SourceGraph/Mutators/CodingKeyEnumReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/CodingKeyEnumReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration /// Builds a reference from a `Codable` conforming type to any child enum that conforms to `CodingKey`. final class CodingKeyEnumReferenceBuilder: SourceGraphMutator { diff --git a/Sources/SourceGraph/Mutators/ComplexPropertyAccessorReferenceBuilder.swift b/Sources/SourceGraph/Mutators/ComplexPropertyAccessorReferenceBuilder.swift index ed7c65917..34d5f879b 100644 --- a/Sources/SourceGraph/Mutators/ComplexPropertyAccessorReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/ComplexPropertyAccessorReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration // Builds references to getters and setters from complex properties. A complex property is one that // explicitly implements a get, set, willSet or didSet. Accessors are distinct declarations and hold diff --git a/Sources/SourceGraph/Mutators/DefaultConstructorReferenceBuilder.swift b/Sources/SourceGraph/Mutators/DefaultConstructorReferenceBuilder.swift index e17a7f7ee..0f63e89e6 100644 --- a/Sources/SourceGraph/Mutators/DefaultConstructorReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/DefaultConstructorReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class DefaultConstructorReferenceBuilder: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/DynamicMemberLookupReferenceBuilder.swift b/Sources/SourceGraph/Mutators/DynamicMemberLookupReferenceBuilder.swift index 202201fa4..787b74cac 100644 --- a/Sources/SourceGraph/Mutators/DynamicMemberLookupReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/DynamicMemberLookupReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class DynamicMemberLookupReferenceBuilder: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/EntryPointAttributeRetainer.swift b/Sources/SourceGraph/Mutators/EntryPointAttributeRetainer.swift index 6b1a5dc15..dd4c30ce1 100644 --- a/Sources/SourceGraph/Mutators/EntryPointAttributeRetainer.swift +++ b/Sources/SourceGraph/Mutators/EntryPointAttributeRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class EntryPointAttributeRetainer: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/EnumCaseReferenceBuilder.swift b/Sources/SourceGraph/Mutators/EnumCaseReferenceBuilder.swift index 468e9535e..ae3ce8b66 100644 --- a/Sources/SourceGraph/Mutators/EnumCaseReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/EnumCaseReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration /// Builds references to enum cases of enums that are raw representable. final class EnumCaseReferenceBuilder: SourceGraphMutator { diff --git a/Sources/SourceGraph/Mutators/ExtensionReferenceBuilder.swift b/Sources/SourceGraph/Mutators/ExtensionReferenceBuilder.swift index 47363b36a..096cdc602 100644 --- a/Sources/SourceGraph/Mutators/ExtensionReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/ExtensionReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration /// Folds all references and declarations that exist within an extension into the /// class/struct that is being extended and removes the extension declaration. diff --git a/Sources/SourceGraph/Mutators/ExternalTypeProtocolConformanceReferenceRemover.swift b/Sources/SourceGraph/Mutators/ExternalTypeProtocolConformanceReferenceRemover.swift index b3db554bb..999de805c 100644 --- a/Sources/SourceGraph/Mutators/ExternalTypeProtocolConformanceReferenceRemover.swift +++ b/Sources/SourceGraph/Mutators/ExternalTypeProtocolConformanceReferenceRemover.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class ExternalTypeProtocolConformanceReferenceRemover: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/GenericClassAndStructConstructorReferenceBuilder.swift b/Sources/SourceGraph/Mutators/GenericClassAndStructConstructorReferenceBuilder.swift index f59a0fb99..243585e3e 100644 --- a/Sources/SourceGraph/Mutators/GenericClassAndStructConstructorReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/GenericClassAndStructConstructorReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration /// https://github.com/apple/swift/issues/54532 /// Constructors on a class/struct with generic type parameters are not referenced despite being used. diff --git a/Sources/SourceGraph/Mutators/ObjCAccessibleRetainer.swift b/Sources/SourceGraph/Mutators/ObjCAccessibleRetainer.swift index cc013a5d5..16534d48e 100644 --- a/Sources/SourceGraph/Mutators/ObjCAccessibleRetainer.swift +++ b/Sources/SourceGraph/Mutators/ObjCAccessibleRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class ObjCAccessibleRetainer: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/PropertyWrapperRetainer.swift b/Sources/SourceGraph/Mutators/PropertyWrapperRetainer.swift index a3a313d27..ed29dc928 100644 --- a/Sources/SourceGraph/Mutators/PropertyWrapperRetainer.swift +++ b/Sources/SourceGraph/Mutators/PropertyWrapperRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class PropertyWrapperRetainer: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/ProtocolConformanceReferenceBuilder.swift b/Sources/SourceGraph/Mutators/ProtocolConformanceReferenceBuilder.swift index 36d4a505e..950ec3c30 100644 --- a/Sources/SourceGraph/Mutators/ProtocolConformanceReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/ProtocolConformanceReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class ProtocolConformanceReferenceBuilder: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/ProtocolExtensionReferenceBuilder.swift b/Sources/SourceGraph/Mutators/ProtocolExtensionReferenceBuilder.swift index 46681dead..6fa4cdd16 100644 --- a/Sources/SourceGraph/Mutators/ProtocolExtensionReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/ProtocolExtensionReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class ProtocolExtensionReferenceBuilder: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/PubliclyAccessibleRetainer.swift b/Sources/SourceGraph/Mutators/PubliclyAccessibleRetainer.swift index 80e8ca712..e0b226edf 100644 --- a/Sources/SourceGraph/Mutators/PubliclyAccessibleRetainer.swift +++ b/Sources/SourceGraph/Mutators/PubliclyAccessibleRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class PubliclyAccessibleRetainer: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/RedundantExplicitPublicAccessibilityMarker.swift b/Sources/SourceGraph/Mutators/RedundantExplicitPublicAccessibilityMarker.swift index 7bc0becaf..7334e978c 100644 --- a/Sources/SourceGraph/Mutators/RedundantExplicitPublicAccessibilityMarker.swift +++ b/Sources/SourceGraph/Mutators/RedundantExplicitPublicAccessibilityMarker.swift @@ -1,4 +1,5 @@ import Shared +import Configuration final class RedundantExplicitPublicAccessibilityMarker: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/RedundantProtocolMarker.swift b/Sources/SourceGraph/Mutators/RedundantProtocolMarker.swift index 4d3caf318..73637c9f9 100644 --- a/Sources/SourceGraph/Mutators/RedundantProtocolMarker.swift +++ b/Sources/SourceGraph/Mutators/RedundantProtocolMarker.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration /// A protocol is considered redundant when it's never used as an existential type, despite being conformed to. final class RedundantProtocolMarker: SourceGraphMutator { diff --git a/Sources/SourceGraph/Mutators/ResultBuilderRetainer.swift b/Sources/SourceGraph/Mutators/ResultBuilderRetainer.swift index 055c4bf21..7b94a1aa2 100644 --- a/Sources/SourceGraph/Mutators/ResultBuilderRetainer.swift +++ b/Sources/SourceGraph/Mutators/ResultBuilderRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration /// Retains static methods used by the Result Builder language feature. final class ResultBuilderRetainer: SourceGraphMutator { diff --git a/Sources/SourceGraph/Mutators/StringInterpolationAppendInterpolationRetainer.swift b/Sources/SourceGraph/Mutators/StringInterpolationAppendInterpolationRetainer.swift index 46c42ae26..b7db6d419 100644 --- a/Sources/SourceGraph/Mutators/StringInterpolationAppendInterpolationRetainer.swift +++ b/Sources/SourceGraph/Mutators/StringInterpolationAppendInterpolationRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration // https://github.com/apple/swift/issues/56189 // The index store does not contain references to `appendInterpolation` functions from their use in string literals. diff --git a/Sources/SourceGraph/Mutators/StructImplicitInitializerReferenceBuilder.swift b/Sources/SourceGraph/Mutators/StructImplicitInitializerReferenceBuilder.swift index ed6852423..eadb6220c 100644 --- a/Sources/SourceGraph/Mutators/StructImplicitInitializerReferenceBuilder.swift +++ b/Sources/SourceGraph/Mutators/StructImplicitInitializerReferenceBuilder.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration /// Builds references from struct implicit initializers to the properties it assigns. final class StructImplicitInitializerReferenceBuilder: SourceGraphMutator { diff --git a/Sources/SourceGraph/Mutators/SwiftUIRetainer.swift b/Sources/SourceGraph/Mutators/SwiftUIRetainer.swift index 646f8d7e8..b21bcf04d 100644 --- a/Sources/SourceGraph/Mutators/SwiftUIRetainer.swift +++ b/Sources/SourceGraph/Mutators/SwiftUIRetainer.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class SwiftUIRetainer: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/UnusedImportMarker.swift b/Sources/SourceGraph/Mutators/UnusedImportMarker.swift index ec0dc1c73..a43a5d342 100644 --- a/Sources/SourceGraph/Mutators/UnusedImportMarker.swift +++ b/Sources/SourceGraph/Mutators/UnusedImportMarker.swift @@ -1,5 +1,6 @@ import Foundation import Shared +import Configuration /// Marks unused import statements (experimental). /// diff --git a/Sources/SourceGraph/Mutators/UnusedParameterRetainer.swift b/Sources/SourceGraph/Mutators/UnusedParameterRetainer.swift index 1d84f2afe..6b1f1ead4 100644 --- a/Sources/SourceGraph/Mutators/UnusedParameterRetainer.swift +++ b/Sources/SourceGraph/Mutators/UnusedParameterRetainer.swift @@ -1,5 +1,6 @@ import Foundation import Shared +import Configuration final class UnusedParameterRetainer: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/UsedDeclarationMarker.swift b/Sources/SourceGraph/Mutators/UsedDeclarationMarker.swift index f7bc024d7..396eaf374 100644 --- a/Sources/SourceGraph/Mutators/UsedDeclarationMarker.swift +++ b/Sources/SourceGraph/Mutators/UsedDeclarationMarker.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration final class UsedDeclarationMarker: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/Mutators/XCTestRetainer.swift b/Sources/SourceGraph/Mutators/XCTestRetainer.swift index 5a0242766..29940ad8f 100644 --- a/Sources/SourceGraph/Mutators/XCTestRetainer.swift +++ b/Sources/SourceGraph/Mutators/XCTestRetainer.swift @@ -1,5 +1,6 @@ import Foundation import Shared +import Configuration final class XCTestRetainer: SourceGraphMutator { private let graph: SourceGraph diff --git a/Sources/SourceGraph/SourceGraph.swift b/Sources/SourceGraph/SourceGraph.swift index 9c5b1109f..d8619e66b 100644 --- a/Sources/SourceGraph/SourceGraph.swift +++ b/Sources/SourceGraph/SourceGraph.swift @@ -1,5 +1,6 @@ import Foundation import Shared +import Configuration public final class SourceGraph { // Global shared instance to prevent costly deinitialization. diff --git a/Sources/SourceGraph/SourceGraphMutator.swift b/Sources/SourceGraph/SourceGraphMutator.swift index 4d7080531..75325cce4 100644 --- a/Sources/SourceGraph/SourceGraphMutator.swift +++ b/Sources/SourceGraph/SourceGraphMutator.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Configuration protocol SourceGraphMutator: AnyObject { init(graph: SourceGraph, configuration: Configuration) diff --git a/Sources/SourceGraph/SourceGraphMutatorRunner.swift b/Sources/SourceGraph/SourceGraphMutatorRunner.swift index 311fd9bf0..cb9c6a8b6 100644 --- a/Sources/SourceGraph/SourceGraphMutatorRunner.swift +++ b/Sources/SourceGraph/SourceGraphMutatorRunner.swift @@ -1,5 +1,7 @@ import Foundation import Shared +import Utils +import Configuration public final class SourceGraphMutatorRunner { public static func perform(graph: SourceGraph) throws { diff --git a/Sources/Shared/Extensions/FilePath+Glob.swift b/Sources/Utils/FilePath+Glob.swift similarity index 100% rename from Sources/Shared/Extensions/FilePath+Glob.swift rename to Sources/Utils/FilePath+Glob.swift diff --git a/Sources/Utils/Logger+Configuration.swift b/Sources/Utils/Logger+Configuration.swift new file mode 100644 index 000000000..08c99ad34 --- /dev/null +++ b/Sources/Utils/Logger+Configuration.swift @@ -0,0 +1,11 @@ +//import Logger +//import Configuration +// +//public extension Logger { +// convenience init() { +// self.init( +// quiet: Configuration.shared.quiet, +// verbose: Configuration.shared.verbose +// ) +// } +//} diff --git a/Sources/Shared/Logger.swift b/Sources/Utils/Logger.swift similarity index 62% rename from Sources/Shared/Logger.swift rename to Sources/Utils/Logger.swift index c5821169b..b299e3b82 100644 --- a/Sources/Shared/Logger.swift +++ b/Sources/Utils/Logger.swift @@ -1,85 +1,11 @@ import Foundation +import BaseLogger +import Configuration #if canImport(os) import os #endif -public enum ANSIColor: String { - case bold = "\u{001B}[0;1m" - case red = "\u{001B}[0;31m" - case boldRed = "\u{001B}[0;1;31m" - case green = "\u{001B}[0;32m" - case boldGreen = "\u{001B}[0;1;32m" - case yellow = "\u{001B}[0;33m" - case boldYellow = "\u{001B}[0;1;33m" - case blue = "\u{001B}[0;34m" - case lightBlue = "\u{001B}[1;34m" - case magenta = "\u{001B}[0;35m" - case boldMagenta = "\u{001B}[0;1;35m" - case cyan = "\u{001B}[0;36m" - case white = "\u{001B}[0;37m" - case gray = "\u{001B}[0;1;30m" -} - -@usableFromInline var isColorOutputCapable: Bool = { - guard let term = ProcessInfo.processInfo.environment["TERM"], - term.lowercased() != "dumb", - isatty(fileno(stdout)) != 0 - else { - return false - } - - return true -}() - -@inlinable -public func colorize(_ text: String, _ color: ANSIColor) -> String { - guard isColorOutputCapable else { return text } - return "\(color.rawValue)\(text)\u{001B}[0;0m" -} - -public final class BaseLogger { - public static let shared = BaseLogger() - - @usableFromInline let outputQueue: DispatchQueue - - private init() { - outputQueue = DispatchQueue(label: "BaseLogger.outputQueue") - } - - @inlinable - func info(_ text: String) { - log(text, output: stdout) - } - - @inlinable - func debug(_ text: String) { - log(text, output: stdout) - } - - @inlinable - func warn(_ text: String, newlinePrefix: Bool = false) { - if newlinePrefix { - log("", output: stderr) - } - let text = colorize("warning: ", .boldYellow) + text - log(text, output: stderr) - } - - @inlinable - func error(_ text: String) { - let text = colorize("error: ", .boldRed) + text - log(text, output: stderr) - } - - // MARK: - Private - - @inlinable - func log(_ line: String, output: UnsafeMutablePointer) { - _ = outputQueue.sync { fputs(line + "\n", output) } - } -} - public final class Logger { public static func configureBuffering() { var info = stat() diff --git a/Sources/Shared/Shell.swift b/Sources/Utils/Shell.swift similarity index 99% rename from Sources/Shared/Shell.swift rename to Sources/Utils/Shell.swift index 86c602c9b..799630f5f 100644 --- a/Sources/Shared/Shell.swift +++ b/Sources/Utils/Shell.swift @@ -1,4 +1,6 @@ import Foundation +import Shared +import Utils open class Shell { public static let shared: Shell = .init(environment: ProcessInfo.processInfo.environment, logger: Logger()) diff --git a/Sources/Shared/Extensions/String+Version.swift b/Sources/Utils/String+Version.swift similarity index 100% rename from Sources/Shared/Extensions/String+Version.swift rename to Sources/Utils/String+Version.swift diff --git a/Sources/Shared/SwiftVersion.swift b/Sources/Utils/SwiftVersion.swift similarity index 98% rename from Sources/Shared/SwiftVersion.swift rename to Sources/Utils/SwiftVersion.swift index dbc711867..ae1d5b819 100644 --- a/Sources/Shared/SwiftVersion.swift +++ b/Sources/Utils/SwiftVersion.swift @@ -1,4 +1,5 @@ import Foundation +import Shared public struct SwiftVersion { public static let current = SwiftVersion() diff --git a/Sources/Shared/SwiftVersionParser.swift b/Sources/Utils/SwiftVersionParser.swift similarity index 96% rename from Sources/Shared/SwiftVersionParser.swift rename to Sources/Utils/SwiftVersionParser.swift index ad484c00e..fe4cda555 100644 --- a/Sources/Shared/SwiftVersionParser.swift +++ b/Sources/Utils/SwiftVersionParser.swift @@ -1,4 +1,5 @@ import Foundation +import Shared enum SwiftVersionParser { static func parse(_ fullVersion: String) throws -> VersionString { diff --git a/Sources/XcodeSupport/XcodeProject.swift b/Sources/XcodeSupport/XcodeProject.swift index de3b8f3a6..6808d1e44 100644 --- a/Sources/XcodeSupport/XcodeProject.swift +++ b/Sources/XcodeSupport/XcodeProject.swift @@ -2,6 +2,7 @@ import Foundation import Shared import SystemPackage import XcodeProj +import Utils public final class XcodeProject: XcodeProjectlike { private static var cache: [FilePath: XcodeProject] = [:] diff --git a/Sources/XcodeSupport/XcodeProjectSetupGuide.swift b/Sources/XcodeSupport/XcodeProjectSetupGuide.swift index 88bf394ad..10aef7752 100644 --- a/Sources/XcodeSupport/XcodeProjectSetupGuide.swift +++ b/Sources/XcodeSupport/XcodeProjectSetupGuide.swift @@ -1,6 +1,8 @@ import Foundation import Shared import SystemPackage +import Configuration +import BaseLogger public final class XcodeProjectSetupGuide: SetupGuideHelpers, SetupGuide { public static func detect() -> Self? { diff --git a/Sources/XcodeSupport/XcodeWorkspace.swift b/Sources/XcodeSupport/XcodeWorkspace.swift index f81be4a31..8847e0dfe 100644 --- a/Sources/XcodeSupport/XcodeWorkspace.swift +++ b/Sources/XcodeSupport/XcodeWorkspace.swift @@ -2,6 +2,8 @@ import Foundation import Shared import SystemPackage import XcodeProj +import Configuration +import Utils public final class XcodeWorkspace: XcodeProjectlike { public let type: String = "workspace" diff --git a/Sources/XcodeSupport/Xcodebuild.swift b/Sources/XcodeSupport/Xcodebuild.swift index 5a2117dac..6055abcc9 100644 --- a/Sources/XcodeSupport/Xcodebuild.swift +++ b/Sources/XcodeSupport/Xcodebuild.swift @@ -1,6 +1,7 @@ import Foundation import Shared import SystemPackage +import Utils public final class Xcodebuild { private let shell: Shell diff --git a/Tests/PeripheryTests/RetentionTest.swift b/Tests/PeripheryTests/RetentionTest.swift index 1c48227e0..1a0655ef4 100644 --- a/Tests/PeripheryTests/RetentionTest.swift +++ b/Tests/PeripheryTests/RetentionTest.swift @@ -1,6 +1,6 @@ -import Shared import SystemPackage @testable import TestShared +import Configuration import XCTest final class RetentionTest: FixtureSourceGraphTestCase { diff --git a/Tests/PeripheryTests/ShellTest.swift b/Tests/PeripheryTests/ShellTest.swift index 88b091bc5..5937af9d6 100644 --- a/Tests/PeripheryTests/ShellTest.swift +++ b/Tests/PeripheryTests/ShellTest.swift @@ -1,4 +1,4 @@ -@testable import Shared +@testable import Utils import XCTest final class ShellTest: XCTestCase { diff --git a/Tests/PeripheryTests/SwiftVersionParserTest.swift b/Tests/PeripheryTests/SwiftVersionParserTest.swift index 4788c19e7..fce4c054e 100644 --- a/Tests/PeripheryTests/SwiftVersionParserTest.swift +++ b/Tests/PeripheryTests/SwiftVersionParserTest.swift @@ -1,5 +1,5 @@ import Foundation -@testable import Shared +@testable import Utils import XCTest final class SwiftVersionParserTest: XCTestCase { diff --git a/Tests/Shared/SPMSourceGraphTestCase.swift b/Tests/Shared/SPMSourceGraphTestCase.swift index 8275abd44..5edc4e73a 100644 --- a/Tests/Shared/SPMSourceGraphTestCase.swift +++ b/Tests/Shared/SPMSourceGraphTestCase.swift @@ -2,6 +2,7 @@ import Foundation import ProjectDrivers import Shared import SystemPackage +import Utils class SPMSourceGraphTestCase: SourceGraphTestCase { static func build(projectPath: FilePath = ProjectRootPath) { diff --git a/Tests/Shared/SourceGraphTestCase.swift b/Tests/Shared/SourceGraphTestCase.swift index 237c96619..8f202b973 100644 --- a/Tests/Shared/SourceGraphTestCase.swift +++ b/Tests/Shared/SourceGraphTestCase.swift @@ -2,6 +2,8 @@ @testable import PeripheryKit import Shared @testable import SourceGraph +import Configuration +import Utils import SystemPackage import XCTest diff --git a/Tests/XcodeTests/ShellMock.swift b/Tests/XcodeTests/ShellMock.swift index 6a7e23acc..15dd0dbbe 100644 --- a/Tests/XcodeTests/ShellMock.swift +++ b/Tests/XcodeTests/ShellMock.swift @@ -1,5 +1,5 @@ import Foundation -import Shared +import Utils class ShellMock: Shell { var output: String = "" diff --git a/Tests/XcodeTests/XcodeSourceGraphTestCase.swift b/Tests/XcodeTests/XcodeSourceGraphTestCase.swift index 43fe207b3..e040aa7fc 100644 --- a/Tests/XcodeTests/XcodeSourceGraphTestCase.swift +++ b/Tests/XcodeTests/XcodeSourceGraphTestCase.swift @@ -1,6 +1,7 @@ import Foundation import ProjectDrivers import Shared +import Utils import SystemPackage @testable import TestShared diff --git a/Tests/XcodeTests/XcodebuildBuildProjectTest.swift b/Tests/XcodeTests/XcodebuildBuildProjectTest.swift index 29ffd7497..c6ce517aa 100644 --- a/Tests/XcodeTests/XcodebuildBuildProjectTest.swift +++ b/Tests/XcodeTests/XcodebuildBuildProjectTest.swift @@ -1,5 +1,4 @@ import Foundation -import Shared @testable import XcodeSupport import XCTest