Skip to content

Commit

Permalink
Merge pull request #10 from jcampbell05/s/NewLayout
Browse files Browse the repository at this point in the history
S/new layout
  • Loading branch information
jcampbell05 committed May 28, 2017
2 parents 61b5218 1a8de1a commit 2dd54ba
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 13 deletions.
5 changes: 4 additions & 1 deletion cocoapods-deploy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 11,16 @@ Gem::Specification.new do |s|
s.date = "2016-03-07"
s.description = "Implement's bundler's --deployment functionality in CocoaPods."
s.email = ["[email protected]"]
s.files = [".gitignore", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "cocoapods-deploy.gemspec", "lib/cocoapods-deploy/command.rb", "lib/cocoapods-deploy/command/deploy.rb", "lib/cocoapods-deploy/deploy_transformer.rb", "lib/cocoapods-deploy/deploy_analyzer.rb", "lib/cocoapods-deploy/deploy_downloader.rb", "lib/cocoapods-deploy/deploy_installer.rb", "lib/cocoapods-deploy/gem_version.rb", "lib/cocoapods-deploy.rb", "lib/cocoapods_plugin.rb", "spec/spec_helper.rb"]
# - Fix this its awful why do we need to declare everything
s.files = [".gitignore", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "cocoapods-deploy.gemspec", "lib/cocoapods-deploy/command.rb", "lib/cocoapods-deploy/command/deploy.rb", "lib/cocoapods-deploy/deploy_transformer.rb", "lib/cocoapods-deploy/deploy_analyzer.rb", "lib/cocoapods-deploy/deploy_downloader.rb", "lib/cocoapods-deploy/deploy_installer.rb", "lib/cocoapods-deploy/gem_version.rb", "lib/cocoapods-deploy.rb", "lib/cocoapods_plugin.rb", "spec/spec_helper.rb", "lib/cocoapods-deploy/patches/write_lockfile_patch.rb"]
s.homepage = "https://github.com/jcampbell05/cocoapods-deploy"
s.licenses = ["MIT"]
s.rubygems_version = "2.4.8"
s.summary = "Implement's bundler's --deployment functionality in CocoaPods."
s.test_files = ["spec/command/deploy_spec.rb", "spec/spec_helper.rb"]

# - Simplify this
# - Cocoapods 1.0 only
if s.respond_to? :specification_version then
s.specification_version = 4

Expand Down
21 changes: 10 additions & 11 deletions lib/cocoapods-deploy/command/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,3 1,5 @@
# - Patch Lockfile to store URLs
# - Use the data in deploy
module Pod
class Command
class Deploy < Command
Expand Down Expand Up @@ -43,7 45,6 @@ def transform_podfile
# In the future passing the lockfile into the resolve is hacked
# potentially we could have a special deploy subclass.
#
# TODO: BDD
def apply_resolver_patch
Resolver.class_eval do

Expand Down Expand Up @@ -77,28 78,27 @@ def dependencies_for(specification)
end
end
end

# Applies patch to external sources to add a no_validate option which
# can be used to disable validation of downloaded podspecs. A normal install
# doesn't validate the podspecs of non-external pods even though certain
# podspecs are not entirely valid (for example an invalid license file type).
# This would mean the normal install command can install certain pods that deploy
# doesn't because of the validation. This patch makes sure validation doesn't
# doesn't because of the validation. This patch makes sure validation doesn't
# happen when deploy is being used.
#
# TODO: BDD
def apply_external_sources_patch
ExternalSources::AbstractExternalSource.class_eval do
attr_accessor :no_validate

old_validate_podspec = instance_method(:validate_podspec)

def validate_podspec(podspec)
return if no_validate
old_validate_podspec(podspec)
end
end
end
end

# Installs required sources for lockfile - TODO: Simplify code
def install_sources_for_lockfile
Expand All @@ -119,23 119,22 @@ def install_sources_for_pod(pod)
# Triggers the CocoaPods install process
def install(podfile)
installer = DeployInstaller.new(config.sandbox, podfile, nil)

# Disable updating of the CocoaPods Repo since we are directly
# deploying using Podspecs
installer.repo_update = false

# Disable cleaning of the source file since we are deploying
# and we don't need to keep things clean.
installer.installation_options.clean = false
installer.installation_options.clean = false

