Commit 6e2d4f6b authored by Fabio Pelosin's avatar Fabio Pelosin

[Config] Complete clean up.

parent 3e1f0a59
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
- Added Podfile to the Pods project. - Added Podfile to the Pods project.
- The `--no-clean` option of the `pod spec lint` command now displays the Pods project for inspection. - The `--no-clean` option of the `pod spec lint` command now displays the Pods project for inspection.
- CocoaPods now can infer the platform from the integrated targets. - CocoaPods now can infer the platform from the integrated targets.
- It is now possible to specify default values for the configuration in `~/.cocoapods/config.yaml`.
- Major clean up and refactor to the code base. - Major clean up and refactor to the code base.
- Extrace models to [CocoaPods-Core](https://github.com/CocoaPods/Core) gem. - Extrace models to [CocoaPods-Core](https://github.com/CocoaPods/Core) gem.
......
...@@ -8,11 +8,11 @@ gemspec ...@@ -8,11 +8,11 @@ gemspec
group :development do group :development do
gem "cocoapods-core", :git => "git://github.com/CocoaPods/Core.git" gem "cocoapods-core", :git => "git://github.com/CocoaPods/Core.git"
gem "xcodeproj", :git => "git://github.com/CocoaPods/Xcodeproj.git" gem "xcodeproj", :git => "git://github.com/CocoaPods/Xcodeproj.git"
gem "cocoapods-downloader", :git => "git://github.com/CocoaPods/cocoapods-downloader" # gem "cocoapods-downloader", :git => "git://github.com/CocoaPods/cocoapods-downloader"
# gem "cocoapods-core", :path => "../Core" # gem "cocoapods-core", :path => "../Core"
# gem "xcodeproj", :path => "../Xcodeproj" # gem "xcodeproj", :path => "../Xcodeproj"
# gem "cocoapods-downloader", :path => "../cocoapods-downloader" gem "cocoapods-downloader", :path => "../cocoapods-downloader"
gem "mocha", "~> 0.11.4" gem "mocha", "~> 0.11.4"
gem "bacon" gem "bacon"
......
...@@ -15,12 +15,6 @@ GIT ...@@ -15,12 +15,6 @@ GIT
activesupport (~> 3.2.6) activesupport (~> 3.2.6)
colored (~> 1.2) colored (~> 1.2)
GIT
remote: git://github.com/CocoaPods/cocoapods-downloader
revision: b349db398d5e9205a67974f70906fec2c7a0e588
specs:
cocoapods-downloader (0.1.0)
GIT GIT
remote: https://github.com/alloy/kicker.git remote: https://github.com/alloy/kicker.git
revision: 6430787ebf8b9305acc2d2f89ae5cf01d2cd5488 revision: 6430787ebf8b9305acc2d2f89ae5cf01d2cd5488
...@@ -46,6 +40,11 @@ PATH ...@@ -46,6 +40,11 @@ PATH
rake (~> 0.9.4) rake (~> 0.9.4)
xcodeproj (~> 0.4.0) xcodeproj (~> 0.4.0)
PATH
remote: ../cocoapods-downloader
specs:
cocoapods-downloader (0.1.0)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
......
...@@ -6,22 +6,28 @@ module Pod ...@@ -6,22 +6,28 @@ module Pod
# #
class Config class Config
# @!group Paths # The default settings for the configuration.
# @return [Pathname] the directory where the CocoaPods sources are stored.
# #
attr_accessor :repos_dir # Users can specify custom settings in `~/.cocoapods/config.yaml`.
# An example of the contents of this file might look like:
# @return [Pathname] the root of the CocoaPods installation where the
# Podfile is located.
# #
attr_accessor :project_root # ---
# skip_repo_update: true
# @return [Pathname] The root of the sandbox. # generate_docs: false
# doc_install: false
# #
# @todo Why is this needed? Can't clients use config.sandbox.root? DEFAULTS = {
# :verbose => false,
attr_accessor :project_pods_root :silent => false,
:skip_repo_update => false,
:clean => true,
:generate_docs => true,
:doc_install => true,
:integrate_targets => true,
:skip_repo_update => true,
:new_version_message => true,
}
#--------------------------------------# #--------------------------------------#
...@@ -77,7 +83,7 @@ module Pod ...@@ -77,7 +83,7 @@ module Pod
attr_accessor :skip_repo_update attr_accessor :skip_repo_update
alias_method :skip_repo_update?, :skip_repo_update alias_method :skip_repo_update?, :skip_repo_update
# @return [Bool] Whether the donwloader should use more agressive caching # @return [Bool] Whether the downloader should use more aggressive caching
# options. # options.
# #
attr_accessor :agressive_cache attr_accessor :agressive_cache
...@@ -85,52 +91,62 @@ module Pod ...@@ -85,52 +91,62 @@ module Pod
#--------------------------------------# #--------------------------------------#
# @!group Initialization
def initialize def initialize
configure_with(defaults) configure_with(DEFAULTS)
config_file = Pathname.new(ENV['HOME'] + "/.cocoapods/config.yaml") if user_settings_file.exist?
if config_file.exist?
require 'yaml' require 'yaml'
user_config = YAML.load_file(config_file) user_config = YAML.load_file(user_settings_file)
configure_with(user_config) configure_with(user_config)
end end
end
@repos_dir = Pathname.new(ENV['HOME'] + "/.cocoapods") def verbose
@project_root = Pathname.pwd @verbose && !silent
@project_pods_root = Pathname.pwd + 'Pods'
end end
# #--------------------------------------#
#
def defaults
{
# @!group Paths
# @return [Pathname] the directory where the CocoaPods sources are stored.
#
def repos_dir
@repos_dir ||= Pathname.new(ENV['HOME'] + "/.cocoapods")
end
:verbose => false, attr_writer :repos_dir
:silent => false,
:skip_repo_update => false,
:clean => true, # @return [Pathname] the root of the CocoaPods installation where the
:generate_docs => true, # Podfile is located.
:doc_install => true, #
:integrate_targets => true, def project_root
:skip_repo_update => true, @project_root ||= Pathname.pwd
:new_version_message => true,
}
end end
def configure_with(values) attr_writer :project_root
values.each do |key, value|
self.instance_variable_set("@#{key}", value) # @return [Pathname] The root of the sandbox.
end #
def project_pods_root
@project_pods_root ||= @project_root + 'Pods'
end end
attr_writer :project_pods_root
# @return [Sandbox] The sandbox of the current project.
#
def sandbox
@sandbox ||= Sandbox.new(project_pods_root)
end
# @return [Podfile] The Podfile to use for the current execution. # @return [Podfile] The Podfile to use for the current execution.
# #
def podfile def podfile
@podfile ||= begin @podfile ||= begin
Podfile.from_file(project_podfile) if project_podfile.exist? Podfile.from_file(podfile_path) if podfile_path.exist?
end end
end end
attr_writer :podfile attr_writer :podfile
...@@ -139,20 +155,35 @@ module Pod ...@@ -139,20 +155,35 @@ module Pod
# #
def lockfile def lockfile
@lockfile ||= begin @lockfile ||= begin
Lockfile.from_file(project_lockfile) if project_lockfile.exist? Lockfile.from_file(lockfile_path) if lockfile_path.exist?
end end
end end
# @return [Sandbox] The sandbox of the current project.
#
def sandbox
@sandbox ||= Sandbox.new(project_pods_root)
end
#--------------------------------------# #--------------------------------------#
# @!group Helpers # @!group Helpers
# private
# @return [Pathname] The path of the file which contains the user settings.
#
def user_settings_file
Pathname.new(ENV['HOME'] + "/.cocoapods/config.yaml")
end
# Sets the values of the attributes with the given hash.
#
# @param [Hash{String,Symbol => Object}] values_by_key
# The values of the attributes grouped by key.
#
# @return [void]
#
def configure_with(values_by_key)
values_by_key.each do |key, value|
self.instance_variable_set("@#{key}", value)
end
end
# Returns the path of the Podfile. # Returns the path of the Podfile.
# #
# @note The Podfile can be named either `CocoaPods.podfile` or `Podfile`. # @note The Podfile can be named either `CocoaPods.podfile` or `Podfile`.
...@@ -160,45 +191,47 @@ module Pod ...@@ -160,45 +191,47 @@ module Pod
# #
# @todo Rename to podfile_path. # @todo Rename to podfile_path.
# #
def project_podfile def podfile_path
unless @project_podfile unless @podfile_path
@project_podfile = project_root + 'CocoaPods.podfile' @podfile_path = project_root + 'CocoaPods.podfile'
unless @project_podfile.exist? unless @podfile_path.exist?
@project_podfile = project_root + 'Podfile' @podfile_path = project_root + 'Podfile'
end end
end end
@project_podfile @podfile_path
end end
# Returns the path of the Lockfile. # Returns the path of the Lockfile.
# #
# @note The Lockfile is named `Podfile.lock`. # @note The Lockfile is named `Podfile.lock`.
# #
# @todo Rename to lockfile_path. def lockfile_path
# @lockfile_path ||= project_root + 'Podfile.lock'
def project_lockfile
@project_lockfile ||= project_root + 'Podfile.lock'
end
# @todo this should be controlled by the sandbox
#
def headers_symlink_root
@headers_symlink_root ||= "#{project_pods_root}/Headers"
end end
#--------------------------------------# #--------------------------------------#
# @return [Config] the current config instance creating one if needed.
#
def self.instance def self.instance
@instance ||= new @instance ||= new
end end
# Sets the current config instance. If set to nil the config will be
# recreated when needed.
#
# @param [Config, Nil] the instance.
#
# @return [void]
#
def self.instance=(instance) def self.instance=(instance)
@instance = instance @instance = instance
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
# Provides support for using the configuration instance in other scopes. # Provides support for accessing the configuration instance in other
# scopes.
# #
module Mixin module Mixin
def config def config
......
...@@ -5,6 +5,7 @@ module Pod ...@@ -5,6 +5,7 @@ module Pod
class Base class Base
override_api do override_api do
def execute_command(executable, command, raise_on_failure = false) def execute_command(executable, command, raise_on_failure = false)
Executable.execute_command(executable, command, raise_on_failure = false) Executable.execute_command(executable, command, raise_on_failure = false)
end end
......
...@@ -677,8 +677,8 @@ module Pod ...@@ -677,8 +677,8 @@ module Pod
def prepare_pods_project def prepare_pods_project
UI.message "- Creating Pods project" do UI.message "- Creating Pods project" do
@pods_project = Pod::Project.new(config.sandbox) @pods_project = Pod::Project.new(config.sandbox)
if config.project_podfile.exist? if config.podfile_path.exist?
@pods_project.add_podfile(config.project_podfile) @pods_project.add_podfile(config.podfile_path)
end end
end end
end end
...@@ -802,8 +802,8 @@ module Pod ...@@ -802,8 +802,8 @@ module Pod
# #
def write_lockfiles def write_lockfiles
@lockfile = Lockfile.generate(podfile, specs_by_target.values.flatten) @lockfile = Lockfile.generate(podfile, specs_by_target.values.flatten)
UI.message "- Writing Lockfile in #{UI.path config.project_lockfile}" do UI.message "- Writing Lockfile in #{UI.path config.lockfile_path}" do
@lockfile.write_to_disk(config.project_lockfile) @lockfile.write_to_disk(config.lockfile_path)
end end
# UI.message "- Writing Manifest in #{UI.path sandbox.manifest_path}" do # UI.message "- Writing Manifest in #{UI.path sandbox.manifest_path}" do
......
...@@ -134,7 +134,7 @@ module Pod ...@@ -134,7 +134,7 @@ module Pod
# #
def path(pathname) def path(pathname)
if pathname if pathname
"`./#{pathname.relative_path_from(config.project_podfile.dirname || Pathname.pwd)}'" "`./#{pathname.relative_path_from(config.podfile_path.dirname || Pathname.pwd)}'"
else else
'' ''
end end
......
...@@ -58,13 +58,13 @@ EOS ...@@ -58,13 +58,13 @@ EOS
private private
def markdown_podfile def markdown_podfile
return '' unless Config.instance.project_podfile && Config.instance.project_podfile.exist? return '' unless Config.instance.podfile_path && Config.instance.podfile_path.exist?
<<-EOS <<-EOS
### Podfile ### Podfile
```ruby ```ruby
#{Config.instance.project_podfile.read.strip} #{Config.instance.podfile_path.read.strip}
``` ```
EOS EOS
end end
......
...@@ -7,7 +7,10 @@ module Bacon ...@@ -7,7 +7,10 @@ module Bacon
define_method(:run_requirement) do |description, spec| define_method(:run_requirement) do |description, spec|
::Pod::Config.instance = nil ::Pod::Config.instance = nil
::Pod::Config.instance.tap do |c| ::Pod::Config.instance.tap do |c|
ENV['VERBOSE_SPECS'] ? c.verbose = true : c.silent = true # c.verbose = ENV['VERBOSE_SPECS']
# c.silent = !ENV['VERBOSE_SPECS']
c.verbose = false
c.silent = true
c.repos_dir = fixture('spec-repos') c.repos_dir = fixture('spec-repos')
c.project_root = SpecHelper.temporary_directory c.project_root = SpecHelper.temporary_directory
c.doc_install = false c.doc_install = false
...@@ -18,7 +21,7 @@ module Bacon ...@@ -18,7 +21,7 @@ module Bacon
::Pod::UI.output = '' ::Pod::UI.output = ''
# The following prevents a nasty behaviour where the increments are not # The following prevents a nasty behaviour where the increments are not
# balanced when testing informatives which might lead to sections not # balanced when testing informatives which might lead to sections not
# being printed to the output as they are too neested. # being printed to the output as they are too nested.
::Pod::UI.indentation_level = 0 ::Pod::UI.indentation_level = 0
::Pod::UI.title_level = 0 ::Pod::UI.title_level = 0
......
require File.expand_path('../../spec_helper', __FILE__) require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Config" do module Pod
before do
Pod::Config.instance = nil
end
it "returns the singleton config instance" do
config.should.be.instance_of Pod::Config
end
it "returns the path to the spec-repos dir" do describe Config do
config.repos_dir.should == Pathname.new("~/.cocoapods").expand_path before do
end Config.instance = nil
end
describe "concerning a user's project, which is expected in the current working directory" do describe "In general" do
extend SpecHelper::TemporaryDirectory it "returns the singleton config instance" do
config.should.be.instance_of Config
end
it "returns the path to the project root" do it "returns the path to the spec-repos dir" do
config.project_root = nil config.repos_dir.should == Pathname.new("~/.cocoapods").expand_path
config.project_root.should == Pathname.pwd end
config.project_root = temporary_directory
end end
it "returns the path to the project Podfile if it exists" do describe "Concerning a user's project, which is expected in the current working directory" do
(temporary_directory + 'Podfile').open('w') { |f| f << '# Yo' } extend SpecHelper::TemporaryDirectory
Dir.chdir(temporary_directory) do
config.project_podfile.should == Pathname.pwd + 'Podfile' before do
config.project_root = temporary_directory
end end
end
it "returns the path to the project Podfile if specified with the extension" do it "returns the path to the project root" do
(temporary_directory + 'CocoaPods.podfile').open('w') { |f| f << '# Yo' } config.project_root.should == temporary_directory
Dir.chdir(temporary_directory) do
config.project_podfile.should == Pathname.pwd + 'CocoaPods.podfile'
end end
end
it "returns the path to the Pods directory that holds the dependencies" do it "returns the path to the project Podfile if it exists" do
config.project_pods_root.should == Pathname.pwd + 'Pods' (temporary_directory + 'Podfile').open('w') { |f| f << '# Yo' }
end config.podfile_path.should == temporary_directory + 'Podfile'
end end
it "returns the path to the project Podfile if specified with the extension" do
(temporary_directory + 'CocoaPods.podfile').open('w') { |f| f << '# Yo' }
config.podfile_path.should == temporary_directory + 'CocoaPods.podfile'
end
describe "concerning default settings" do it "returns the path to the Pods directory that holds the dependencies" do
it "prints out normal information" do config.project_pods_root.should == temporary_directory + 'Pods'
config.should.not.be.silent end
end end
it "does not print vebose information" do describe "Concerning default settings" do
config.should.not.be.verbose
before do
Config.any_instance.stubs(:user_settings_file).returns(Pathname.new('not_found'))
end
it "prints out normal information" do
config.should.not.be.silent
end
it "does not print verbose information" do
config.should.not.be.verbose
end
it "cleans SCM dirs in dependency checkouts" do
config.should.clean
end
end end
it "cleans SCM dirs in dependency checkouts" do describe "Private helpers" do
config.should.clean
it "returns the path of the user settings file" do
config.user_settings_file.should == Pathname.new("~/.cocoapods/config.yaml").expand_path
end
it "returns the path of the user settings file" do
config.user_settings_file.should == Pathname.new("~/.cocoapods/config.yaml").expand_path
end
end end
end end
end end
...@@ -43,7 +43,7 @@ describe Pod::Project do ...@@ -43,7 +43,7 @@ describe Pod::Project do
end end
it "adds the Podfile configured as a Ruby file" do it "adds the Podfile configured as a Ruby file" do
@project.add_podfile(config.project_podfile) @project.add_podfile(config.podfile_path)
f = @project['Podfile'] f = @project['Podfile']
f.name.should == 'Podfile' f.name.should == 'Podfile'
f.source_tree.should == 'SOURCE_ROOT' f.source_tree.should == 'SOURCE_ROOT'
......
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