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

[Config] Complete clean up.

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