pod-target 0.1.3 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97308de3fd3333a54481539d7ef0acb5d696510930890c55c28ff221c2c69280
4
- data.tar.gz: 1f1c1c2823d1ecda9517fc853b1e463600efb41170d4d4b337a052c0937aff95
3
+ metadata.gz: cabccf59c7954023e0392edd2e30f65ffb2192511b27b2bbaca8451f8c09fe08
4
+ data.tar.gz: 475498fbf859ce5c2e8ab2e572bca243d4c608acb254ff8f9748251ff6821ed1
5
5
  SHA512:
6
- metadata.gz: 423cd6f323ca5d14d693a567c211e8a7748ba82352cad03c84e4453affd8805c9fbfcc50ace5913b11f933760d7054f54f957c4eab40bb3499e37df746f1cd80
7
- data.tar.gz: 03d9fb63f9b614a709e9251f9ad34ac0c25388e513ac53a9796eab929c27e16b1a1afd0e25db846cb00bd59b73b117cd8844238cbaf33b901c226d4faaa1f825
6
+ metadata.gz: 0e47a241a046b7c5afbdc55abdb973407ae849c1c07e6a7e6e8b4b4cb3f254d2aa4f3aa93924f112c9e59bf4efdd3272c690ac4552f59d0acf60d6f4791d03ba
7
+ data.tar.gz: 72d2514d303e4d9fe01ba367a161f89c90a38bb24d313e4e29150dbaec0a2dafb607f40e2cc5e115f8390b98ebddef7c022ba57835109062ad660293c1581221
@@ -1,6 +1,11 @@
1
1
  <component name="InspectionProjectProfileManager">
2
2
  <profile version="1.0">
3
3
  <option name="myName" value="Project Default" />
4
+ <inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
5
+ <Languages>
6
+ <language minSize="69" name="Ruby" />
7
+ </Languages>
8
+ </inspection_tool>
4
9
  <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
10
  </profile>
6
11
  </component>
data/.idea/modules.xml CHANGED
@@ -2,7 +2,6 @@
2
2
  <project version="4">
3
3
  <component name="ProjectModuleManager">
4
4
  <modules>
5
- <module fileurl="file://$USER_HOME$/Learning/pandan/.idea/pandan.iml" filepath="$USER_HOME$/Learning/pandan/.idea/pandan.iml" />
6
5
  <module fileurl="file://$PROJECT_DIR$/.idea/pod-target.iml" filepath="$PROJECT_DIR$/.idea/pod-target.iml" />
7
6
  </modules>
8
7
  </component>
data/.idea/pod-target.iml CHANGED
@@ -22,11 +22,13 @@
22
22
  <orderEntry type="library" scope="PROVIDED" name="necromancer (v0.3.0, RVM: ruby-2.7.0) [gem]" level="application" />
23
23
  <orderEntry type="library" scope="PROVIDED" name="pastel (v0.6.1, RVM: ruby-2.7.0) [gem]" level="application" />
24
24
  <orderEntry type="library" scope="PROVIDED" name="rake (v12.3.3, RVM: ruby-2.7.0) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.3, RVM: ruby-2.7.0) [gem]" level="application" />
25
26
  <orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, RVM: ruby-2.7.0) [gem]" level="application" />
26
27
  <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.1, RVM: ruby-2.7.0) [gem]" level="application" />
27
28
  <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, RVM: ruby-2.7.0) [gem]" level="application" />
28
29
  <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, RVM: ruby-2.7.0) [gem]" level="application" />
29
30
  <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.2, RVM: ruby-2.7.0) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="ruby-graphviz (v1.2.5, RVM: ruby-2.7.0) [gem]" level="application" />
30
32
  <orderEntry type="library" scope="PROVIDED" name="thor (v1.1.0, RVM: ruby-2.7.0) [gem]" level="application" />
31
33
  <orderEntry type="library" scope="PROVIDED" name="tty (v0.5.0, RVM: ruby-2.7.0) [gem]" level="application" />
32
34
  <orderEntry type="library" scope="PROVIDED" name="tty-color (v0.3.0, RVM: ruby-2.7.0) [gem]" level="application" />
@@ -49,16 +51,16 @@
49
51
  <option name="myRootTask">
50
52
  <RakeTaskImpl id="rake">
51
53
  <subtasks>
