Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post_install hook doesn't respect adding GCC_PREPROCESSOR_DEFINITIONS to a specific target. #1322

Closed
yas375 opened this issue Aug 29, 2013 · 9 comments

Comments

@yas375
Copy link
Contributor

yas375 commented Aug 29, 2013

In continuation of the discussion started on SO.

I'm using MTDates in my project and would like to add a preprocessor macros MTDATES_NO_PREFIX=1 to enable short method names.

I've added a post_install hook (thanks for the proposal @alloy) to my Podfile:

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
    if target.name == 'Pods-MTDates'
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'MTDATES_NO_PREFIX=1'
      end
    end
  end
end

And I've noticed that it adds MTDATES_NO_PREFIX=1 to Debug configuration of all my Pods-* targets.

2013-08-29_1845

2013-08-29_1846

I've created a test project to demonstrate the issue.

It has Podfile with the contents:

platform :ios, :deployment_target => '6.0'

pod 'MTDates'
pod 'SVProgressHUD'
pod 'TransformerKit'

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
    if target.name == 'Pods-MTDates'
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'MTDATES_NO_PREFIX=1'
      end
    elsif target.name == 'Pods-SVProgressHUD'
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'SOMETHING_SPECAIL_FOR_SVPROGRESS=1'
      end
    end
  end
end

As you can see I've added some special preprocessor macroses for two of three libraries. So I expect that Pods-TransformerKit target has only default preprocessor macros, but it has all of them. Including MTDATES_NO_PREFIX=1 which is specific for Pods-MTDates target and SOMETHING_SPECAIL_FOR_SVPROGRESS=1 which is specific for Pods-SVProgressHUD target.

2013-08-29_1833

And please notice that Release configurations have expected preprocessor macros.

Is this a bug?

Thanks in advance.

@fabiopelosin
Copy link
Member

Can you try to print the objects id to see whether they are the same instance (they shouldn't)?

puts config.object_id
puts config.build_settings.object_id

@yas375
Copy link
Contributor Author

yas375 commented Sep 4, 2013

@irrationalfab I've modified post_install hook in my Podfile to:

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
    if target.name == 'Pods-MTDates'
      puts 'Pods-MTDates'
      target.build_configurations.each do |config|
        puts "  config.name: #{config.name}"
        puts "    config.object_id: #{config.object_id}"
        puts "    config.build_settings.object_id: #{config.build_settings.object_id}"

        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'MTDATES_NO_PREFIX=1'
      end
    elsif target.name == 'Pods-SVProgressHUD'
      puts 'Pods-SVProgressHUD'
      target.build_configurations.each do |config|
        puts "  config.name: #{config.name}"
        puts "    config.object_id: #{config.object_id}"
        puts "    config.build_settings.object_id: #{config.build_settings.object_id}"

        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'SOMETHING_SPECAIL_FOR_SVPROGRESS=1'
      end
    end
  end
end

And here it the output:

➜  TestApp git:(master) ✗ pod --version
0.23.0
➜  TestApp git:(master) ✗ pod install
Analyzing dependencies
Downloading dependencies
Using MTDates (0.9.3)
Using SVProgressHUD (0.9)
Using TransformerKit (0.2.4)
Generating Pods project
Pods-MTDates
  config.name: Release
    config.object_id: 70205035659800
    config.build_settings.object_id: 70205035674720
  config.name: Debug
    config.object_id: 70205035673960
    config.build_settings.object_id: 70205035672520
Pods-SVProgressHUD
  config.name: Release
    config.object_id: 70205040374920
    config.build_settings.object_id: 70205040373480
  config.name: Debug
    config.object_id: 70205040372740
    config.build_settings.object_id: 70205040371300
Integrating client project
➜  TestApp git:(master) ✗ 

@fabiopelosin
Copy link
Member

can you print the object id of the config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] string. I think that we forgot to dup it! If this is the case using the + method instead of << should produce the desired result.

        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] + 'SOMETHING_SPECAIL_FOR_SVPROGRESS=1'

@yas375
Copy link
Contributor Author

yas375 commented Sep 4, 2013

can you print the object id of the config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] string

@irrationalfab but it's not a string. It's an array or nil...
I've added both object_id and inspect before and after hooking so you see what it was and what it becomes after adding a macros.

