pod-target 0.1.1 → 0.2.1

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: de4190a35cde2f6981e4816fce856fbe2c154d3aa8749f37e46e467d96ec0d0f
4
- data.tar.gz: '086e531c929c666f42c7bfbf0a93b59eaca3bd921b92a5f5fa4687178360e8ac'
3
+ metadata.gz: 02fd569d54c81ac41ff0225faf92f2dc35c3f396fe01094cd6c5d75d66612fc9
4
+ data.tar.gz: d39a1e3d011cb3d7143a4900493d7a04d90897fdf69b13a714c7c4c388c5251f
5
5
  SHA512:
6
- metadata.gz: 3fe7369bbea6b0bfeddf567cba9393fd67b02189b5f0f4245e187a727745aa6540ca49bad3a499d05b360ba6fa85bf3a70f165023e47452dfdedecbb8e2bfd71
7
- data.tar.gz: 141eaa9eba1e9754a1630a13a1721159cdb3834de36dac1715662ebb0d8fe1ccc715d76e272d9a5fc180efdb01fc0a44ac4d18db83b86af0e74b6afd9b6d5929
6
+ metadata.gz: a14876a68e5f08930be2fb548f3a0bfd38026cdc09cda83771d302c9fdc8e1afe1512aef20628011b5aee78c391e720aadaca8c6df602e50d0e3329e13e24bfd
7
+ data.tar.gz: 59c7649ba23598e92839a63fe53a883a7680abffd1f63d9008d9a1ec033909c68b0b005eb838ae02df257a6c577212408ae5c93168707ee842f4ee9d2f36cc40
@@ -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,6 +2,7 @@
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" />
5
6
  <module fileurl="file://$PROJECT_DIR$/.idea/pod-target.iml" filepath="$PROJECT_DIR$/.idea/pod-target.iml" />
6
7
  </modules>
7
8
  </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" />
@@ -45,4 +47,32 @@
45
47
  <orderEntry type="library" scope="PROVIDED" name="wisper (v1.6.1, RVM: ruby-2.7.0) [gem]" level="application" />
46
48
  <orderEntry type="library" scope="PROVIDED" name="xcodeproj (v1.19.0, RVM: ruby-2.7.0) [gem]" level="application" />
47
49
  </component>
50
+ <component name="RakeTasksCache">
51
+ <option name="myRootTask">
52
+ <RakeTaskImpl id="rake">
53
+ <subtasks>
54
+ <RakeTaskImpl description="Build pod-target-0.1.4.gem into the pkg directory" fullCommand="build" id="build" />
55
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
56
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
57
+ <RakeTaskImpl description="Build and install pod-target-0.1.4.gem into system gems" fullCommand="install" id="install" />
58
+ <RakeTaskImpl id="install">
59
+ <subtasks>
60
+ <RakeTaskImpl description="Build and install pod-target-0.1.4.gem into system gems without network access" fullCommand="install:local" id="local" />
61
+ </subtasks>
62
+ </RakeTaskImpl>
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]" />
64
+ <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
65
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
66
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
67
+ <RakeTaskImpl id="release">
68
+ <subtasks>
69
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
70
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
71
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
72
+ </subtasks>
73
+ </RakeTaskImpl>
74
+ </subtasks>
75
+ </RakeTaskImpl>
76
+ </option>
77
+ </component>
48
78
  </module>