52
- <RakeTaskImpl description="Build pod-target-0.1.2.gem into the pkg directory" fullCommand="build" id="build" />
54
+ <RakeTaskImpl description="Build pod-target-0.1.4.gem into the pkg directory" fullCommand="build" id="build" />
53
55
  <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
54
56
  <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
55
- <RakeTaskImpl description="Build and install pod-target-0.1.2.gem into system gems" fullCommand="install" id="install" />
57
+ <RakeTaskImpl description="Build and install pod-target-0.1.4.gem into system gems" fullCommand="install" id="install" />
56
58
  <RakeTaskImpl id="install">
57
59
  <subtasks>
58
- <RakeTaskImpl description="Build and install pod-target-0.1.2.gem into system gems without network access" fullCommand="install:local" id="local" />
60
+ <RakeTaskImpl description="Build and install pod-target-0.1.4.gem into system gems without network access" fullCommand="install:local" id="local" />
59
61
  </subtasks>
60
62
  </RakeTaskImpl>
61
- <RakeTaskImpl description="Create tag v0.1.2 and build and push pod-target-0.1.2.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
63
+ <RakeTaskImpl description="Create tag v0.1.4 and build and push pod-target-0.1.4.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
62
64
  <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
63
65
  <RakeTaskImpl description="" fullCommand="default" id="default" />
64
66
  <RakeTaskImpl description="" fullCommand="release" id="release" />
data/.idea/vcs.xml CHANGED
@@ -2,5 +2,6 @@
2
2
  <project version="4">
3
3
  <component name="VcsDirectoryMappings">
4
4
  <mapping directory="" vcs="Git" />
5
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
6
  </component>
6
7
  </project>
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ gemspec
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
8
  gem 'tty'
9
+ gem 'ruby-graphviz'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pod-target (0.1.3)
4
+ pod-target (0.3.0)
5
5
  thor
6
6
  xcodeproj (~> 1.7)
7
7
 
@@ -20,6 +20,7 @@ GEM
20
20
  equatable (~> 0.5.0)
21
21
  tty-color (~> 0.3.0)
22
22
  rake (12.3.3)
23
+ rexml (3.2.3)
23
24
  rspec (3.10.0)
24
25
  rspec-core (~> 3.10.0)
25
26
  rspec-expectations (~> 3.10.0)
@@ -33,6 +34,8 @@ GEM
33
34
  diff-lcs (>= 1.2.0, < 2.0)
34
35
  rspec-support (~> 3.10.0)
35
36
  rspec-support (3.10.2)
37
+ ruby-graphviz (1.2.5)
38
+ rexml
36
39
  thor (1.1.0)
37
40
  tty (0.5.0)
38
41
  equatable (~> 0.5.0)
@@ -93,6 +96,7 @@ DEPENDENCIES
93
96
  pod-target!
94
97
  rake (~> 12.0)
95
98
  rspec (~> 3.0)
99
+ ruby-graphviz
96
100
  tty
97
101
 
98
102
  BUNDLED WITH
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Find dependencies between targets in your pod project, and output the csv file which shows dependencies that can be removed from podspec of the target.
4
4
 
5
+ X->Y means X depends on Y
6
+ ![Example image](./images/image.png)
7
+ Like the image above, we have: A->B->C and A->C. We will output the file csv named "remove_dependency.csv" to show the targets that can be removed from A. For this example, it will be like this:
8
+ A,C. The first column is the target, and the following targets are targets can be removed.
9
+
10
+ Moreover, we also draw dependency graph for specific target based on this idea. We remove all dependencies lika A->C, so we can see dependencie between targets clearer.
5
11
  ## Installation
6
12
 
7
13
  Add this line to your application's Gemfile:
@@ -19,9 +25,25 @@ Or install it yourself as:
19
25
  $ gem install pod-target
20
26
 
21
27
  ## Usage
28
+ pod-target resolve-dependency\
29
+
30
+ Options:\
31
+ [--workspace=WORKSPACE] # Set workspace path, if not set will use current directory\
32
+ \
33
+ [--output=OUTPUT] # Set output path of csv file, if not set will use current directory\
34
+ \
35
+ [--filter=expression] # If set, filter targets which name matches the regular expression\
36
+
37
+ Workspace path and output path can be absolute path or relative path
22
38
 
23
- TODO: Write usage instructions here
39
+ pod-target target\
24
40
 
