Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Project] Change config defines to be prefixed
  • Loading branch information
segiddins committed Dec 30, 2015
1 parent 7a83889 commit 17702a1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
19 changes: 15 additions & 4 deletions lib/cocoapods/project.rb
Expand Up @@ -240,18 +240,29 @@ def add_podfile(podfile_path)
#
def add_build_configuration(name, type)
build_configuration = super
values = ["#{name.gsub(/[^a-zA-Z0-9_]/, '_').sub(/(^[0-9])/, '_\1').upcase}=1"]
settings = build_configuration.build_settings
definitions = Array(settings['GCC_PREPROCESSOR_DEFINITIONS'])
values.each do |value|
definitions = settings['GCC_PREPROCESSOR_DEFINITIONS'] || ['$(inherited)']
defines = [define_for_build_configuration(name)]
defines << 'DEBUG' if type == :debug
defines.each do |define|
value = "#{define}=1"
unless definitions.include?(value)
definitions << value
definitions.unshift(value)
end
end
settings['GCC_PREPROCESSOR_DEFINITIONS'] = definitions
build_configuration
end

# @param [String] name
# The name of the build configuration.
#
# @return [String] The preprocessor definition to set for the configuration.
#
def define_for_build_configuration(name)
"POD_CONFIGURATION_#{name}".gsub(/[^a-zA-Z0-9_]/, '_').upcase
end

private

# @!group Private helpers
Expand Down
23 changes: 18 additions & 5 deletions spec/unit/project_spec.rb
Expand Up @@ -383,33 +383,46 @@ def settings_for_root_configs(key)
it 'adds a preprocessor definition for build configurations' do
configuration = @project.add_build_configuration('Release', :release)
settings = configuration.build_settings
settings['GCC_PREPROCESSOR_DEFINITIONS'].should.include('RELEASE=1')
settings['GCC_PREPROCESSOR_DEFINITIONS'].should == ['POD_CONFIGURATION_RELEASE=1', '$(inherited)']
end

it "doesn't create invalid preprocessor definitions for configurations" do
configuration = @project.add_build_configuration('1 Release-Foo.bar', :release)
settings = configuration.build_settings
settings['GCC_PREPROCESSOR_DEFINITIONS'].should.include('_1_RELEASE_FOO_BAR=1')
settings['GCC_PREPROCESSOR_DEFINITIONS'].should.include('POD_CONFIGURATION_1_RELEASE_FOO_BAR=1')
end

it "doesn't duplicate values" do
original = @project.build_configuration_list['Debug']
original_settings = original.build_settings
original_settings['GCC_PREPROCESSOR_DEFINITIONS'].should ==
['DEBUG=1', '$(inherited)']
['POD_CONFIGURATION_DEBUG=1', 'DEBUG=1', '$(inherited)']

configuration = @project.add_build_configuration('Debug', :debug)
settings = configuration.build_settings
settings['GCC_PREPROCESSOR_DEFINITIONS'].should ==
['DEBUG=1', '$(inherited)']
['POD_CONFIGURATION_DEBUG=1', 'DEBUG=1', '$(inherited)']

configuration = @project.add_build_configuration('Debug-Based', :debug)
settings = configuration.build_settings
settings['GCC_PREPROCESSOR_DEFINITIONS'].should ==
['POD_CONFIGURATION_DEBUG_BASED=1', 'DEBUG=1', '$(inherited)']
end

it 'normalizes the name of the configuration' do
configuration = @project.add_build_configuration(
'My Awesome Configuration', :release)
settings = configuration.build_settings
settings['GCC_PREPROCESSOR_DEFINITIONS'].should ==
['MY_AWESOME_CONFIGURATION=1']
['POD_CONFIGURATION_MY_AWESOME_CONFIGURATION=1', "$(inherited)"]
end

it 'adds DEBUG for configurations based upon :debug' do
configuration = @project.add_build_configuration(
'Config', :debug)
settings = configuration.build_settings
settings['GCC_PREPROCESSOR_DEFINITIONS'].should ==
["POD_CONFIGURATION_CONFIG=1", "DEBUG=1", "$(inherited)"]
end
end
end
Expand Down

0 comments on commit 17702a1

Please sign in to comment.