depcheck 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +50 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +37 -0
  5. data/LICENSE +21 -0
  6. data/README.md +48 -0
  7. data/Rakefile +6 -0
  8. data/bin/depcheck +16 -0
  9. data/depcheck.gemspec +25 -0
  10. data/example/Example.xcodeproj/project.pbxproj +323 -0
  11. data/example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  12. data/example/Example.xcodeproj/project.xcworkspace/xcuserdata/wojtek.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  13. data/example/Example.xcodeproj/xcuserdata/wojtek.xcuserdatad/xcschemes/Example.xcscheme +91 -0
  14. data/example/Example.xcodeproj/xcuserdata/wojtek.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
  15. data/example/Example/AppDelegate.swift +16 -0
  16. data/example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json +73 -0
  17. data/example/Example/Base.lproj/LaunchScreen.storyboard +27 -0
  18. data/example/Example/Base.lproj/Main.storyboard +26 -0
  19. data/example/Example/Info.plist +47 -0
  20. data/example/Example/Models/Model1.swift +14 -0
  21. data/example/Example/Models/Model2.swift +13 -0
  22. data/example/Example/Models/Model3.swift +13 -0
  23. data/example/Example/Models/Model4.swift +13 -0
  24. data/example/Example/Models/Model5.swift +15 -0
  25. data/example/Example/ViewController.swift +19 -0
  26. data/example/analyze.png +0 -0
  27. data/example/usage.png +0 -0
  28. data/lib/depcheck.rb +9 -0
  29. data/lib/depcheck/analyzer.rb +59 -0
  30. data/lib/depcheck/command/analyze_command.rb +17 -0
  31. data/lib/depcheck/command/usage_command.rb +17 -0
  32. data/lib/depcheck/command/version_command.rb +6 -0
  33. data/lib/depcheck/dependency_info.rb +13 -0
  34. data/lib/depcheck/finder.rb +33 -0
  35. data/lib/depcheck/output/simple_output.rb +21 -0
  36. data/lib/depcheck/version.rb +3 -0
  37. metadata +136 -0
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:Example.xcodeproj">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,91 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Scheme
3
+ LastUpgradeVersion = "0730"
4
+ version = "1.3">
5
+ <BuildAction
6
+ parallelizeBuildables = "YES"
7
+ buildImplicitDependencies = "YES">
8
+ <BuildActionEntries>
9
+ <BuildActionEntry
10
+ buildForTesting = "YES"
11
+ buildForRunning = "YES"
12
+ buildForProfiling = "YES"
13
+ buildForArchiving = "YES"
14
+ buildForAnalyzing = "YES">
15
+ <BuildableReference
16
+ BuildableIdentifier = "primary"
17
+ BlueprintIdentifier = "2E845E151D638EFE0040B44C"
18
+ BuildableName = "Example.app"
19
+ BlueprintName = "Example"
20
+ ReferencedContainer = "container:Example.xcodeproj">
21
+ </BuildableReference>
22
+ </BuildActionEntry>
23
+ </BuildActionEntries>
24
+ </BuildAction>
25
+ <TestAction
26
+ buildConfiguration = "Debug"
27
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29
+ shouldUseLaunchSchemeArgsEnv = "YES">
30
+ <Testables>
31
+ </Testables>
32
+ <MacroExpansion>
33
+ <BuildableReference
34
+ BuildableIdentifier = "primary"
35
+ BlueprintIdentifier = "2E845E151D638EFE0040B44C"
36
+ BuildableName = "Example.app"
37
+ BlueprintName = "Example"
38
+ ReferencedContainer = "container:Example.xcodeproj">
39
+ </BuildableReference>
40
+ </MacroExpansion>
41
+ <AdditionalOptions>
42
+ </AdditionalOptions>
43
+ </TestAction>
44
+ <LaunchAction
45
+ buildConfiguration = "Debug"
46
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48
+ launchStyle = "0"
49
+ useCustomWorkingDirectory = "NO"
50
+ ignoresPersistentStateOnLaunch = "NO"
51
+ debugDocumentVersioning = "YES"
52
+ debugServiceExtension = "internal"
53
+ allowLocationSimulation = "YES">
54
+ <BuildableProductRunnable
55
+ runnableDebuggingMode = "0">
56
+ <BuildableReference
57
+ BuildableIdentifier = "primary"
58
+ BlueprintIdentifier = "2E845E151D638EFE0040B44C"
59
+ BuildableName = "Example.app"
60
+ BlueprintName = "Example"
61
+ ReferencedContainer = "container:Example.xcodeproj">
62
+ </BuildableReference>
63
+ </BuildableProductRunnable>
64
+ <AdditionalOptions>
65
+ </AdditionalOptions>
66
+ </LaunchAction>
67
+ <ProfileAction
68
+ buildConfiguration = "Release"
69
+ shouldUseLaunchSchemeArgsEnv = "YES"
70
+ savedToolIdentifier = ""
71
+ useCustomWorkingDirectory = "NO"
72
+ debugDocumentVersioning = "YES">
73
+ <BuildableProductRunnable
74
+ runnableDebuggingMode = "0">
75
+ <BuildableReference
76
+ BuildableIdentifier = "primary"
77
+ BlueprintIdentifier = "2E845E151D638EFE0040B44C"
78
+ BuildableName = "Example.app"
79
+ BlueprintName = "Example"
80
+ ReferencedContainer = "container:Example.xcodeproj">
81
+ </BuildableReference>
82
+ </BuildableProductRunnable>
83
+ </ProfileAction>
84
+ <AnalyzeAction
85
+ buildConfiguration = "Debug">
86
+ </AnalyzeAction>
87
+ <ArchiveAction
88
+ buildConfiguration = "Release"
89
+ revealArchiveInOrganizer = "YES">
90
+ </ArchiveAction>
91
+ </Scheme>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>SchemeUserState</key>
6
+ <dict>
7
+ <key>Example.xcscheme</key>
8
+ <dict>
9
+ <key>orderHint</key>
10
+ <integer>0</integer>
11
+ </dict>
12
+ </dict>
13
+ <key>SuppressBuildableAutocreation</key>
14
+ <dict>
15
+ <key>2E845E151D638EFE0040B44C</key>
16
+ <dict>
17
+ <key>primary</key>
18
+ <true/>
19
+ </dict>
20
+ </dict>
21
+ </dict>
22
+ </plist>
@@ -0,0 +1,16 @@
1
+ //
2
+ // AppDelegate.swift
3
+ // Example
4
+ //
5
+ // Created by Wojtek on 16/08/2016.
6
+ // Copyright © 2016 wojteklu. All rights reserved.
7
+ //
8
+
9
+ import UIKit
10
+
11
+ @UIApplicationMain
12
+ class AppDelegate: UIResponder, UIApplicationDelegate {
13
+
14
+ var window: UIWindow?
15
+ }
16
+
@@ -0,0 +1,73 @@
1
+ {
2
+ "images" : [
3
+ {
4
+ "idiom" : "iphone",
5
+ "size" : "29x29",
6
+ "scale" : "2x"
7
+ },
8
+ {
9
+ "idiom" : "iphone",
10
+ "size" : "29x29",
11
+ "scale" : "3x"
12
+ },
13
+ {
14
+ "idiom" : "iphone",
15
+ "size" : "40x40",
16
+ "scale" : "2x"
17
+ },
18
+ {
19
+ "idiom" : "iphone",
20
+ "size" : "40x40",
21
+ "scale" : "3x"
22
+ },
23
+ {
24
+ "idiom" : "iphone",
25
+ "size" : "60x60",
26
+ "scale" : "2x"
27
+ },
28
+ {
29
+ "idiom" : "iphone",
30
+ "size" : "60x60",
31
+ "scale" : "3x"
32
+ },
33
+ {
34
+ "idiom" : "ipad",
35
+ "size" : "29x29",
36
+ "scale" : "1x"
37
+ },
38
+ {
39
+ "idiom" : "ipad",
40
+ "size" : "29x29",
41
+ "scale" : "2x"
42
+ },
43
+ {
44
+ "idiom" : "ipad",
45
+ "size" : "40x40",
46
+ "scale" : "1x"
47
+ },
48
+ {
49
+ "idiom" : "ipad",
50
+ "size" : "40x40",
51
+ "scale" : "2x"
52
+ },
53
+ {
54
+ "idiom" : "ipad",
55
+ "size" : "76x76",
56
+ "scale" : "1x"
57
+ },
58
+ {
59
+ "idiom" : "ipad",
60
+ "size" : "76x76",
61
+ "scale" : "2x"
62
+ },
63
+ {
64
+ "idiom" : "ipad",
65
+ "size" : "83.5x83.5",
66
+ "scale" : "2x"
67
+ }
68
+ ],
69
+ "info" : {
70
+ "version" : 1,
71
+ "author" : "xcode"
72
+ }
73
+ }
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
3
+ <dependencies>
4
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
5
+ </dependencies>
6
+ <scenes>
7
+ <!--View Controller-->
8
+ <scene sceneID="EHf-IW-A2E">
9
+ <objects>
10
+ <viewController id="01J-lp-oVM" sceneMemberID="viewController">
11
+ <layoutGuides>
12
+ <viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
13
+ <viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
14
+ </layoutGuides>
15
+ <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
16
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
17
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18
+ <animations/>
19
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
20
+ </view>
21
+ </viewController>
22
+ <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
23
+ </objects>
24
+ <point key="canvasLocation" x="53" y="375"/>
25
+ </scene>
26
+ </scenes>
27
+ </document>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
3
+ <dependencies>
4
+ <deployment identifier="iOS"/>
5
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
6
+ </dependencies>
7
+ <scenes>
8
+ <!--View Controller-->
9
+ <scene sceneID="tne-QT-ifu">
10
+ <objects>
11
+ <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
12
+ <layoutGuides>
13
+ <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
14
+ <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
15
+ </layoutGuides>
16
+ <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
17
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
18
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
20
+ </view>
21
+ </viewController>
22
+ <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
23
+ </objects>
24
+ </scene>
25
+ </scenes>
26
+ </document>
@@ -0,0 +1,47 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>en</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>APPL</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleSignature</key>
20
+ <string>????</string>
21
+ <key>CFBundleVersion</key>
22
+ <string>1</string>
23
+ <key>LSRequiresIPhoneOS</key>
24
+ <true/>
25
+ <key>UILaunchStoryboardName</key>
26
+ <string>LaunchScreen</string>
27
+ <key>UIMainStoryboardFile</key>
28
+ <string>Main</string>
29
+ <key>UIRequiredDeviceCapabilities</key>
30
+ <array>
31
+ <string>armv7</string>
32
+ </array>
33
+ <key>UISupportedInterfaceOrientations</key>
34
+ <array>
35
+ <string>UIInterfaceOrientationPortrait</string>
36
+ <string>UIInterfaceOrientationLandscapeLeft</string>
37
+ <string>UIInterfaceOrientationLandscapeRight</string>
38
+ </array>
39
+ <key>UISupportedInterfaceOrientations~ipad</key>
40
+ <array>
41
+ <string>UIInterfaceOrientationPortrait</string>
42
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
43
+ <string>UIInterfaceOrientationLandscapeLeft</string>
44
+ <string>UIInterfaceOrientationLandscapeRight</string>
45
+ </array>
46
+ </dict>
47
+ </plist>
@@ -0,0 +1,14 @@
1
+ //
2
+ // Model.swift
3
+ // Example
4
+ //
5
+ // Created by Wojtek on 16/08/2016.
6
+ // Copyright © 2016 wojteklu. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ struct Model1 {
12
+ var model2 = Model2()
13
+ var model3 = Model3()
14
+ }
@@ -0,0 +1,13 @@
1
+ //
2
+ // Model.swift
3
+ // Example
4
+ //
5
+ // Created by Wojtek on 16/08/2016.
6
+ // Copyright © 2016 wojteklu. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ struct Model2 {
12
+
13
+ }
@@ -0,0 +1,13 @@
1
+ //
2
+ // Model.swift
3
+ // Example
4
+ //
5
+ // Created by Wojtek on 16/08/2016.
6
+ // Copyright © 2016 wojteklu. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ struct Model3 {
12
+ var model2 = Model2()
13
+ }
@@ -0,0 +1,13 @@
1
+ //
2
+ // Model.swift
3
+ // Example
4
+ //
5
+ // Created by Wojtek on 16/08/2016.
6
+ // Copyright © 2016 wojteklu. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ struct Model4 {
12
+ var model1 = Model1()
13
+ }
@@ -0,0 +1,15 @@
1
+ //
2
+ // Model.swift
3
+ // Example
4
+ //
5
+ // Created by Wojtek on 16/08/2016.
6
+ // Copyright © 2016 wojteklu. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ struct Model5 {
12
+ var model1 = Model1()
13
+ var model2 = Model2()
14
+ var model3 = Model3()
15
+ }
@@ -0,0 +1,19 @@
1
+ //
2
+ // ViewController.swift
3
+ // Example
4
+ //
5
+ // Created by Wojtek on 16/08/2016.
6
+ // Copyright © 2016 wojteklu. All rights reserved.
7
+ //
8
+
9
+ import UIKit
10
+
11
+ class ViewController: UIViewController {
12
+ var model1: Model1!
13
+ var model2: Model2!
14
+
15
+ private func test() {
16
+ _ = Model3()
17
+ _ = Model4()
18
+ }
19
+ }
Binary file
data/example/usage.png ADDED
Binary file
data/lib/depcheck.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'depcheck/finder'
2
+ require 'depcheck/analyzer'
3
+ require 'depcheck/dependency_info'
4
+ require 'depcheck/output/simple_output'
5
+
6
+ module Depcheck
7
+ Encoding.default_external = 'utf-8'
8
+
9
+ end
@@ -0,0 +1,59 @@
1
+ require 'yaml'
2
+
3
+ module Depcheck
4
+ module Analyzer
5
+
6
+ def self.generate_dependencies(swiftdeps)
7
+ results = []
8
+ usage = {}
9
+
10
+ swiftdeps.each do |my_text_file|
11
+ begin
12
+ dependencies = YAML.load_file(my_text_file)
13
+ rescue
14
+ next
15
+ end
16
+
17
+ provides = dependencies['provides-top-level']
18
+ nominals = dependencies['provides-nominal']
19
+ depends = dependencies['depends-top-level']
20
+ depends_member = dependencies['depends-member']
21
+
22
+ if provides.nil? || nominals.nil? || provides.count != nominals.count
23
+ next
24
+ end
25
+
26
+ provides.zip(nominals).each do |name, nominal|
27
+ dependencies = []
28
+
29
+ depends_member.each do |d|
30
+ if d[0] == nominal && depends.include?(d[1]) && valid_dep?(d[1])
31
+ dependencies << d[1]
32
+ usage[d[1]] = usage[d[1]].to_i + 1
33
+ end
34
+ end
35
+
36
+ results << DependencyInfo.new(name, nominal, dependencies)
37
+ end
38
+ end
39
+
40
+ results.each do |r|
41
+ value = usage[r.name]
42
+ r.usage = value if value
43
+ end
44
+
45
+ results
46
+ end
47
+
48
+ def self.valid_dep?(dep)
49
+ !dep.nil? && !/^(<\s)?\w/.match(dep).nil? && !keyword?(dep) && /^(CA|CF|CG|CI|CL|kCA|NS|UI)/.match(dep).nil?
50
+ end
51
+ private_class_method :valid_dep?
52
+
53
+ def self.keyword?(dep)
54
+ /^(Any|AnyBidirectionalCollection|AnyBidirectionalIndex|AnyClass|AnyForwardCollection|AnyForwardIndex|AnyObject|AnyRandomAccessCollection|AnyRandomAccessIndex|AnySequence|Array|ArraySlice|AutoreleasingUnsafeMutablePointer|BOOL|Bool|BooleanLiteralType|CBool|CChar|CChar16|CChar32|CDouble|CFloat|CInt|CLong|CLongLong|COpaquePointer|CShort|CSignedChar|CUnsignedChar|CUnsignedInt|CUnsignedLong|CUnsignedLongLong|CUnsignedShort|CVaListPointer|CWideChar|Character|ClosedInterval|ClusterType|CollectionOfOne|ContiguousArray|DISPATCH_|Dictionary|DictionaryGenerator|DictionaryIndex|DictionaryLiteral|Double|EmptyGenerator|EnumerateGenerator|EnumerateSequence|ExtendedGraphemeClusterType|FlattenBidirectionalCollection|FlattenBidirectionalCollectionIndex|FlattenCollectionIndex|FlattenSequence|Float|Float32|Float64|FloatLiteralType|GeneratorSequence|HalfOpenInterval|IndexingGenerator|Int|Int16|Int32|Int64|Int8|IntMax|IntegerLiteralType|JoinGenerator|JoinSequence|LazyCollection|LazyFilterCollection|LazyFilterGenerator|LazyFilterIndex|LazyFilterSequence|LazyMapCollection|LazyMapGenerator|LazyMapSequence|LazySequence|LiteralType|ManagedBufferPointer|Mirror|MutableSlice|ObjectIdentifier|Optional|PermutationGenerator|Range|RangeGenerator|RawByte|Repeat|ReverseCollection|ReverseIndex|ReverseRandomAccessCollection|ReverseRandomAccessIndex|ScalarType|Set|SetGenerator|SetIndex|Slice|StaticString|StrideThrough|StrideThroughGenerator|StrideTo|StrideToGenerator|String|String.CharacterView|String.CharacterView.Index|String.UTF16View|String.UTF16View.Index|String.UTF8View|String.UTF8View.Index|String.UnicodeScalarView|String.UnicodeScalarView.Generator|String.UnicodeScalarView.Index|StringLiteralType|UInt|UInt16|UInt32|UInt64|UInt8|UIntMax|UTF16|UTF32|UTF8|UnicodeScalar|UnicodeScalarType|Unmanaged|UnsafeBufferPointer|UnsafeBufferPointerGenerator|UnsafeMutableBufferPointer|UnsafeMutablePointer|UnsafePointer|Void|Zip2Generator|Zip2Sequence|abs|alignof|alignofValue|anyGenerator|anyGenerator|assert|assertionFailure|debugPrint|debugPrint|dispatch_|dump|dump|fatalError|getVaList|isUniquelyReferenced|isUniquelyReferencedNonObjC|isUniquelyReferencedNonObjC|max|max|min|min|numericCast|numericCast|numericCast|numericCast|precondition|preconditionFailure|print|print|readLine|sizeof|sizeofValue|strideof|strideofValue|swap|transcode|unsafeAddressOf|unsafeBitCast|unsafeDowncast|unsafeUnwrap|withExtendedLifetime|withExtendedLifetime|withUnsafeMutablePointer|withUnsafeMutablePointers|withUnsafeMutablePointers|withUnsafePointer|withUnsafePointers|withUnsafePointers|withVaList|withVaList|zip)$/.match(dep) != nil
55
+ end
56
+ private_class_method :keyword?
57
+
58
+ end
59
+ end