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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cocoapod overwrite change made in project after post_install #7432

Closed
1 task done
neofly opened this issue Feb 13, 2018 · 4 comments 路 Fixed by #9391
Closed
1 task done

Cocoapod overwrite change made in project after post_install #7432

neofly opened this issue Feb 13, 2018 · 4 comments 路 Fixed by #9391
Labels
t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome!
Milestone

Comments

@neofly
Copy link

neofly commented Feb 13, 2018

Report 馃寛

When I modify the project in post_install, some of my change are overwrited after pod finish.

Podfile

platform :ios, '8.0'

post_install do |installer|
  test_proj = installer.aggregate_targets.find do |target| 
    target.user_project.root_object.name == "Test"
  end.user_project
    
  test_target = test_proj.native_targets.find { |target| target.name == "Test"}
  
  to_del = test_proj.native_targets.find_all { |target| target.name.start_with?("NewTest") }
  test_proj.targets.delete(to_del)
  
  target = test_proj.new_target(test_target.symbol_type, "NewTest", test_target.platform_name, test_target.deployment_target)
  
  target.build_configurations.clear
  test_target.build_configurations.each do |item|
    build = test_proj.new(Xcodeproj::Project::XCBuildConfiguration)
    build.name = item.name
    build.base_configuration_reference = item.base_configuration_reference
    build.build_settings.update(item.build_settings)
        
    target.build_configurations << build
  end
  
  # copy build_phases
  target.build_phases.clear
  test_target.build_phases.each do |src|
    dst = test_proj.new(src.class)
    target.build_phases << dst

    if (src.is_a?(Xcodeproj::Project::PBXShellScriptBuildPhase))
      dst.name = "#{src.name}"
      dst.input_paths = src.input_paths
      dst.output_paths = src.output_paths
      dst.shell_path = src.shell_path
      dst.shell_script = src.shell_script
      dst.show_env_vars_in_log = src.show_env_vars_in_log
    else
      src.files.each do |f|
        build_file = test_proj.new(Xcodeproj::Project::Object::PBXBuildFile)
        build_file.file_ref = f.file_ref
        dst.files << build_file
      end
    end
  end
  
  test_proj.save()
  
  sleep(100)
end

target 'Test' do
  
end

Bug

What I do is just copying the target. When the project is opened before sleep end, everything is correct. After, configuration file for my new target is missing, and some build phase are deleted.

CocoaPods Environment

Stack

   CocoaPods : 1.4.0
        Ruby : ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
    RubyGems : 2.5.2
        Host : Mac OS X 10.13 (17A365)
       Xcode : 9.2 (9C40b)
         Git : git version 2.14.3 (Apple Git-98)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 21d6bc804ed8858b89e89cbe290b52faf0bf534a

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-deintegrate : 1.0.2
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.3.0
cocoapods-try         : 1.1.0

Project that demonstrates the issue

Just create a empty project in Xcode and copy my podfile.

馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛馃寛

@segiddins segiddins added the t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome! label Feb 13, 2018
@amorde
Copy link
Member

amorde commented Apr 26, 2019

Dug into this a bit, the target is being de-integrated since it is not included in the Podfile, and because the xcconfig is a CocoaPod xcconfig we are removing it as you'd expect when running pod deintegrate or when removing the target 'MyTarget' declaration in the Podfile.

To solve this, we'd need to either:

  1. Integrate before calling the post_install hook
  2. Provide another hook that is run after integrating the user project
  3. Detect targets that were added in the post_install hook (not a great solution IMO)

@dnkoutso
Copy link
Contributor

dnkoutso commented Dec 4, 2019

Provide another hook that is run after integrating the user project

I like that, perhaps a post_integrate API.

@dnkoutso dnkoutso added this to the 1.10.0 milestone Feb 27, 2020
@dnkoutso
Copy link
Contributor

This was implemented with CocoaPods/Core#606 and #9391

@dnkoutso dnkoutso linked a pull request Mar 10, 2020 that will close this issue
@sphanley
Copy link

Sorry to bump an old closed issue, but I came across this in looking for something to help with my use case. My team is interested in adding a hook that will run after the Pods project has been generated, and in a case where we've set integrate_targets to false.

The use case is that we want to trigger a custom script that parses the Pods project and performs additional logic 鈥撀燽ut we can't use the post_install, because the Pods project hasn't generated yet, and we can't use the post_integrate because it's skipped.

Would there be any openness to the idea of another hook that runs after "everything", or at some other always-executed time after the Pods project is generated? Or is there any other clever way for us to inject logic to run after a pod install is completed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants