static swift code analysis - the background story
TRANSCRIPT
Static Swift Code AnalysisThe Background Story
HelsinkiOS March 2017Jouni Miettunen @jomtwiZalando Helsinki
Jouni Miettunen at HelsinkiOS March, 2017 1
What
• Oriented graph of dependencies between classes
• Objective-C has objc_dep
"Class A depends on B if class A imports class B header"
Jouni Miettunen at HelsinkiOS March, 2017 2
Why
Discover real (sub) architecture
• New features with existing APIs
• Maintenance & bug fixes
• Refactor technical dept
• Curious or new people
Jouni Miettunen at HelsinkiOS March, 2017 3
Compiled object files
• App / framework sources
• Fix project settings
• Update to latest swift
• Build project
• Parse compiled object files
• Open the graph
• Profit !!!
Jouni Miettunen at HelsinkiOS March, 2017 5
Want
• Fast
• Easy
• Configure
• Parse whatever
• Profit !!!
Jouni Miettunen at HelsinkiOS March, 2017 6
Work in progress...
Hackweek #5Zalando Open SourceHow to Open Source at Zalando
Jouni Miettunen at HelsinkiOS March, 2017 7
Phase 0: basics
• python
• One file or folder tree
• One line, regex
• Ignore
• swift keywords
• swift vs. Objective-C frameworks (71)
Jouni Miettunen at HelsinkiOS March, 2017 8
Phase 1: import framework
import-kind → typealias struct class enum protocol var func
The Swift Programming Language (Swift 3.0.1)
// Easy
import Foundation
@testable import MyFramework
// What to do
import func MyFramework.debugLog
import class MyFramework.DebugLogger
import enum MyFramework.DebugLevel
import class MyFramework.UIButton
Jouni Miettunen at HelsinkiOS March, 2017 9
Phase 2: class inheritance
• class, protocol, struct, enum
• generics, extensions, typealias
internal final class MyClass {}class SomeClass: Superclass, FirstProtocol {}open class Event <ElementA, ElementB>: EventType {}@objc protocol MyDelegate: OtherDelegate {}public protocol OwnProtocol: class {}
"Extensions can add new nested types to existing classes, structures, and enumerations"Jouni Miettunen at HelsinkiOS March, 2017 10
Phase 3: class usage
1.Definitions
2.Namespace {} and strings
3.Ignore and match
Jouni Miettunen at HelsinkiOS March, 2017 11
Phase 4: decoration
• UI via Graphviz
• Type shapes and colors
• Point of view
• Lonely
• Circular dependencies
• Risk(ish) analysis
Jouni Miettunen at HelsinkiOS March, 2017 12
Phase 5: future
• Continuous integration
• More circular dependencies
• Unused code
• Internal modules
• Any language
• Profit !!!
Jouni Miettunen at HelsinkiOS March, 2017 13
Thank You!! We're hiring, too
backendwebmobile
Profit !!!
Jouni Miettunen at HelsinkiOS March, 2017 14
The Others
• objc_dep
• Refactorator II, The App
• Objective-C Class Dependencies Visualizer
• Swift relationship graph
Jouni Miettunen at HelsinkiOS March, 2017 15