Commit 943ea72d authored by Fabio Pelosin's avatar Fabio Pelosin

[Installer] Clean up & specs

parent d9f450c7
...@@ -81,17 +81,35 @@ module Pod ...@@ -81,17 +81,35 @@ module Pod
# @return [void] # @return [void]
# #
def install! def install!
analyze resolve_dependencies
detect_pods_to_install download_dependencies
prepare_for_legacy_compatibility generate_pods_project
prepare_sandbox
if config.integrate_targets?
UI.section "Integrating client projects" do
integrate_user_project
end
end
end
def resolve_dependencies
UI.section "Resolving dependencies" do
analyze
detect_pods_to_install
prepare_for_legacy_compatibility
prepare_sandbox
end
end
def download_dependencies
UI.section "Downloading dependencies" do UI.section "Downloading dependencies" do
create_file_accessors create_file_accessors
install_pod_sources install_pod_sources
end end
end
UI.section "Generating Pods Project" do def generate_pods_project
UI.section "Generating pods project" do
prepare_pods_project prepare_pods_project
run_pre_install_hooks run_pre_install_hooks
install_file_references install_file_references
...@@ -100,12 +118,6 @@ module Pod ...@@ -100,12 +118,6 @@ module Pod
write_pod_project write_pod_project
write_lockfiles write_lockfiles
end end
if config.integrate_targets?
UI.section "Integrating client projects" do
integrate_user_project
end
end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -117,7 +129,7 @@ module Pod ...@@ -117,7 +129,7 @@ module Pod
# @return [Analyzer] the analyzer which provides the information about what # @return [Analyzer] the analyzer which provides the information about what
# needs to be installed. # needs to be installed.
# #
attr_reader :analyzer attr_reader :analysis_result
# @return [Pod::Project] the `Pods/Pods.xcodeproj` project. # @return [Pod::Project] the `Pods/Pods.xcodeproj` project.
# #
...@@ -140,18 +152,15 @@ module Pod ...@@ -140,18 +152,15 @@ module Pod
private private
# TODO: This is recreating the file accessors
# TODO: the file accessor should be initializable without a path list
# @!group Installation steps # @!group Installation steps
# @return [void] # @return [void]
# #
def analyze def analyze
@analyzer = Analyzer.new(sandbox, podfile, lockfile) analyzer = Analyzer.new(sandbox, podfile, lockfile)
@analyzer.update_mode = update_mode analyzer.update_mode = update_mode
@analyzer.analyze @analysis_result = analyzer.analyze
@libraries = analyzer.libraries @libraries = analyzer.result.libraries
end end
# Computes the list of the Pods that should be installed or reinstalled in # Computes the list of the Pods that should be installed or reinstalled in
...@@ -173,11 +182,11 @@ module Pod ...@@ -173,11 +182,11 @@ module Pod
def detect_pods_to_install def detect_pods_to_install
names = [] names = []
analyzer.specifications.each do |spec| analysis_result.specifications.each do |spec|
root_name = spec.root.name root_name = spec.root.name
if update_mode if update_mode
if spec.version.head? #|| TODO resolver.pods_from_external_sources.include?(root_name) if spec.version.head? # || resolver.pods_from_external_sources.include?(root_name) TODO
names << root_name names << root_name
end end
end end
...@@ -187,7 +196,7 @@ module Pod ...@@ -187,7 +196,7 @@ module Pod
end end
end end
names += analyzer.sandbox_state.added + analyzer.sandbox_state.changed names += analysis_result.sandbox_state.added + analysis_result.sandbox_state.changed
names = names.map { |name| Specification.root_name(name) } names = names.map { |name| Specification.root_name(name) }
names = names.flatten.uniq names = names.flatten.uniq
@names_of_pods_to_install = names @names_of_pods_to_install = names
...@@ -210,10 +219,6 @@ module Pod ...@@ -210,10 +219,6 @@ module Pod
# #
# @todo [#247] Clean the headers of only the pods to install. # @todo [#247] Clean the headers of only the pods to install.
# #
# @todo [#534] Clean all the Pods folder that are not unchanged
#
# @todo Use the local pod implode.
#
# @todo Clean the podspecs of all the pods that aren't unchanged so the # @todo Clean the podspecs of all the pods that aren't unchanged so the
# resolution process doesn't get confused by them. # resolution process doesn't get confused by them.
# #
...@@ -221,36 +226,19 @@ module Pod ...@@ -221,36 +226,19 @@ module Pod
sandbox.build_headers.implode! sandbox.build_headers.implode!
sandbox.public_headers.implode! sandbox.public_headers.implode!
# TODO local option unless analysis_result.sandbox_state.deleted.empty?
unless analyzer.sandbox_state.deleted.empty?
UI.section "Removing deleted dependencies" do UI.section "Removing deleted dependencies" do
analyzer.sandbox_state.deleted.each do |pod_name| analysis_result.sandbox_state.deleted.each do |pod_name|
UI.section("Removing #{pod_name}", "-> ".red) do UI.section("Removing #{pod_name}", "-> ".red) do
path = sandbox.root + pod_name sandbox.clean_pod(pod_name)
path.rmtree if path.exist?
end end
end end
end end
end end
end end
# Creates the Pods project from scratch if it doesn't exists. # TODO: the file accessor should be initialized by the sandbox as they
# # created by the Pod source installer as well.
# @return [void]
#
# @todo Clean and modify the project if it exists.
#
def prepare_pods_project
UI.message "- Creating Pods project" do
@pods_project = Pod::Project.new(sandbox.project_path)
if config.podfile_path.exist?
@pods_project.add_podfile(config.podfile_path)
end
sandbox.project = @pods_project
end
end
#
# #
def create_file_accessors def create_file_accessors
libraries.each do |library| libraries.each do |library|
...@@ -275,7 +263,6 @@ module Pod ...@@ -275,7 +263,6 @@ module Pod
# #
def install_pod_sources def install_pod_sources
@installed_specs = [] @installed_specs = []
root_specs = analyzer.specifications.map { |spec| spec.root }.uniq
root_specs.each do |spec| root_specs.each do |spec|
if names_of_pods_to_install.include?(spec.name) if names_of_pods_to_install.include?(spec.name)
UI.section("Installing #{spec}".green, "-> ".green) do UI.section("Installing #{spec}".green, "-> ".green) do
...@@ -313,6 +300,22 @@ module Pod ...@@ -313,6 +300,22 @@ module Pod
@installed_specs.concat(specs_by_platform.values.flatten) @installed_specs.concat(specs_by_platform.values.flatten)
end end
# Creates the Pods project from scratch if it doesn't exists.
#
# @return [void]
#
# @todo Clean and modify the project if it exists.
#
def prepare_pods_project
UI.message "- Creating Pods project" do
@pods_project = Pod::Project.new(sandbox.project_path)
if config.podfile_path.exist?
@pods_project.add_podfile(config.podfile_path)
end
sandbox.project = @pods_project
end
end
# Installs the file references in the Pods project. This is done once per # Installs the file references in the Pods project. This is done once per
# Pod as the same file reference might be shared by multiple targets. # Pod as the same file reference might be shared by multiple targets.
...@@ -353,12 +356,13 @@ module Pod ...@@ -353,12 +356,13 @@ module Pod
# Writes the Podfile and the lock files. # Writes the Podfile and the lock files.
# #
# @todo Pass the checkout options to the Lockfile.
#
# @return [void] # @return [void]
# #
def write_lockfiles def write_lockfiles
# checkout_options = sandbox.checkout_options # checkout_options = sandbox.checkout_options
# TODO pass the options to the Lockfile @lockfile = Lockfile.generate(podfile, analysis_result.specifications)
@lockfile = Lockfile.generate(podfile, analyzer.specifications)
UI.message "- Writing Lockfile in #{UI.path config.lockfile_path}" do UI.message "- Writing Lockfile in #{UI.path config.lockfile_path}" do
@lockfile.write_to_disk(config.lockfile_path) @lockfile.write_to_disk(config.lockfile_path)
...@@ -383,13 +387,13 @@ module Pod ...@@ -383,13 +387,13 @@ module Pod
# #
def integrate_user_project def integrate_user_project
installation_root = config.installation_root installation_root = config.installation_root
libraries = analyzer.libraries integrator = UserProjectIntegrator.new(podfile, sandbox, installation_root, libraries)
UserProjectIntegrator.new(podfile, sandbox, installation_root, libraries).integrate! integrator.integrate!
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
public private
# @!group Hooks # @!group Hooks
...@@ -400,7 +404,7 @@ module Pod ...@@ -400,7 +404,7 @@ module Pod
def run_pre_install_hooks def run_pre_install_hooks
UI.message "- Running pre install hooks" do UI.message "- Running pre install hooks" do
installed_specs.each do |spec| installed_specs.each do |spec|
executed = spec.pre_install!(pod_data(spec), library_data(libraries.first)) #todo executed = spec.pre_install!(pod_data(spec), library_data(libraries.first)) #TODO
UI.message "- #{spec.name}" if executed UI.message "- #{spec.name}" if executed
end end
...@@ -429,6 +433,8 @@ module Pod ...@@ -429,6 +433,8 @@ module Pod
end end
end end
#-------------------------------------------------------------------------#
public public
# @!group Hooks Data # @!group Hooks Data
...@@ -447,8 +453,6 @@ module Pod ...@@ -447,8 +453,6 @@ module Pod
end end
def pods_data def pods_data
specs = libraries.map(&:specs).flatten
root_specs = specs.map { |spec| spec.root }.uniq
root_specs.map do |spec| root_specs.map do |spec|
pod_data(spec) pod_data(spec)
end end
...@@ -466,5 +470,18 @@ module Pod ...@@ -466,5 +470,18 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
private
# @!group Private helpers
# @return [Array<Specification>] All the root specifications of the
# installation.
#
def root_specs
analysis_result.specifications.map { |spec| spec.root }.uniq
end
#-------------------------------------------------------------------------#
end end
end end
This diff is collapsed.
...@@ -86,6 +86,19 @@ module Pod ...@@ -86,6 +86,19 @@ module Pod
root.rmtree root.rmtree
end end
#
#
#
def clean_pod(name)
root_name = Specification.root_name(name)
unless local?(root_name)
path = pod_dir(name)
path.rmtree if path.exist?
end
podspe_path = specification_path(name)
podspe_path.rmtree if podspe_path
end
# @return [String] a string representation suitable for debugging. # @return [String] a string representation suitable for debugging.
# #
def inspect def inspect
......
...@@ -49,8 +49,7 @@ module Pod ...@@ -49,8 +49,7 @@ module Pod
#--------------------------------------# #--------------------------------------#
it "computes the state of the Podfile respect to the Lockfile" do it "computes the state of the Podfile respect to the Lockfile" do
@analyzer.analyze state = @analyzer.analyze.podfile_state
state = @analyzer.podfile_state
state.added.should == ["AFNetworking", "libextobjc"] state.added.should == ["AFNetworking", "libextobjc"]
state.changed.should == ["JSONKit"] state.changed.should == ["JSONKit"]
state.unchanged.should == ["SVPullToRefresh"] state.unchanged.should == ["SVPullToRefresh"]
...@@ -74,8 +73,7 @@ module Pod ...@@ -74,8 +73,7 @@ module Pod
#--------------------------------------# #--------------------------------------#
it "generates the libraries which represent the target definitions" do it "generates the libraries which represent the target definitions" do
@analyzer.analyze libs = @analyzer.analyze.libraries
libs = @analyzer.libraries
libs.map(&:name).should == ['Pods'] libs.map(&:name).should == ['Pods']
lib = libs.first lib = libs.first
lib.support_files_root.should == config.sandbox.root lib.support_files_root.should == config.sandbox.root
...@@ -90,8 +88,7 @@ module Pod ...@@ -90,8 +88,7 @@ module Pod
it "generates configures the library appropriately if the installation will not integrate" do it "generates configures the library appropriately if the installation will not integrate" do
config.integrate_targets = false config.integrate_targets = false
@analyzer.analyze lib = @analyzer.analyze.libraries.first
lib = @analyzer.libraries.first
lib.user_project_path.should == config.installation_root lib.user_project_path.should == config.installation_root
lib.user_target_uuids.should == [] lib.user_target_uuids.should == []
...@@ -115,8 +112,7 @@ module Pod ...@@ -115,8 +112,7 @@ module Pod
#--------------------------------------# #--------------------------------------#
it "resolves the dependencies" do it "resolves the dependencies" do
@analyzer.analyze @analyzer.analyze.specifications.map(&:to_s).should == [
@analyzer.specifications.map(&:to_s).should == [
"AFNetworking (1.0.1)", "AFNetworking (1.0.1)",
"JSONKit (1.5pre)", "JSONKit (1.5pre)",
"SVPullToRefresh (0.4)", "SVPullToRefresh (0.4)",
...@@ -134,8 +130,7 @@ module Pod ...@@ -134,8 +130,7 @@ module Pod
end end
it "adds the specifications to the correspondent libraries in after the resolution" do it "adds the specifications to the correspondent libraries in after the resolution" do
@analyzer.analyze @analyzer.analyze.libraries.first.specs.map(&:to_s).should == [
@analyzer.libraries.first.specs.map(&:to_s).should == [
"AFNetworking (1.0.1)", "AFNetworking (1.0.1)",
"JSONKit (1.5pre)", "JSONKit (1.5pre)",
"SVPullToRefresh (0.4)", "SVPullToRefresh (0.4)",
...@@ -169,8 +164,7 @@ module Pod ...@@ -169,8 +164,7 @@ module Pod
it "computes the state of the Sandbox respect to the resolved dependencies" do it "computes the state of the Sandbox respect to the resolved dependencies" do
@analyzer.stubs(:lockfile).returns(nil) @analyzer.stubs(:lockfile).returns(nil)
@analyzer.analyze state = @analyzer.analyze.sandbox_state
state = @analyzer.sandbox_state
state.added.sort.should == ["AFNetworking", "JSONKit", "SVPullToRefresh", "libextobjc"] state.added.sort.should == ["AFNetworking", "JSONKit", "SVPullToRefresh", "libextobjc"]
end end
......
This diff is collapsed.
...@@ -36,6 +36,24 @@ module Pod ...@@ -36,6 +36,24 @@ module Pod
File.directory?(temporary_directory + 'Sandbox').should.be.false File.directory?(temporary_directory + 'Sandbox').should.be.false
end end
it "cleans any trace of the Pod with the given name" do
pod_root = @sandbox.root + 'BananaLib'
pod_root.mkpath
@sandbox.store_podspec('BananaLib', fixture('banana-lib/BananaLib.podspec'))
specification_path = @sandbox.specification_path('BananaLib')
@sandbox.clean_pod('BananaLib')
pod_root.should.not.exist
specification_path.should.not.exist
end
it "doesn't remove the root of local Pods while cleaning" do
pod_root = @sandbox.root + 'BananaLib'
@sandbox.stubs(:local?).returns(true)
pod_root.mkpath
@sandbox.clean_pod('BananaLib')
pod_root.should.exist
end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment