Skip to content

Commit

Permalink
Always apply patch on fresh source + project cleanup (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz authored Mar 24, 2021
1 parent 9af489f commit b095c17
Show file tree
Hide file tree
Showing 38 changed files with 1,190 additions and 61 deletions.
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ build-iPhoneSimulator/
## Environment normalization:
/.bundle/
/vendor/bundle
spec/project/vendor/bundle
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
Expand All @@ -56,3 +57,47 @@ build-iPhoneSimulator/
# .rubocop-https?--*

.DS_Store

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#

Pods/

# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in cocoapods-patch.gemspec
gemspec

group :development do
gem 'cocoapods'
end
117 changes: 117 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
PATH
remote: .
specs:
cocoapods-patch (0.0.7)
cocoapods (~> 1.0)

GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.3)
activesupport (5.2.4.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.0.3)
cocoapods (1.10.1)
addressable (~> 2.6)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.10.1)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.4.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.4.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.6.6)
nap (~> 1.0)
ruby-macho (~> 1.4)
xcodeproj (>= 1.19.0, < 2.0)
cocoapods-core (1.10.1)
activesupport (> 5.0, < 6)
addressable (~> 2.6)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.4.0)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-trunk (1.5.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.1.8)
diff-lcs (1.4.4)
escape (0.0.4)
ethon (0.12.0)
ffi (>= 1.3.0)
ffi (1.14.2)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
json (2.5.1)
minitest (5.14.3)
molinillo (0.6.6)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.6)
rake (13.0.3)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.1)
ruby-macho (1.4.0)
thread_safe (0.3.6)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (1.2.9)
thread_safe (~> 0.1)
xcodeproj (1.19.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)

PLATFORMS
x86_64-darwin-19

DEPENDENCIES
bundler (~> 2.0)
cocoapods-patch!
rake (~> 13.0)
rspec (~> 3.9)

BUNDLED WITH
2.2.6
13 changes: 3 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
require 'bundler/gem_tasks'

def specs(dir)
FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
end

desc 'Runs all the specs'
task :specs do
sh "bundle exec bacon #{specs('**')}"
end

task :default => :specs
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task default: :spec
13 changes: 7 additions & 6 deletions cocoapods-patch.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cocoapods-patch/gem_version.rb'
require 'cocoapods_patch.rb'

Gem::Specification.new do |spec|
spec.name = 'cocoapods-patch'
Expand All @@ -13,11 +13,12 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/DoubleSymmetry/cocoapods-patch'
spec.license = 'MIT'

spec.files = Dir['lib/**/*.rb']
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.files = Dir['*.md', 'lib/**/*', 'LICENSE']
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.9'

spec.add_dependency 'cocoapods', '~> 1.0'
end
1 change: 0 additions & 1 deletion lib/cocoapods-patch.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/cocoapods-patch/command.rb

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions lib/cocoapods_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require 'cocoapods-patch/command'
require 'cocoapods-patch/hook'
require 'pod/command'
require 'pod/hook'
3 changes: 3 additions & 0 deletions lib/pod/command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative 'command/patch'
require_relative 'command/patch/apply'
require_relative 'command/patch/create'
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require_relative 'patch/apply'
require_relative 'patch/create'

module Pod
class Command
class Patch < Command
Expand All @@ -7,6 +10,10 @@ class Patch < Command
def patch_file
config.project_root + 'patches' + "#{@name}.diff"
end

def patches_path
config.project_root + 'patches'
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def apply_patch(patch_file)
apply_cmd = check_cmd.gsub('--check ', '')
did_apply = system(apply_cmd)
if did_apply
Pod::UI.puts "Successfully applied #{patch_file}"
Pod::UI.puts "Successfully applied #{patch_file} 🎉"
else
Pod::UI.warn "Failed to apply #{patch_file}"
Pod::UI.warn "Error: failed to apply #{patch_file}"
end
end
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ def validate!
help! 'A Pod name is required.' unless @name
end

def clear_patches_folder_if_empty
if Dir.empty?(patches_path)
FileUtils.remove_dir(patches_path)
end
end

def run
FileUtils.mkdir_p('patches')
# create patches folder if it doesn't exist
FileUtils.mkdir_p(patches_path)

Dir.mktmpdir('cocoapods-patch-', config.project_root) do |work_dir|
sandbox = Pod::Sandbox.new(work_dir)
installer = Pod::Installer.new(sandbox, config.podfile)
Expand All @@ -34,18 +42,35 @@ def run
installer.prepare
installer.resolve_dependencies

UI.puts "Checking if pod exists in project..."
specs_by_platform = installer.send :specs_for_pod, @name

if specs_by_platform.empty?
clear_patches_folder_if_empty
help! "Given pod does not exist in project. Did you use incorrect pod name?"

return
end

pod_installer = installer.send :create_pod_installer, @name
pod_installer.install!

UI.puts "Creating patch"
theirs = Pathname.new(work_dir).join(@name).relative_path_from(config.project_root)
ours = config.project_pods_root.join(@name).relative_path_from(config.project_root)
gen_diff_cmd = "git diff --no-index #{theirs} #{ours} > #{patch_file}"

did_succeed = system(gen_diff_cmd)
if not did_succeed.nil?
UI.puts "Created patch #{patch_file}"
if File.empty?(patch_file)
File.delete(patch_file)
clear_patches_folder_if_empty
UI.warn "Error: no changes detected between current pod and original"
else
UI.puts "Created patch #{patch_file} 🎉"
end
else
UI.warn "Error creating patch for #{@name}"
UI.warn "Error: failed to create patch for #{@name}"
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions lib/cocoapods-patch/hook.rb → lib/pod/hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
require 'pathname'
require_relative 'command/patch/apply'

module CocoapodsPatch
module Hooks
Pod::HooksManager.register('cocoapods-patch', :pre_install) do |context|
Pod::UI.puts 'Preparing patchable pods for clean patching'
patches_dir = Pathname.new(Dir.pwd) + 'patches'
if patches_dir.directory?
patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
patches.each do |p|
pod_name = File.basename(p, ".diff")
context.sandbox.clean_pod(pod_name)
end
end
end
end
end

class Pod::Installer
# Because our patches may also delete files, we need to apply them before the pod project is generated
# The project is generated in the `integrate` method, so we override it
Expand Down
9 changes: 9 additions & 0 deletions spec/apply_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe Pod::Command::Patch::Apply do
describe 'CLAide' do
it 'registers it self' do
expect(Pod::Command.parse(%w{ patch apply POD_NAME })).to be_an_instance_of Pod::Command::Patch::Apply
end
end
end
12 changes: 0 additions & 12 deletions spec/command/patch_spec.rb

This file was deleted.

9 changes: 9 additions & 0 deletions spec/create_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe Pod::Command::Patch::Create do
describe 'CLAide' do
it 'registers it self' do
expect(Pod::Command.parse(%w{ patch create POD_NAME })).to be_an_instance_of Pod::Command::Patch::Create
end
end
end
9 changes: 9 additions & 0 deletions spec/patch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe Pod::Command::Patch do
describe 'CLAide' do
it 'registers it self' do
expect(Pod::Command.parse(%w{ patch })).to be_an_instance_of Pod::Command::Patch
end
end
end
1 change: 1 addition & 0 deletions spec/project/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.6.3
Loading

0 comments on commit b095c17

Please sign in to comment.