Updated post_install hook:

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
    if target.name == 'Pods-MTDates'
      puts 'Pods-MTDates'
      target.build_configurations.each do |config|
        puts "  config.name: #{config.name}"
        puts "    config.object_id: #{config.object_id}"
        puts "    config.build_settings.object_id: #{config.build_settings.object_id}"
        puts "    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']"
        puts "      before hooking:"
        puts "        object_id: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].object_id}"
        puts "        inspect: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].inspect}"

        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'MTDATES_NO_PREFIX=1'

        puts "      after hooking:"
        puts "        object_id: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].object_id}"
        puts "        inspect: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].inspect}"
      end
    elsif target.name == 'Pods-SVProgressHUD'
      puts 'Pods-SVProgressHUD'
      target.build_configurations.each do |config|
        puts "  config.name: #{config.name}"
        puts "    config.object_id: #{config.object_id}"
        puts "    config.build_settings.object_id: #{config.build_settings.object_id}"
        puts "    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']"
        puts "      before hooking:"
        puts "        object_id: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].object_id}"
        puts "        inspect: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].inspect}"

        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'SOMETHING_SPECAIL_FOR_SVPROGRESS=1'

        puts "      after hooking:"
        puts "        object_id: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].object_id}"
        puts "        inspect: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].inspect}"
      end
    end
  end
end

Output:

➜  TestApp git:(master) ✗ pod install
Analyzing dependencies
Downloading dependencies
Using MTDates (0.9.3)
Using SVProgressHUD (0.9)
Using TransformerKit (0.2.4)
Generating Pods project
Pods-MTDates
  config.name: Release
    config.object_id: 70328443134080
    config.build_settings.object_id: 70328443149000
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
      before hooking:
        object_id: 4
        inspect: nil
      after hooking:
        object_id: 70328448388180
        inspect: ["$(inherited)", "MTDATES_NO_PREFIX=1"]
  config.name: Debug
    config.object_id: 70328443148240
    config.build_settings.object_id: 70328443146800
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
      before hooking:
        object_id: 70328438561320
        inspect: ["DEBUG=1", "$(inherited)"]
      after hooking:
        object_id: 70328438561320
        inspect: ["DEBUG=1", "$(inherited)", "MTDATES_NO_PREFIX=1"]
Pods-SVProgressHUD
  config.name: Release
    config.object_id: 70328447816400
    config.build_settings.object_id: 70328447814960
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
      before hooking:
        object_id: 4
        inspect: nil
      after hooking:
        object_id: 70328448408920
        inspect: ["$(inherited)", "SOMETHING_SPECAIL_FOR_SVPROGRESS=1"]
  config.name: Debug
    config.object_id: 70328447814220
    config.build_settings.object_id: 70328447812780
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
      before hooking:
        object_id: 70328438561320
        inspect: ["DEBUG=1", "$(inherited)", "MTDATES_NO_PREFIX=1"]
      after hooking:
        object_id: 70328438561320
        inspect: ["DEBUG=1", "$(inherited)", "MTDATES_NO_PREFIX=1", "SOMETHING_SPECAIL_FOR_SVPROGRESS=1"]
Integrating client project
➜  TestApp git:(master) ✗ 

@fabiopelosin
Copy link
Member

So the issue is that it is the same array.

fabiopelosin added a commit to CocoaPods/Xcodeproj that referenced this issue Sep 4, 2013
@fabiopelosin
Copy link
Member

I have added a fix, today the new version of CocoaPods should be out but the fix will not be included. However you should be able to test it easily by cloning xcodeproj and running $ rake gem:install

@yas375
Copy link
Contributor Author

yas375 commented Sep 4, 2013

@irrationalfab thank you! I also was just looking how it can be fixed. But I was much slower than you in this :) I've just found that in settings.merge!... also should be passed duplicated objects and that just dup is not enough here and we need to make a deep dup so Constants::COMMON_BUILD_SETTINGS[:debug]['GCC_PREPROCESSOR_DEFINITIONS'] would be copied as well :)
You was much more faster than I 👍
Thanks a lot! I'll test it now :)

@yas375
Copy link
Contributor Author

yas375 commented Sep 4, 2013

@irrationalfab works good! Thanks! 👍

@yas375 yas375 closed this as completed Sep 4, 2013
@fabiopelosin
Copy link
Member

🍻

jzapater pushed a commit to jzapater/CocoaPods that referenced this issue Sep 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants