periphery icon indicating copy to clipboard operation
periphery copied to clipboard

Analysis across local swiftpm packages in xcodeproj

Open mjarvis opened this issue 3 years ago • 3 comments

Can periphery support scanning across local SwiftPM Packages?

Test case

Example Project: PeripheryLocalPackage.zip

This project contains an xcodeproj with a mac app, which imports a local swiftPM package, and a couple of used & unused functions for testing periphery output.

periphery scan --project PeripheryLocalPackage.xcodeproj --targets PeripheryLocalPackage --schemes PeripheryLocalPackage

* No unused code detected..

I was hoping to have it detect the two unused functions in LocalPackage.swift.

Scanning the individual package

cd LocalPackage; periphery scan;

Sources/LocalPackage/LocalPackage.swift:5:13: warning: Function 'unusedPublicFunction()' is unused
Sources/LocalPackage/LocalPackage.swift:9:6: warning: Function 'unusedInternalFunction()' is unused
Sources/LocalPackage/LocalPackage.swift:13:13: warning: Function 'usedPublicFunction()' is unused
Sources/LocalPackage/LocalPackage.swift:18:6: warning: Function 'usedInternalFunction()' is unused

cd LocalPackage; periphery scan --retain-public;

Sources/LocalPackage/LocalPackage.swift:9:6: warning: Function 'unusedInternalFunction()' is unused

Scanning the individual packages is insufficient as while we can --retain-public to see the unused internal function, it cannot tell us if a public member is unused from the main target (or other modules), which is what we'd like to know.

Desired outcome from original test case:

LocalPackage/Sources/LocalPackage/LocalPackage.swift:5:13: warning: Function 'unusedPublicFunction()' is unused
LocalPackage/Sources/LocalPackage/LocalPackage.swift:9:6: warning: Function 'unusedInternalFunction()' is unused

mjarvis avatar Dec 01 '21 20:12 mjarvis

Thanks for the detailed report, and the reproduction, @mjarvis. Yes I'm afraid Periphery doesn't support local packages yet, though I think it shouldn't be too hard to implement. I'll take a look when I next have some time.

ileitch avatar Dec 04 '21 19:12 ileitch

Looking for this feature now, too! Thanks for the start, @ileitch !!

mthole avatar Feb 04 '22 19:02 mthole

Looking forward to this being implemented 😁

jorgealegre avatar Mar 03 '22 19:03 jorgealegre

YAY!

jorgealegre avatar Jan 07 '23 23:01 jorgealegre

Should this work out of the box? It doesn't seem like it's looking in my local spm's :-) Do I need to add a parameter in my yml or something?

nharbo avatar Mar 20 '23 14:03 nharbo