Skip to content

Commit

Permalink
Add project_name DSL to allow grouping pods into projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Jun 27, 2019
1 parent e46c3ef commit fef4942
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

##### Enhancements

* Add `project_name` DSL to allow grouping pods into projects.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#547](https://github.com/CocoaPods/Core/pull/547)

* Allow test specs to specify an `app_host_name` to point to an app spec whose
application is used as the test's app host.
[jkap](https://github.com/jkap)
Expand Down
39 changes: 39 additions & 0 deletions lib/cocoapods-core/podfile/target_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ def script_phases

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

# @return [String] The project name to use for the given pod name or `nil` if none specified.
#
# @note When querying for a subspec then use the root pod spec name instead as this is what's stored.
#
def project_name_for_pod(pod_name)
raw_project_names_hash[pod_name]
end

#--------------------------------------#
#
# @return [Bool] whether the target definition should inhibit warnings
# for a single pod. If inhibit_all_warnings is true, it will
# return true for any asked pod.
Expand Down Expand Up @@ -666,6 +676,7 @@ def store_pod(name, *requirements)
parse_inhibit_warnings(name, requirements)
parse_modular_headers(name, requirements)
parse_configuration_whitelist(name, requirements)
parse_project_name(name, requirements)

if requirements && !requirements.empty?
pod = { name => requirements }
Expand Down Expand Up @@ -769,6 +780,7 @@ def store_script_phase(options)
use_modular_headers
user_project_path
build_configurations
project_names
dependencies
script_phases
children
Expand Down Expand Up @@ -1041,6 +1053,33 @@ def parse_modular_headers(name, requirements)
requirements.pop if options.empty?
end

# Removes :project_name from the requirements list, and adds
# the pods name into internal hash.
#
# @param [String] name The name of the pod
#
# @param [Array] requirements
# If :project_name is the only key in the hash, the hash
# should be destroyed because it confuses Gem::Dependency.
#
# @return [void]
#
def parse_project_name(name, requirements)
options = requirements.last
return requirements unless options.is_a?(Hash)

project_name = options.delete(:project_name)
pod_name = Specification.root_name(name)
raw_project_names_hash[pod_name] = project_name if project_name

requirements.pop if options.empty?
end

def raw_project_names_hash
get_hash_value('project_names', {})
end
private :raw_project_names_hash

# Removes :configurations or :configuration from the requirements list,
# and adds the pod's name into the internal hash for which pods should be
# linked in which configuration only.
Expand Down
11 changes: 11 additions & 0 deletions spec/podfile/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ module Pod
end
end

describe 'project names' do
it 'sets the project name for a given pod' do
podfile = Podfile.new do
pod 'PonyDebugger', :project_name => 'PonyProject'
end

target = podfile.target_definitions['Pods']
target.project_name_for_pod('PonyDebugger').should == 'PonyProject'
end
end

describe 'modular headers' do
it 'does not have modular headers by default' do
podfile = Podfile.new do
Expand Down
14 changes: 11 additions & 3 deletions spec/podfile/target_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ module Pod

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

it 'stores the project name for a given pod' do
@parent.store_pod('ASIHTTPRequest', :project_name => 'SomeProject')
@parent.project_name_for_pod('ASIHTTPRequest').should == 'SomeProject'
@parent.project_name_for_pod('UnknownPod').should.be.nil
end

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

it 'returns if it should use frameworks' do
@parent.use_frameworks!
@parent.should.uses_frameworks?
Expand Down Expand Up @@ -508,7 +516,7 @@ module Pod
@child.all_whitelisted_configurations.sort.should == %w(Debug Release)
end

it 'whitelistes pod configurations with testspecs' do
it 'whitelists pod configurations with testspecs' do
@parent.build_configurations = { 'Debug' => :debug, 'Release' => :release }
@parent.store_pod('RestKit', :testspecs => %w(Tests), :configuration => 'Debug')
@parent.should.pod_whitelisted_for_configuration?('RestKit', 'Debug')
Expand All @@ -517,7 +525,7 @@ module Pod
@parent.should.not.pod_whitelisted_for_configuration?('RestKit/Tests', 'Release')
end

it 'whitelistes pod configurations with appspecs' do
it 'whitelists pod configurations with appspecs' do
@parent.build_configurations = { 'Debug' => :debug, 'Release' => :release }
@parent.store_pod('RestKit', :appspecs => %w(App), :configuration => 'Debug')
@parent.should.pod_whitelisted_for_configuration?('RestKit', 'Debug')
Expand All @@ -526,7 +534,7 @@ module Pod
@parent.should.not.pod_whitelisted_for_configuration?('RestKit/App', 'Release')
end

it 'whitelistes pod configurations with appspecs and testspecs' do
it 'whitelists pod configurations with appspecs and testspecs' do
@parent.build_configurations = { 'Debug' => :debug, 'Release' => :release }
@parent.store_pod('RestKit', :testspecs => %w(Tests), :configuration => 'Debug')
@parent.store_pod('RestKit', :appspecs => %w(App), :configuration => 'Debug')
Expand Down

0 comments on commit fef4942

Please sign in to comment.