41
+ Options:\
42
+ [--root=ROOT] # Set name of the root target, must be set
43
+ \
44
+ [--workspace=WORKSPACE] # Set workspace path, if not set will use current directory
45
+ \
46
+ [--output=OUTPUT] # Set output path of csv file, if not set will use current directory
25
47
  ## Development
26
48
 
27
49
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/images/image.png ADDED
Binary file
@@ -19,9 +19,21 @@ module Pod
19
19
  end
20
20
  map %w(--version -v) => :version
21
21
 
22
+ desc 'target', 'Find dependencies of the target'
23
+ method_option :root, type: :string,
24
+ desc: 'Set name of the root target, must be set'
25
+ method_option :workspace, type: :string,
26
+ desc: "Set workspace path, if not set will use current directory"
27
+ method_option :max_depth, type: :numeric,
28
+ desc: "Set max depth of the graph, if not set will traverse the whole graph"
29
+ method_option :output, type: :string,
30
+ desc: "Set output path of csv file, if not set will use current directory"
31
+ def target(*)
32
+ require_relative 'commands/target'
33
+ Pod::Target::Commands::Target.new(options).execute
34
+ end
35
+
22
36
  desc 'resolve-dependency', "Resolve dependencies of pod's targets"
23
- method_option :help, aliases: '-h', type: :boolean,
24
- desc: 'Display usage information'
25
37
  method_option :workspace, type: :string,
26
38
  desc: "Set workspace path, if not set will use current directory"
27
39
  method_option :output, type: :string,
@@ -29,12 +41,8 @@ module Pod
29
41
  method_option :filter, type: :string, banner: "expression",
30
42
  desc: "If set, filter targets which name matches the regular expression"
31
43
  def resolve_dependency(*)
32
- if options[:help]
33
- invoke :help, ['resolve-dependency']
34
- else
35
- require_relative 'commands/resolve/dependency'
36
- Pod::Target::Commands::Dependency.new(options).execute
37
- end
44
+ require_relative 'commands/dependency'
45
+ Pod::Target::Commands::Dependency.new(options).execute
38
46
  end
39
47
  end
40
48
  end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../command'
3
+ require_relative '../command'
4
4
  require 'tty-prompt'
5
5
 
6
6
  module Pod
7
7
  module Target
8
8
  module Commands
9
9
  class Dependency < Pod::Target::Command
10
- require_relative './xcworkspace'
11
- require_relative './parser'
12
- require_relative './graph'
10
+ require_relative './resolve/xcworkspace'
11
+ require_relative './resolve/parser'
12
+ require_relative './resolve/graph'
13
13
  def initialize(options)
14
14
  @options = options
15
15
  end
@@ -36,12 +36,11 @@ module Pod
36
36
  nodes = graph.nodes
37
37
  nodes.each do |_, value|
38
38
  level_map = {}
39
- graph.bfs(value, level_map, 0)
39
+ graph.dfs(value, level_map, 0)
40
40
  removes = []
41
41
  value.neighbors.each do |neighbor|
42
42
  if level_map[neighbor.name] > 1
43
43
  removes << neighbor.name
44
-
45
44
  end
46
45
  end
47
46
  if removes.size > 0
@@ -52,7 +52,7 @@ module Pod
52
52
  source.add_neighbor(destination)
53
53
  end
54
54
 
55
- def bfs(node, level_map, depth)
55
+ def dfs(node, level_map, depth)
56
56
  return if depth == 3
57
57
  name = node.name
58
58
  if level_map.key?(name)
@@ -61,7 +61,7 @@ module Pod
61
61
  level_map[name] = depth
62
62
  end
63
63
  node.neighbors.each do |neighbor|
64
- bfs(neighbor, level_map, depth+1)
64
+ dfs(neighbor, level_map, depth+1)
65
65
  end
66
66
  end
