Skip to content

Commit

Permalink
add target type .auto
Browse files Browse the repository at this point in the history
  • Loading branch information
yume190 committed Aug 25, 2023
1 parent fd60a4b commit b2dd210
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ graph:
.PHONY: single
single:
leakDetect \
--targetType singleFile \
--sdk macosx \
--file temp.swift --verbose
--file fixture/temp.swift
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ let package = Package(
.product(name: "SourceKittenFramework", package: "SourceKitten"),
.product(name: "SKClient", package: "TypeFill"),
"LeakDetectKit",
"PathKit",
]
),

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,4 @@ leakDetect \
--module LeakDetectorDemo \
--targetType xcworkspace \
--file LeakDetectorDemo.xcworkspace

# Mode:
# * assign: detecting assign instance function `x = self.func` or `y(self.func)`.
# * capture: detecting capture instance in closure.
```
28 changes: 28 additions & 0 deletions Sources/LeakDetect/Arguments+Ex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ArgumentParser
import Foundation
import SKClient
import PathKit

extension Reporter: ExpressibleByArgument {
static let all: String = Reporter
Expand All @@ -24,10 +25,37 @@ public enum TargetType: String, CaseIterable, ExpressibleByArgument {
.map(\.rawValue)
.joined(separator: "|")

case auto
case xcodeproj
case xcworkspace
case singleFile
case spm

func detect(_ path: String) -> TargetType {
guard case .auto = self else {
return self
}

if path.hasSuffix(".xcodeproj") {
return .xcodeproj
}

if path.hasSuffix(".xcworkspace") {
return .xcworkspace
}

if path.hasSuffix(".swift") && !path.hasSuffix("Package.swift") {
return .singleFile
}

let path = Path(path)
let package = path + "Package.swift"
if path.isDirectory && package.exists {
return .spm
}

return .singleFile
}
}

enum Mode: String, CaseIterable, ExpressibleByArgument {
Expand Down
14 changes: 6 additions & 8 deletions Sources/LeakDetect/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ struct Command: ParsableCommand {
--module LeakDetectorDemo \
--targetType xcworkspace \
--file LeakDetectorDemo.xcworkspace
# Mode:
# * assign: detecting assign instance function `x = self.func` or `y(self.func)`.
# * capture: detecting capture instance in closure.
""",
version: "0.0.3"
)
Expand All @@ -41,7 +37,7 @@ struct Command: ParsableCommand {
var sdk: SDK = .iphonesimulator

@Option(name: [.customLong("targetType", withSingleDash: false)], help: "[\(Reporter.all)]")
var targetType: TargetType = .xcodeproj
var targetType: TargetType = .auto

@Option(name: [.customLong("module", withSingleDash: false)], help: "Name of Swift module to document (can't be used with `--single-file`)")
var moduleName = ""
Expand All @@ -60,8 +56,8 @@ struct Command: ParsableCommand {

private var module: Module? {
let moduleName = self.moduleName.isEmpty ? nil : self.moduleName

switch targetType {
switch targetType.detect(path) {
case .spm:
return Module(spmArguments: arguments, spmName: moduleName)
case .singleFile:
Expand All @@ -82,11 +78,13 @@ struct Command: ParsableCommand {
self.moduleName,
]
return Module(xcodeBuildArguments: arguments + newArgs, name: moduleName)
case .auto:
return nil
}
}

mutating func run() throws {
if case .singleFile = targetType {
if case .singleFile = targetType.detect(path) {
try SingleFilePipeline(path, arguments + [path] + sdk.pathArgs)
.detect(reporter, verbose)
return
Expand Down
12 changes: 0 additions & 12 deletions Sources/LeakDetectKit/Pipeline/Pipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,6 @@ public struct SingleFilePipeline {
let visitors = state2(client)
try client.editorOpen()
let count = try visitors.detect(client, reporter, isVerbose)
print("Found blocks: \(visitors.capture.subVisitors.count)")
// let ids = visitors.capture.leakVisitors
// .flatMap(\.ids)
// .map {
// $0.withoutTrivia().description
// }
// .joined(separator: "\n")
//
// print("""
// Found blocks:
// \(ids)
// """)
try client.editorClose()
summery(count)
}
Expand Down
File renamed without changes.

0 comments on commit b2dd210

Please sign in to comment.