data/.idea/vcs.xml CHANGED
@@ -1,6 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
4
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.1)
4
+ pod-target (0.2.1)
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
@@ -1,9 +1,13 @@
1
- # Pod::Target
1
+ # pod-target
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pod/target`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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.
6
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.
7
11
  ## Installation
8
12
 
9
13
  Add this line to your application's Gemfile:
@@ -21,9 +25,25 @@ Or install it yourself as:
21
25
  $ gem install pod-target
22
26
 
23
27
  ## Usage
28
+ pod-target resolve-dependency\
24
29
 
25
- TODO: Write usage instructions here
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\
26
36
 
37
+ Workspace path and output path can be absolute path or relative path
38
+
39
+ pod-target target\
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
27
47
  ## Development
28
48
 
29
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.
@@ -32,12 +52,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
52
 
33
53
  ## Contributing
34
54
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pod-target. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/pod-target/blob/master/CODE_OF_CONDUCT.md).
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bendoppler/podspec-dependency-resolve This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/bendoppler/podspec-dependency-resolve/blob/master/CODE_OF_CONDUCT.md).
36
56
 
37
57
 
38
58
  ## Code of Conduct
39
59
 
40
- Everyone interacting in the Pod::Target project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pod-target/blob/master/CODE_OF_CONDUCT.md).
60
+ Everyone interacting in the pod-target project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bendoppler/podspec-dependency-resolve/blob/master/CODE_OF_CONDUCT.md).
41
61
 
42
62
  ## Copyright
43
63
 
data/images/image.png ADDED
Binary file
@@ -19,20 +19,28 @@ 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 :output, type: :string,
28
+ desc: "Set output path of csv file, if not set will use current directory"
29
+ def target(*)
30
+ require_relative 'commands/target'
31
+ Pod::Target::Commands::Target.new(options).execute
32
+ end
33
+
22
34
  desc 'resolve-dependency', "Resolve dependencies of pod's targets"
23
- method_option :help, aliases: '-h', type: :boolean,
24
- desc: 'Display usage information'
25
35
  method_option :workspace, type: :string,
26
36
  desc: "Set workspace path, if not set will use current directory"
27
37
  method_option :output, type: :string,
28
38
  desc: "Set output path of csv file, if not set will use current directory"
39
+ method_option :filter, type: :string, banner: "expression",
40
+ desc: "If set, filter targets which name matches the regular expression"
29
41
  def resolve_dependency(*)
30
- if options[:help]
31
- invoke :help, ['resolve-dependency']
32
- else
33
- require_relative 'commands/resolve/dependency'
34
- Pod::Target::Commands::Dependency.new(options).execute
35
- end
42
+ require_relative 'commands/dependency'
43
+ Pod::Target::Commands::Dependency.new(options).execute
36
44
  end
37
45
  end
38
46
  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
@@ -19,13 +19,15 @@ module Pod
19
19
  @xcworkspace ||= XCWorkspace.find_workspace
20
20
  @output = @options[:output]
21
21
  @output ||= '.'
22
+ @filter = @options[:filter]
23
+ @filter ||= '.*'
22
24
  parse
23
25
  end
24
26
 
25
27
  def parse
26
28
  prompt = TTY::Prompt.new
27
29
  prompt.ok("Finding targets' dependencies and resolving them...")
28
- parser = Parser.new(@xcworkspace)
30
+ parser = Parser.new(@xcworkspace, @filter)
29
31
  targets = parser.all_targets
30
32
  graph = Pod::Target::Commands::Graph.new
31
33
  graph.add_target_info(targets)
@@ -34,12 +36,11 @@ module Pod
34
36
  nodes = graph.nodes
35
37
  nodes.each do |_, value|
36
38
  level_map = {}
37
- graph.bfs(value, level_map, 0)
39
+ graph.dfs(value, level_map, 0)
38
40
  removes = []
39
41
  value.neighbors.each do |neighbor|
40
42
  if level_map[neighbor.name] > 1
41
43
  removes << neighbor.name
42
-
43
44
  end
44
45
  end
45
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,19 @@ 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
+ end
66
+ end
67
+
68
+ def dfs2(node, level_map, depth)
69
+ name = node.name
70
+ if level_map.key?(name)
71
+ level_map[name] = [level_map[name], depth].max
72
+ else
73
+ level_map[name] = depth
74
+ end
75
+ node.neighbors.each do |neighbor|
76
+ dfs2(neighbor, level_map, depth+1)
65
77
  end
66
78
  end
67
79
  end
@@ -5,8 +5,8 @@ module Pod
5
5
  module Target
6
6
  module Commands
7
7
  class Parser
8
- attr_reader :workspace, :workspace_dir
9
- def initialize(workspace_path)
8
+ attr_reader :workspace, :workspace_dir, :regex
9
+ def initialize(workspace_path, filter)
10
10
  if workspace_path.nil?
11
11
  prompt = TTY::Prompt.new
12
12
  prompt.error("Error! Cannot find workspace path")
@@ -14,11 +14,12 @@ module Pod
14
14
  end
15
15
  @workspace_dir = File.dirname(workspace_path)
16
16
  @workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
17
+ @regex = filter
17
18
  end
18
19
 
19
20
  def all_targets
20
21
  @projects ||= projects
21
- projects.flat_map(&:targets)
22
+ projects.flat_map(&:targets).select { |target| target.name =~ /#{regex}/ }
22
23
  end
23
24
 
24
25
  def projects
@@ -0,0 +1,88 @@
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
+ if @root.nil?
25
+ prompt = TTY::Prompt.new
26
+ prompt.error("Root target is not set")
27
+ exit 1
28
+ end
29
+ parse
30
+ end
31
+
32
+ def parse
33
+ prompt = TTY::Prompt.new
34
+ prompt.ok("Finding targets' dependencies and build graph...")
35
+ parser = Parser.new(@xcworkspace, nil)
36
+ targets = parser.all_targets
37
+ graph = Graph.new
38
+ graph.add_target_info(targets)
39
+ dir = File.dirname(@output + "/dependencies.gv")
40
+ tmp_file = File.join(dir, '/dependencies.gv')
41
+ save_gv(graphviz_data(graph), tmp_file)
42
+ graphviz_graph = GraphViz.parse(tmp_file)
43
+ save_png(graphviz_graph, @root + '-dependencies.png')
44
+ FileUtils.remove_file(tmp_file)
45
+ prompt.ok("File is write at: " + dir + "/" + @root + "-dependencies.png")
46
+ end
47
+
48
+ def save_gv(graphviz_data, filename)
49
+ graphviz_data.output(dot: filename)
50
+ end
51
+
52
+ def save_png(graphviz_data, filename)
53
+ graphviz_data.output(png: filename)
54
+ end
55
+
56
+ def graphviz_data(graph)
57
+ node = graph.nodes.values.find { |node| node.name == @root }
58
+ if node.nil?
59
+ prompt = TTY::Prompt.new
60
+ prompt.error("Cannot find root target")
61
+ exit 1
62
+ else
63
+ graphviz = GraphViz.new(type: :digraph)
64
+ level_map = {}
65
+ graph.dfs2(node, level_map, 0)
66
+ visited = Set.new([])
67
+ dfs(graphviz, node, visited, level_map)
68
+ graphviz
69
+ end
70
+ end
71
+
72
+ def dfs(graphviz, node, visited, level_map)
73
+ return if visited.include?(node.name)
74
+ visited.add(node.name)
75
+ depth = level_map[node.name]
76
+ target_node = graphviz.add_node(node.name)
77
+ node.neighbors.each do |dependency|
78
+ if level_map[dependency.name] == depth+1
79
+ dep_node = graphviz.add_node(dependency.name)
80
+ graphviz.add_edge(target_node, dep_node)
81
+ dfs(graphviz, dependency, visited, level_map)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1 @@
1
+ #
@@ -1,5 +1,5 @@
1
1
  module Pod
2
2
  module Target
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.1"
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.1
4
+ version: 0.2.1
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-05 00:00:00.000000000 Z
11
+ date: 2021-05-18 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