67
67
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../command'
4
+ require 'tty-prompt'
5
+ require 'graphviz'
6
+
7
+ module Pod
8
+ module Target
9
+ module Commands
10
+ class Target < Pod::Target::Command
11
+ require_relative './resolve/xcworkspace'
12
+ require_relative './resolve/parser'
13
+ require_relative './resolve/graph'
14
+ def initialize(options)
15
+ @options = options
16
+ end
17
+
18
+ def execute(input: $stdin, output: $stdout)
19
+ @xcworkspace = @options[:workspace]
20
+ @xcworkspace ||= XCWorkspace.find_workspace
21
+ @output = @options[:output]
22
+ @output ||= '.'
23
+ @root = @options[:root]
24
+ @max_depth = @options[:max_depth]
25
+ @max_depth ||= -1
26
+ if @root.nil?
27
+ prompt = TTY::Prompt.new
28
+ prompt.error("Root target is not set")
29
+ exit 1
30
+ end
31
+ parse
32
+ end
33
+
34
+ def parse
35
+ prompt = TTY::Prompt.new
36
+ prompt.ok("Finding targets' dependencies and build graph...")
37
+ parser = Parser.new(@xcworkspace, nil)
38
+ targets = parser.all_targets
39
+ graph = Graph.new
40
+ graph.add_target_info(targets)
41
+ dir = File.dirname(@output + "/dependencies.gv")
42
+ tmp_file = File.join(dir, '/dependencies.gv')
43
+ save_gv(graphviz_data(graph), tmp_file)
44
+ graphviz_graph = GraphViz.parse(tmp_file)
45
+ file = File.join(dir, '/' + @root + '-dependencies.png')
46
+ save_png(graphviz_graph, file)
47
+ FileUtils.remove_file(tmp_file)
48
+ prompt.ok("File is write at: " + dir + "/" + @root + "-dependencies.png")
49
+ end
50
+
51
+ def save_gv(graphviz_data, filename)
52
+ graphviz_data.output(dot: filename)
53
+ end
54
+
55
+ def save_png(graphviz_data, filename)
56
+ graphviz_data.output(png: filename)
57
+ end
58
+
59
+ def graphviz_data(graph)
60
+ node = graph.nodes.values.find { |node| node.name == @root }
61
+ if node.nil?
62
+ prompt = TTY::Prompt.new
63
+ prompt.error("Cannot find root target")
64
+ exit 1
65
+ else
66
+ graphviz = GraphViz.new(type: :digraph)
67
+ parent = {}
68
+ dfs(graphviz, node, graph, parent, 0)
69
+ graphviz
70
+ end
71
+ end
72
+
73
+ def dfs(graphviz, node, graph, parent, depth)
74
+ if @max_depth != -1 && depth == @max_depth
75
+ return
76
+ end
77
+ target_node = graphviz.add_node(node.name)
78
+ level_map = {}
79
+ graph.dfs(node, level_map, 0)
80
+ node.neighbors.each do |dependency|
81
+ if level_map[dependency.name] == 1
82
+ if parent.key?(dependency.name) == false
83
+ parent[dependency.name] = Set.new
84
+ end
85
+ if parent[dependency.name].include?(node.name) == false
86
+ parent[dependency.name].add(node.name)
87
+ dep_node = graphviz.add_node(dependency.name)
88
+ graphviz.add_edge(target_node, dep_node)
89
+ dfs(graphviz, dependency, graph, parent, depth+1)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1 @@
1
+ #
@@ -1,5 +1,5 @@
1
1
  module Pod
2
2
  module Target
3
- VERSION = "0.1.3"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pod-target
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bao Do
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-14 00:00:00.000000000 Z
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -65,16 +65,19 @@ files:
65
65
  - bin/console
66
66
  - bin/setup
67
67
  - exe/pod-target
68
+ - images/image.png
68
69
  - lib/pod/target.rb
69
70
  - lib/pod/target/cli.rb
70
71
  - lib/pod/target/command.rb
71
72
  - lib/pod/target/commands/.gitkeep
72
- - lib/pod/target/commands/resolve/dependency.rb
73
+ - lib/pod/target/commands/dependency.rb
73
74
  - lib/pod/target/commands/resolve/graph.rb
74
75
  - lib/pod/target/commands/resolve/parser.rb
75
76
  - lib/pod/target/commands/resolve/xcworkspace.rb
77
+ - lib/pod/target/commands/target.rb
76
78
  - lib/pod/target/templates/.gitkeep
77
79
  - lib/pod/target/templates/resolve/dependency/.gitkeep
80
+ - lib/pod/target/templates/target/.gitkeep
78
81
  - lib/pod/target/version.rb
79
82
  - pod-target.gemspec
80
83
  homepage: https://github.com/bendoppler/podspec-dependency-resolve.git