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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First version of Public API #825

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 5 additions & 5 deletions Sources/ProjectDrivers/BazelProjectDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import Logger
import Shared
import SystemPackage

public class BazelProjectDriver: ProjectDriver {
public static var isSupported: Bool {
class BazelProjectDriver: ProjectDriver {
static var isSupported: Bool {
FilePath("MODULE.bazel").exists || FilePath("WORKSPACE").exists
}

public static func build(configuration: Configuration, shell: Shell, logger: Logger) throws -> Self {
static func build(configuration: Configuration, shell: Shell, logger: Logger) throws -> Self {
configuration.bazel = false // Generic project mode is used for the actual scan.
configuration.reportExclude.append("**/bazel-out/**/*")
return self.init(configuration: configuration, shell: shell, logger: logger)
}

private static let topLevelKinds = [
static let topLevelKinds = [
// rules_apple, iOS
"ios_app_clip",
"ios_application",
Expand Down Expand Up @@ -81,7 +81,7 @@ public class BazelProjectDriver: ProjectDriver {
self.fileManager = fileManager
}

public func build() throws {
func build() throws {
guard let executablePath = Bundle.main.executablePath else {
fatalError("Expected executable path.")
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/ProjectDrivers/GenericProjectDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Shared
import SwiftIndexStore
import SystemPackage

public final class GenericProjectDriver {
final class GenericProjectDriver {
struct GenericConfig: Decodable {
let indexstores: Set<String>
let plists: Set<String>
Expand All @@ -24,7 +24,7 @@ public final class GenericProjectDriver {
private let testTargets: Set<String>
private let configuration: Configuration

public convenience init(genericProjectConfig: FilePath, configuration: Configuration) throws {
convenience init(genericProjectConfig: FilePath, configuration: Configuration) throws {
guard genericProjectConfig.exists else {
throw PeripheryError.pathDoesNotExist(path: genericProjectConfig.string)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
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
)
}

// periphery:ignore
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 +61,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
17 changes: 14 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,31 @@ 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] {
// periphery:ignore
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
Loading