Skip to content

Commit

Permalink
Extract Configuration into new target (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch authored Sep 15, 2024
1 parent 3760805 commit d8734be
Show file tree
Hide file tree
Showing 105 changed files with 279 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@master
- uses: jdx/mise-action@v2
- run: mise run lint
- run: mise run lint-ci
macOS:
strategy:
fail-fast: false
Expand Down
4 changes: 2 additions & 2 deletions .mise/tasks/lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -euo pipefail

cd $MISE_PROJECT_ROOT

swiftformat --quiet --strict .
swiftlint lint --quiet --strict
swiftformat .
swiftlint lint --quiet
8 changes: 8 additions & 0 deletions .mise/tasks/lint-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# mise description="Lint the project for CI"
set -euo pipefail

cd $MISE_PROJECT_ROOT

swiftformat --quiet --strict .
swiftlint lint --quiet --strict
25 changes: 24 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,33 @@ var targets: [PackageDescription.Target] = [
name: "Frontend",
dependencies: [
.target(name: "Shared"),
.target(name: "Configuration"),
.target(name: "SourceGraph"),
.target(name: "PeripheryKit"),
.target(name: "ProjectDrivers"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "FilenameMatcher", package: "swift-filename-matcher"),
]
),
.target(
name: "Configuration",
dependencies: [
.target(name: "Extensions"),
.target(name: "Shared"),
.target(name: "Logger"),
.product(name: "Yams", package: "Yams"),
.product(name: "SystemPackage", package: "swift-system"),
.product(name: "FilenameMatcher", package: "swift-filename-matcher"),
]
),
.target(
name: "Extensions",
dependencies: [
.product(name: "SystemPackage", package: "swift-system"),
.product(name: "FilenameMatcher", package: "swift-filename-matcher"),
]
),
.target(name: "Logger"),
.target(
name: "PeripheryKit",
dependencies: [
Expand Down Expand Up @@ -80,14 +100,16 @@ var targets: [PackageDescription.Target] = [
.target(
name: "SourceGraph",
dependencies: [
.target(name: "Configuration"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.target(name: "Shared"),
]
),
.target(
name: "Shared",
dependencies: [
.product(name: "Yams", package: "Yams"),
.target(name: "Extensions"),
.target(name: "Logger"),
.product(name: "SystemPackage", package: "swift-system"),
.product(name: "FilenameMatcher", package: "swift-filename-matcher"),
]
Expand Down Expand Up @@ -120,6 +142,7 @@ var targets: [PackageDescription.Target] = [
dependencies: [
.target(name: "TestShared"),
.target(name: "PeripheryKit"),
.target(name: "Configuration"),
],
exclude: ["AccessibilityProject"]
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Extensions
import FilenameMatcher
import Foundation
import Logger
import Shared
import SystemPackage
import Yams

Expand Down Expand Up @@ -38,7 +41,7 @@ public final class Configuration {
@Setting(key: "xcode_list_arguments", defaultValue: [])
public var xcodeListArguments: [String]

@Setting(key: "retain_assign_only_property_types", defaultValue: [], setter: PropertyTypeSanitizer.sanitize)
@Setting(key: "retain_assign_only_property_types", defaultValue: [])
public var retainAssignOnlyPropertyTypes: [String]

@Setting(key: "external_encodable_protocols", defaultValue: [])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private class Glob {
let firstPart = parts.removeFirst()
var lastPart = parts.joined(separator: "**")

var directories: [URL] = if FileManager.default.fileExists(atPath: firstPart) {
let directories: [URL] = if FileManager.default.fileExists(atPath: firstPart) {
exploreDirectories(url: URL(fileURLWithPath: firstPart))
} else {
[]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion Sources/Frontend/Commands/CheckUpdateCommand.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ArgumentParser
import Configuration
import Foundation
import Shared
import Logger

struct CheckUpdateCommand: FrontendCommand {
static let configuration = CommandConfiguration(
Expand Down
2 changes: 2 additions & 0 deletions Sources/Frontend/Commands/ClearCacheCommand.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ArgumentParser
import Configuration
import Foundation
import Logger
import Shared

struct ClearCacheCommand: FrontendCommand {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Frontend/Commands/FrontendCommand.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ArgumentParser
import Shared
import Logger

protocol FrontendCommand: ParsableCommand {}
extension FrontendCommand {
Expand Down
100 changes: 0 additions & 100 deletions Sources/Frontend/Commands/ScanBehavior.swift

This file was deleted.

72 changes: 60 additions & 12 deletions Sources/Frontend/Commands/ScanCommand.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import ArgumentParser
import Configuration
import Foundation
import Logger
import PeripheryKit
import Shared
import SystemPackage

Expand Down Expand Up @@ -135,14 +138,13 @@ struct ScanCommand: FrontendCommand {
private static let defaultConfiguration = Configuration()

func run() throws {
let logger = Logger(quiet: quiet, verbose: verbose)
logger.contextualized(with: "version").debug(PeripheryVersion)

let configuration = Configuration()
let logger = Logger(configuration: configuration)
let shell = Shell(logger: logger)
let swiftVersion = SwiftVersion(shell: shell)
let scanBehavior = ScanBehavior(configuration: configuration, logger: logger, shell: shell, swiftVersion: swiftVersion)

if !setup {
try scanBehavior.setup(config).get()
try configuration.load(from: config, logger: logger)
}

configuration.guidedSetup = setup
Expand Down Expand Up @@ -186,13 +188,59 @@ struct ScanCommand: FrontendCommand {
configuration.apply(\.$bazel, bazel)
configuration.apply(\.$bazelFilter, bazelFilter)

try scanBehavior.main { project in
try Scan(
configuration: configuration,
logger: logger,
swiftVersion: swiftVersion
).perform(project: project)
}.get()
let shell = Shell(logger: logger)
let swiftVersion = SwiftVersion(shell: shell)
logger.debug(swiftVersion.fullVersion)
try swiftVersion.validateVersion()

let project: Project = if configuration.guidedSetup {
try GuidedSetup(configuration: configuration, shell: shell, logger: logger).perform()
} else {
try Project(configuration: configuration, shell: shell, logger: logger)
}

let updateChecker = UpdateChecker(logger: logger, configuration: configuration)
updateChecker.run()

let results = try Scan(
configuration: configuration,
logger: logger,
swiftVersion: swiftVersion
).perform(project: project)

let interval = logger.beginInterval("result:output")
var baseline: Baseline?

if let baselinePath = configuration.baseline {
let data = try Data(contentsOf: baselinePath.url)
baseline = try JSONDecoder().decode(Baseline.self, from: data)
}

let filteredResults = try OutputDeclarationFilter(configuration: configuration, logger: logger).filter(results, with: baseline)

if let baselinePath = configuration.writeBaseline {
let usrs = filteredResults
.flatMapSet { $0.usrs }
.union(baseline?.usrs ?? [])
let baseline = Baseline.v1(usrs: usrs.sorted())
let data = try JSONEncoder().encode(baseline)
try data.write(to: baselinePath.url)
}

let output = try configuration.outputFormat.formatter.init(configuration: configuration).format(filteredResults)

if configuration.outputFormat.supportsAuxiliaryOutput {
logger.info("", canQuiet: true)
}

logger.info(output, canQuiet: false)
logger.endInterval(interval)

updateChecker.notifyIfAvailable()

if !filteredResults.isEmpty, configuration.strict {
throw PeripheryError.foundIssues(count: filteredResults.count)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/Frontend/CommonSetupGuide.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Configuration
import Foundation
import Logger
import Shared

final class CommonSetupGuide: SetupGuideHelpers {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Frontend/GuidedSetup.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Configuration
import Foundation
import Logger
import Shared

#if canImport(XcodeSupport)
Expand Down
9 changes: 9 additions & 0 deletions Sources/Frontend/Logger+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Configuration
import Logger

public extension Logger {
@inlinable
convenience init(configuration: Configuration) {
self.init(quiet: configuration.quiet, verbose: configuration.verbose)
}
}
2 changes: 2 additions & 0 deletions Sources/Frontend/Project.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Configuration
import Foundation
import Logger
import ProjectDrivers
import Shared
import SystemPackage
Expand Down
1 change: 1 addition & 0 deletions Sources/Frontend/SPMProjectSetupGuide.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import ProjectDrivers
import Shared
import SystemPackage

Expand Down
2 changes: 2 additions & 0 deletions Sources/Frontend/Scan.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Configuration
import Foundation
import Indexer
import Logger
import PeripheryKit
import ProjectDrivers
import Shared
Expand Down
2 changes: 2 additions & 0 deletions Sources/Frontend/UpdateChecker.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Configuration
import Foundation
import Logger
import Shared

#if canImport(FoundationNetworking)
Expand Down
Loading

0 comments on commit d8734be

Please sign in to comment.