installer.install!
end

def run
setup_environment
verify_environment

# TODO: BDD Patch
apply_resolver_patch
apply_external_sources_patch

Expand Down
5 changes: 4 additions & 1 deletion lib/cocoapods-deploy/deploy_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 3,12 @@ class DeployTransformer

attr_accessor :lockfile
attr_accessor :sandbox
attr_accessor :metadata

def initialize(lockfile, sandbox)
@lockfile = lockfile
@sandbox = sandbox
@metadata = Source::Metadata.new({'prefix_lengths' => [1, 1, 1]})
end

def transform_podfile(podfile)
Expand Down Expand Up @@ -64,7 66,8 @@ def parse_dependency(name_or_hash)
end

def podspec_url(pod, version)
"{root-url}/#{pod}/#{version}/#{pod}"
path_fragment = metadata.path_fragment(pod)
"{root-url}/#{path_fragment}/#{version}/#{pod}"
end

def collect_podspec_dependencies(name_or_hash)
Expand Down
87 changes: 87 additions & 0 deletions lib/cocoapods-deploy/patches/write_lockfile_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 1,87 @@
module Pod

# - Apply patch to sandbox
# - Both work together to record URI of ext pod
# - deploy transformer should use this data
# - Help people upgrade to 0.1 of cocoapods-deploy

Sandbox.class_eval do

def external_podspecs
@external_podspecs
end

def store_external_podspec(name, url)
UI.message("store #{name} and #{url}")
@external_podspecs ||= {}
@external_podspecs[name] = url
end
end

Installer.class_eval do

def apply_lockfile_patch

ExternalSources::DownloaderSource.class_eval do
def pre_download(sandbox)

# - Call original and just apply the store section afterwards

strategy = Downloader.strategy_from_options(params)
options = params.dup
url = options.delete(strategy)

title = "Pre-downloading: `#{name}` #{description}"
UI.titled_section(title, :verbose_prefix => '-> ') do
target = sandbox.pod_dir(name)
download_result = Downloader.download(download_request, target, :can_cache => can_cache)
spec = download_result.spec

raise Informative, "Unable to find a specification for '#{name}'." unless spec

store_podspec(sandbox, spec)
sandbox.store_external_podspec(name, url)
sandbox.store_pre_downloaded_pod(name)
sandbox.store_checkout_source(name, download_result.checkout_options)
end
end
end

Lockfile.class_eval do
def self.generate(podfile, specs, checkout_options, podspecs)
hash = {
'PODS' => generate_pods_data(specs),
'DEPENDENCIES' => generate_dependencies_data(podfile),
'EXTERNAL SOURCES' => generate_external_sources_data(podfile),
'CHECKOUT OPTIONS' => checkout_options,
'SPEC CHECKSUMS' => generate_checksums(specs),
'PODFILE CHECKSUM' => podfile.checksum,
'EXTERNAL PODSPECS' => podspecs,
'COCOAPODS' => CORE_VERSION,
'COCOAPODS DEPLOY' => '0.0.11' # - Get from cocoapods version
}
Lockfile.new(hash)
end
end
end

def write_lockfiles
apply_lockfile_patch

# How do we get URL for podspec on download that we can put here ?
external_source_pods = podfile.dependencies.select(&:external_source).map(&:root_name).uniq
checkout_options = sandbox.checkout_sources.select { |root_name, _| external_source_pods.include? root_name }
@lockfile = Lockfile.generate(podfile, analysis_result.specifications, checkout_options, sandbox.external_podspecs)

UI.message "- Writing Lockfile in #{UI.path config.lockfile_path}" do
@lockfile.write_to_disk(config.lockfile_path)
end

UI.message "- Writing Manifest in #{UI.path sandbox.manifest_path}" do
sandbox.manifest_path.open('w') do |f|
f.write config.lockfile_path.read
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/cocoapods_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 3,4 @@
require 'cocoapods-deploy/deploy_installer'
require 'cocoapods-deploy/deploy_transformer'
require 'cocoapods-deploy/command'
require 'cocoapods-deploy/patches/write_lockfile_patch'

0 comments on commit 2dd54ba

Please sign in to comment.