cocoapods-patch 0.0.3 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0630f65e8646fbca0c6a49834d7cb617ad8fc1895a23bb6eeca1c92cf6ba96fe
4
- data.tar.gz: 7ddba775f9029c46588750f176870f6b5c5ec27ce0373db22ac5832dab354a85
3
+ metadata.gz: 765a982a7881db3b57c31e3bbe5e54ec56f5d990a4918c81f1ff7dbf6e7d9cf7
4
+ data.tar.gz: b9ec1d2c051c580b5f9c79f34e6905b8931a5ca3abcde268d61ff03fbdb6e938
5
5
  SHA512:
6
- metadata.gz: 6e56809e31e8b3beecdc9bf9df7699915cb8591aa05d70b428ab47803414552d22e14cfce734ec5733002ae9ba5943e97539bbe4853dffea03f539a413a63b4a
7
- data.tar.gz: 2511dc28bc71ef9f6d04470a315b12f7a442afdb9d1020798ea93ed8ef23faae065c2cedfe8819723e1809b97a114c5598aed7d6d40b8d5aa600cece249f1fc9
6
+ metadata.gz: 32860c686e91f67ee8d4939bb1507c852b34284c626086a74375e3c51a38d6c31e4b06e4f07e401f73724105824b55e3b3cc59001fbac875843e5e904046d970
7
+ data.tar.gz: 8702ff7065ed62bdca2455c145a7519bc9317db9f86a05639b8c2f08ae5dd9901e6566bfe6ea0dfd6b5501fa25d7a910af085ce3270996545a02d2117f701cfc
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+
2
+ # cocoapods-patch
3
+
4
+ cocoapods-patch is a Cocoapods plugin that solves the problem of forking and maintaining a separate version of a Pod when only a small (often a one-liner), long-lived change in the original Pod is needed.
5
+
6
+ The idea behind the plugin is that patches should live inside the repo (in the `patches` directory) and be distributed together with the rest of your source code. This way, you can more easily code review and test the changes to a Pod and keep it synced across your team.
7
+
8
+ ## Installation
9
+
10
+ First, install the plugin
11
+
12
+ $ gem install cocoapods-patch
13
+
14
+ Next, add a `plugin 'cocoapods-patch'` line to your Podfile to use the plugin. This will enable [automatic apply](#automatically-applying-all-patches-on-install) so you don't have to worry about it again.
15
+
16
+ That's it, you're done.
17
+
18
+ ## Usage
19
+
20
+ ### Creating a patch
21
+
22
+ To create a patch, first, you need to modify the source code of the installed Pod. Do the desired changes to the Pod source code (under the `Pods/` directory). Once you're satisfied with the result, run:
23
+
24
+ pod patch create POD_NAME
25
+
26
+ This will create a `patches/POD_NAME.diff` file in your repository. The patch is a diff between the Pod version you have specified in your Podfile and your local changes to the Pod. You can now add and commit this patch.
27
+
28
+ ### Automatically applying all patches on install
29
+
30
+ cocoapod-patch can be seamlessly integrated into the normal iOS development workflow. If you follow the installation instructions and add `plugin 'cocoapods-patch'` to your Podfile, every time you do a `pod install`, the plugin will go throught all the available patches and try to apply them. It will only warn you when the patch cannot be applied.
31
+
32
+ ### Applying a patch manually
33
+
34
+ When you want to apply a patch to a pod, run
35
+
36
+ pod patch apply POD_NAME
37
+
38
+ This command will look for the appropriate patch in the `patches` directory and, if possibly, apply it to your local Pod. A patch can be applied only once.
@@ -1,3 +1,3 @@
1
1
  module CocoapodsPatch
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -1,2 +1,2 @@
1
- require 'cocoapods-patch/command'
2
- require 'cocoapods-patch/hook'
1
+ require 'pod/command'
2
+ require 'pod/hook'
@@ -0,0 +1,3 @@
1
+ require_relative 'command/patch'
2
+ require_relative 'command/patch/apply'
3
+ require_relative 'command/patch/create'
@@ -1,3 +1,6 @@
1
+ require_relative 'patch/apply'
2
+ require_relative 'patch/create'
3
+
1
4
  module Pod
2
5
  class Command
3
6
  class Patch < Command
@@ -7,6 +10,10 @@ module Pod
7
10
  def patch_file
8
11
  config.project_root + 'patches' + "#{@name}.diff"
9
12
  end
13
+
14
+ def patches_path
15
+ config.project_root + 'patches'
16
+ end
10
17
  end
11
18
  end
12
19
  end
@@ -0,0 +1,53 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+ class Command
5
+ class Patch < Command
6
+ class Apply < Patch
7
+ self.summary = 'Applies a patch to an installed Pod'
8
+
9
+ self.arguments = [
10
+ CLAide::Argument.new('NAME', true)
11
+ ]
12
+
13
+ def initialize(argv)
14
+ @name = argv.shift_argument
15
+ super
16
+ end
17
+
18
+ def validate!
19
+ super
20
+ help! 'A Pod name is required.' unless @name
21
+ end
22
+
23
+ def run
24
+ apply_patch patch_file
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ # also used from the post-install hook
32
+ def apply_patch(patch_file)
33
+ working_dir = Dir.pwd
34
+ repo_root = `git rev-parse --show-toplevel`.strip
35
+ ios_project_path = Pathname.new(working_dir).relative_path_from(Pathname.new(repo_root))
36
+
37
+ directory_arg = (ios_project_path.to_s.eql? ".") ? "Pods" : File.join(ios_project_path, 'Pods')
38
+
39
+ Dir.chdir(repo_root) {
40
+ check_cmd = "git apply --check #{patch_file} --directory=#{directory_arg} -p2 2> /dev/null"
41
+
42
+ can_apply = system(check_cmd)
43
+ if can_apply
44
+ apply_cmd = check_cmd.gsub('--check ', '')
45
+ did_apply = system(apply_cmd)
46
+ if did_apply
47
+ Pod::UI.puts "Successfully applied #{patch_file} 🎉"
48
+ else
49
+ Pod::UI.warn "Error: failed to apply #{patch_file}"
50
+ end
51
+ end
52
+ }
53
+ end
@@ -24,7 +24,16 @@ module Pod
24
24
  help! 'A Pod name is required.' unless @name
25
25
  end
26
26
 
27
+ def clear_patches_folder_if_empty
28
+ if Dir.empty?(patches_path)
29
+ FileUtils.remove_dir(patches_path)
30
+ end
31
+ end
32
+
27
33
  def run
34
+ # create patches folder if it doesn't exist
35
+ FileUtils.mkdir_p(patches_path)
36
+
28
37
  Dir.mktmpdir('cocoapods-patch-', config.project_root) do |work_dir|
29
38
  sandbox = Pod::Sandbox.new(work_dir)
30
39
  installer = Pod::Installer.new(sandbox, config.podfile)
@@ -33,18 +42,35 @@ module Pod
33
42
  installer.prepare
34
43
  installer.resolve_dependencies
35
44
 
45
+ UI.puts "Checking if pod exists in project..."
46
+ specs_by_platform = installer.send :specs_for_pod, @name
47
+
48
+ if specs_by_platform.empty?
49
+ clear_patches_folder_if_empty
50
+ help! "Given pod does not exist in project. Did you use incorrect pod name?"
51
+
52
+ return
53
+ end
54
+
36
55
  pod_installer = installer.send :create_pod_installer, @name
37
56
  pod_installer.install!
38
57
 
58
+ UI.puts "Creating patch"
39
59
  theirs = Pathname.new(work_dir).join(@name).relative_path_from(config.project_root)
40
60
  ours = config.project_pods_root.join(@name).relative_path_from(config.project_root)
41
61
  gen_diff_cmd = "git diff --no-index #{theirs} #{ours} > #{patch_file}"
42
62
 
43
63
  did_succeed = system(gen_diff_cmd)
44
64
  if not did_succeed.nil?
45
- UI.puts "Created patch #{patch_file}"
65
+ if File.empty?(patch_file)
66
+ File.delete(patch_file)
67
+ clear_patches_folder_if_empty
68
+ UI.warn "Error: no changes detected between current pod and original"
69
+ else
70
+ UI.puts "Created patch #{patch_file} 🎉"
71
+ end
46
72
  else
47
- UI.warn "Error creating patch for #{@name}"
73
+ UI.warn "Error: failed to create patch for #{@name}"
48
74
  end
49
75
  end
50
76
  end
data/lib/pod/hook.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'cocoapods'
2
+ require 'pathname'
3
+ require_relative 'command/patch/apply'
4
+
5
+ module CocoapodsPatch
6
+ module Hooks
7
+ Pod::HooksManager.register('cocoapods-patch', :pre_install) do |context|
8
+ Pod::UI.puts 'Preparing patchable pods for clean patching'
9
+ patches_dir = Pathname.new(Dir.pwd) + 'patches'
10
+ if patches_dir.directory?
11
+ patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
12
+ patches.each do |p|
13
+ pod_name = File.basename(p, ".diff")
14
+ context.sandbox.clean_pod(pod_name)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ class Pod::Installer
22
+ # Because our patches may also delete files, we need to apply them before the pod project is generated
23
+ # The project is generated in the `integrate` method, so we override it
24
+ # We first run our patch action and then the original implementation of the method
25
+ # Reference: https://github.com/CocoaPods/CocoaPods/blob/760828a07f8fcfbff03bce13f56a1789b6f5a95d/lib/cocoapods/installer.rb#L178
26
+ alias_method :integrate_old, :integrate
27
+
28
+ def integrate
29
+ # apply our patches
30
+ apply_patches
31
+ # run the original implementation
32
+ integrate_old
33
+ end
34
+
35
+ def apply_patches
36
+ Pod::UI.puts 'Applying patches if necessary'
37
+ patches_dir = Pathname.new(Dir.pwd) + 'patches'
38
+ if patches_dir.directory?
39
+ patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
40
+ patches.each { |p| apply_patch(p) }
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Double Symmetry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-09 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '3.9'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cocoapods
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
39
67
  - !ruby/object:Gem::Version
40
- version: '0'
68
+ version: '1.0'
41
69
  description: Create & apply patches to Pods
42
70
  email:
43
71
  - dev@doublesymmetry.com
@@ -45,14 +73,14 @@ executables: []
45
73
  extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
48
- - lib/cocoapods-patch.rb
49
- - lib/cocoapods-patch/command.rb
50
- - lib/cocoapods-patch/command/patch.rb
51
- - lib/cocoapods-patch/command/patch/apply.rb
52
- - lib/cocoapods-patch/command/patch/create.rb
53
- - lib/cocoapods-patch/gem_version.rb
54
- - lib/cocoapods-patch/hook.rb
76
+ - README.md
77
+ - lib/cocoapods_patch.rb
55
78
  - lib/cocoapods_plugin.rb
79
+ - lib/pod/command.rb
80
+ - lib/pod/command/patch.rb
81
+ - lib/pod/command/patch/apply.rb
82
+ - lib/pod/command/patch/create.rb
83
+ - lib/pod/hook.rb
56
84
  homepage: https://github.com/DoubleSymmetry/cocoapods-patch
57
85
  licenses:
58
86
  - MIT
@@ -1 +0,0 @@
1
- require 'cocoapods-patch/gem_version'
@@ -1,3 +0,0 @@
1
- require 'cocoapods-patch/command/patch'
2
- require 'cocoapods-patch/command/patch/apply'
3
- require 'cocoapods-patch/command/patch/create'
@@ -1,44 +0,0 @@
1
- require 'cocoapods'
2
-
3
- module Pod
4
- class Command
5
- class Patch < Command
6
- class Apply < Patch
7
- self.summary = 'Applies a patch to an installed Pod'
8
-
9
- self.arguments = [
10
- CLAide::Argument.new('NAME', true)
11
- ]
12
-
13
- def initialize(argv)
14
- @name = argv.shift_argument
15
- super
16
- end
17
-
18
- def validate!
19
- super
20
- help! 'A Pod name is required.' unless @name
21
- end
22
-
23
- def run
24
- apply_patch patch_file
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
31
- # also used from the post-install hook
32
- def apply_patch(patch_file)
33
- check_cmd = "git apply --check #{patch_file} --directory=Pods -p2 2> /dev/null"
34
- can_apply = system(check_cmd)
35
- if can_apply
36
- apply_cmd = check_cmd.gsub('--check ', '')
37
- did_apply = system(apply_cmd)
38
- if did_apply
39
- Pod::UI.puts "Successfully applied #{patch_file}"
40
- else
41
- Pod::UI.warn "Failed to apply #{patch_file}"
42
- end
43
- end
44
- end
@@ -1,34 +0,0 @@
1
- require 'cocoapods'
2
- require 'pathname'
3
- require_relative 'command/patch/apply'
4
-
5
- class Pod::Installer
6
- # The only way to run my custom method after the pod integrates with the project (http://blog.bigbinary.com/2012/01/08/alias-vs-alias-method.html)
7
- # Repace the method implementation integrate_user_project with ours
8
- alias_method :perform_post_install_actions_old, :perform_post_install_actions
9
-
10
- def perform_post_install_actions
11
- # integrate with the user project
12
- perform_post_install_actions_old
13
- # run custom post_integrate_method
14
- apply_patches
15
- end
16
-
17
- def apply_patches
18
- Pod::UI.puts 'Applying patches if necessary'
19
- patches_dir = Pathname.new(Dir.pwd) + 'patches'
20
- patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
21
- patches.each { |p| apply_patch(p) }
22
- end
23
- end
24
-
25
- # module CocoapodsPatch
26
- # module Hooks
27
- # Pod::HooksManager.register('cocoapods-patch', :post_integrate) do |context|
28
- # Pod::UI.puts 'Applying patches if necessary'
29
- # patches_dir = Pathname.new(context.sandbox_root) + '..' + 'patches'
30
- # patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
31
- # patches.each { |p| apply_patch(p) }
32
- # end
33
- # end
34
- # end