Skip to content

Commit

Permalink
Added public api
Browse files Browse the repository at this point in the history
  • Loading branch information
rofle100lvl committed Sep 30, 2024
1 parent e8d41f3 commit 115f2b0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 22 deletions.
20 changes: 19 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var targets: [PackageDescription.Target] = [
.executableTarget(
name: "Frontend",
dependencies: [
.target(name: "Scan"),
.target(name: "Shared"),
.target(name: "Configuration"),
.target(name: "SourceGraph"),
Expand Down Expand Up @@ -114,6 +115,18 @@ var targets: [PackageDescription.Target] = [
.product(name: "FilenameMatcher", package: "swift-filename-matcher"),
]
),
.target(
name: "Scan",
dependencies: [
.target(name: "Configuration"),
.target(name: "Indexer"),
.target(name: "PeripheryKit"),
.target(name: "ProjectDrivers"),
.target(name: "Shared"),
.target(name: "SourceGraph"),
.target(name: "Logger"),
]
),
.target(
name: "TestShared",
dependencies: [
Expand Down Expand Up @@ -176,7 +189,12 @@ let package = Package(
platforms: [.macOS(.v13)],
products: [
.executable(name: "periphery", targets: ["Frontend"]),
.library(name: "PeripheryKit", targets: ["PeripheryKit"]),
.library(name: "PeripheryKit", targets: [
"SourceGraph",
"Configuration",
"ProjectDrivers",
"Scan",
]),
],
dependencies: dependencies,
targets: targets,
Expand Down
2 changes: 2 additions & 0 deletions Sources/Frontend/Commands/ScanCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Configuration
import Foundation
import Logger
import PeripheryKit
import ProjectDrivers
import Scan
import Shared
import SystemPackage

Expand Down
1 change: 1 addition & 0 deletions Sources/Frontend/GuidedSetup.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Configuration
import Foundation
import Logger
import ProjectDrivers
import Shared

#if canImport(XcodeSupport)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
import Configuration
import Foundation
import Logger
import ProjectDrivers
import Shared
import SystemPackage

final class Project {
public final class Project {
let kind: ProjectKind

private let configuration: Configuration
private let shell: Shell
private let logger: Logger

convenience init(
public convenience init(
configuration: Configuration,
shell: Shell,
logger: Logger
) throws {
try self.init(
kind: Self.detectKind(configuration: configuration),
configuration: configuration,
shell: shell,
logger: logger
)
}

public init(configuration: Configuration) throws {
self.configuration = configuration
logger = Logger()
shell = Shell(logger: logger)
kind = try Self.detectKind(configuration: configuration)
}

public init(
kind: ProjectKind,
configuration: Configuration,
shell: Shell,
logger: Logger
) {
self.kind = kind
self.configuration = configuration
self.shell = shell
self.logger = logger
}

static func detectKind(configuration: Configuration) throws -> ProjectKind {
var kind: ProjectKind?

if let path = configuration.project {
Expand All @@ -33,22 +60,10 @@ final class Project {
throw PeripheryError.usageError("Failed to identify project in the current directory. For Xcode projects use the '--project' option, and for SPM projects change to the directory containing the Package.swift.")
}

self.init(kind: kind, configuration: configuration, shell: shell, logger: logger)
}

init(
kind: ProjectKind,
configuration: Configuration,
shell: Shell,
logger: Logger
) {
self.kind = kind
self.configuration = configuration
self.shell = shell
self.logger = logger
return kind
}

func driver() throws -> ProjectDriver {
public func driver() throws -> ProjectDriver {
switch kind {
case let .xcode(projectPath):
#if canImport(XcodeSupport)
Expand Down
16 changes: 13 additions & 3 deletions Sources/Frontend/Scan.swift → Sources/Scan/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@ import ProjectDrivers
import Shared
import SourceGraph

final class Scan {
public final class Scan {
private let configuration: Configuration
private let logger: Logger
private let graph: SourceGraph
private let swiftVersion: SwiftVersion

required init(configuration: Configuration, logger: Logger, swiftVersion: SwiftVersion) {
public required init(configuration: Configuration, logger: Logger, swiftVersion: SwiftVersion) {
self.configuration = configuration
self.logger = logger
self.swiftVersion = swiftVersion
graph = SourceGraph(configuration: configuration)
}

func perform(project: Project) throws -> [ScanResult] {
public init(
configuration: Configuration,
sourceGraph: SourceGraph
) {
self.configuration = configuration
logger = Logger()
swiftVersion = .init(shell: Shell(logger: logger))
graph = sourceGraph
}

public func perform(project: Project) throws -> [ScanResult] {
if !configuration.indexStorePath.isEmpty {
logger.warn("When using the '--index-store-path' option please ensure that Xcode is not running. False-positives can occur if Xcode writes to the index store while Periphery is running.")

Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceGraph/SourceGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public final class SourceGraph {
public private(set) var extensions: [Declaration: Set<Declaration>] = [:]

private var allDeclarationsByKind: [Declaration.Kind: Set<Declaration>] = [:]
private var allExplicitDeclarationsByUsr: [String: Declaration] = [:]
public private(set) var allExplicitDeclarationsByUsr: [String: Declaration] = [:]
private var moduleToExportingModules: [String: Set<String>] = [:]

private let configuration: Configuration
Expand Down

0 comments on commit 115f2b0

Please sign in to comment.