Skip to content

Commit

Permalink
Merge pull request #281 from CocoaPods/seg-podfile-refactor
Browse files Browse the repository at this point in the history
Podfile Refactor
  • Loading branch information
segiddins committed Dec 30, 2015
2 parents 0851a1e + e04ca18 commit ca0a5d5
Show file tree
Hide file tree
Showing 21 changed files with 656 additions and 629 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

## Master

##### Breaking

* The `link_with` Podfile DSL method has been removed in favor of target
inheritance.
[Samuel Giddins](https://github.com/segiddins)

* The `:exclusive => true` Podfile DSL target option has been removed in favor
of the `inherit! :search_paths` directive.
[Samuel Giddins](https://github.com/segiddins)

* The specification of `:head` dependencies has been removed.
[Samuel Giddins](https://github.com/segiddins)

* The deprecated `:local` dependency option has been removed in favor of the
equivalent `:path` option.
[Samuel Giddins](https://github.com/segiddins)

* The deprecated `dependency` method in the Podfile DSL has been removed in
favor of the equivalent `pod` method.
[Samuel Giddins](https://github.com/segiddins)

* The deprecated `preferred_dependency` method in the Specification DSL has been
removed in favor of the equivalent `default_subspecs` method.
[Samuel Giddins](https://github.com/segiddins)

##### Enhancements

* Add support for specifying :source with a pod dependency.
Expand All @@ -24,6 +49,15 @@
[Samuel Giddins](https://github.com/segiddins)
[#267](https://github.com/CocoaPods/Core/issues/267)

* The Podfile now allows specifying installation options via the `install!`
directive.
[Samuel Giddins](https://github.com/segiddins)
[#151](https://github.com/CocoaPods/Core/issues/151)

* The Podfile now allows marking targets as `abstract` and specifying the pod
inheritance mode via the `inherit!` directive.
[Samuel Giddins](https://github.com/segiddins)

##### Bug Fixes

* Allow non-exact version matches to be equal while maintaining a sort order.
Expand Down
30 changes: 6 additions & 24 deletions lib/cocoapods-core/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ class Dependency
# should be used to resolve the dependency.
attr_accessor :podspec_repo

# @return [Bool] whether the dependency should use the podspec with the
# highest know version but force the downloader to checkout the
# `head` of the source repository.
#
attr_accessor :head
alias_method :head?, :head

# @overload initialize(name, requirements)
#
# @param [String] name
Expand Down Expand Up @@ -84,6 +77,8 @@ class Dependency
# @param [Symbol] is_head
# a symbol that can be `:head` or nil.
#
# @todo Remove `:head` code once everyone has migrated past CocoaPods 1.0.
#
# @example Initialization with the head option
#
# Dependency.new('RestKit', :head)
Expand All @@ -109,12 +104,9 @@ def initialize(name = nil, *requirements)
end

elsif requirements.last == :head
@head = true
requirements.pop
unless requirements.empty?
raise Informative, 'A `:head` dependency may not specify version ' \
"requirements (#{name})."
end
raise Informative, '`:head` dependencies have been removed. Please use ' \
"normal external source dependencies (`:git => 'GIT_REPO_URL'`) " \
"instead of `:head` for `#{name}`."
end

if requirements.length == 1 && requirements.first.is_a?(Requirement)
Expand Down Expand Up @@ -159,7 +151,7 @@ def external?
#
def local?
if external_source
external_source[:path] || external_source[:local]
external_source[:path]
end
end

Expand Down Expand Up @@ -209,7 +201,6 @@ def root_name
#
def compatible?(other)
return false unless name == other.name
return false unless head? == other.head?
return false unless external_source == other.external_source

other.requirement.requirements.all? do |_operator, version|
Expand All @@ -225,7 +216,6 @@ def ==(other)
self.class == other.class &&
name == other.name &&
requirement == other.requirement &&
head? == other.head? &&
external_source == other.external_source
end
alias_method :eql?, :==
Expand Down Expand Up @@ -271,7 +261,6 @@ def merge(other)
dep = self.class.new(name, self_req.as_list.concat(other_req.as_list))
end

dep.head = head? || other.head?
if external_source || other.external_source
self_external_source = external_source || {}
other_external_source = other.external_source || {}
Expand Down Expand Up @@ -322,7 +311,6 @@ def match?(name, version)
# "libPusher (= 1.0)"
# "libPusher (~> 1.0.1)"
# "libPusher (> 1.0, < 2.0)"
# "libPusher (HEAD)"
# "libPusher (from `www.example.com')"
# "libPusher (defined in Podfile)"
# "RestKit/JSON"
Expand All @@ -333,8 +321,6 @@ def to_s
version = ''
if external?
version << external_source_description(external_source)
elsif head?
version << 'HEAD'
elsif requirement != Requirement.default
version << requirement.to_s
end
Expand Down Expand Up @@ -364,8 +350,6 @@ def self.from_string(string)
case version
when nil, /from `(.*)(`|')/
Dependency.new(name)
when /HEAD/
Dependency.new(name, :head)
else
version_requirements = version.split(',') if version
Dependency.new(name, version_requirements)
Expand Down Expand Up @@ -409,8 +393,6 @@ def external_source_description(source)
desc = "`#{source[:podspec]}`"
elsif source.key?(:path)
desc = "`#{source[:path]}`"
elsif source.key?(:local)
desc = "`#{source[:local]}`"
else
desc = "`#{source}`"
end
Expand Down
6 changes: 1 addition & 5 deletions lib/cocoapods-core/lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def checksum_data
# - added: Pods that weren't present in the Podfile.
# - changed: Pods that were present in the Podfile but changed:
# - Pods whose version is not compatible anymore with Podfile,
# - Pods that changed their head or external options.
# - Pods that changed their external options.
# - removed: Pods that were removed form the Podfile.
# - unchanged: Pods that are still compatible with Podfile.
#
Expand Down Expand Up @@ -443,10 +443,6 @@ def generate_dependencies_data(podfile)
# the values store the external source hashes of each
# dependency.
#
# @todo The downloader should generate an external source hash that
# should be store for dependencies in head mode and for those
# with external source.
#
def generate_external_sources_data(podfile)
deps = podfile.dependencies.select(&:external?)
deps = deps.sort { |d, other| d.name <=> other.name }
Expand Down
38 changes: 20 additions & 18 deletions lib/cocoapods-core/podfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def initialize(defined_in_file = nil, internal_hash = {}, &block)
@internal_hash = internal_hash
if block
default_target_def = TargetDefinition.new('Pods', self)
default_target_def.link_with_first_target = true
default_target_def.abstract = true
@root_target_definitions = [default_target_def]
@current_target_definition = default_target_def
instance_eval(&block)
Expand Down Expand Up @@ -74,6 +74,8 @@ def target_definitions
Hash[target_definition_list.map { |td| [td.name, td] }]
end

# @return [Array<TargetDefinition>] all target definitions in the podfile.
#
def target_definition_list
root_target_definitions.map { |td| [td, td.recursive_children] }.flatten
end
Expand Down Expand Up @@ -134,6 +136,14 @@ def set_arc_compatibility_flag?
get_hash_value('set_arc_compatibility_flag')
end

# @return [(String,Hash)] the installation strategy and installation options
# to be used during installation.
#
def installation_method
get_hash_value('installation_method', 'name' => 'cocoapods', 'options' => {}).
values_at('name', 'options')
end

#-------------------------------------------------------------------------#

public
Expand Down Expand Up @@ -183,6 +193,7 @@ def post_install!(installer)
# @return [Array] The keys used by the hash representation of the Podfile.
#
HASH_KEYS = %w(
installation_method
workspace
sources
plugins
Expand Down Expand Up @@ -348,7 +359,7 @@ def self.from_hash(hash, path = nil)
# @param [Object] value
# The value to store.
#
# @raise If the key is not recognized.
# @raise [StandardError] If the key is not recognized.
#
# @return [void]
#
Expand All @@ -364,35 +375,26 @@ def set_hash_value(key, value)
# @param [String] key
# The key for which the value is needed.
#
# @raise If the key is not recognized.
# @param default
# The default value to return if the internal hash has no entry for
# the given `key`.
#
# @raise [StandardError] If the key is not recognized.
#
# @return [Object] The value for the key.
#
def get_hash_value(key)
def get_hash_value(key, default = nil)
unless HASH_KEYS.include?(key)
raise StandardError, "Unsupported hash key `#{key}`"
end
internal_hash[key]
internal_hash.fetch(key, default)
end

# @return [TargetDefinition] The current target definition to which the DSL
# commands apply.
#
attr_accessor :current_target_definition

public

# @!group Deprecations
#-------------------------------------------------------------------------#

# @deprecated Deprecated in favour of the more succinct {#pod}. Remove for
# CocoaPods 1.0.
#
def dependency(name = nil, *requirements, &block)
CoreUI.warn "[DEPRECATED] `dependency' is deprecated (use `pod')"
pod(name, *requirements, &block)
end

#-------------------------------------------------------------------------#
end
end
Loading

0 comments on commit ca0a5d5

Please sign in to comment.