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

Unable to customize schemes before projects are written. #9379

Closed
yusufoos opened this issue Dec 2, 2019 · 3 comments
Closed

Unable to customize schemes before projects are written. #9379

yusufoos opened this issue Dec 2, 2019 · 3 comments
Milestone

Comments

@yusufoos
Copy link

yusufoos commented Dec 2, 2019

🌈 We would like to modify the visibility of specific schemes before our projects are written/saved to disk.

Unfortunately, this is not supported by podfile post install hooks because projects_writer.write! overwrites the visibility of all the schemes.

run_podfile_post_install_hooks
projects_writer = Xcode::PodsProjectWriter.new(sandbox, generated_projects,
target_installation_results.pod_target_installation_results, installation_options)
projects_writer.write!

def write!
cleanup_projects(projects)
projects.each do |project|
UI.message "- Writing Xcode project file to #{UI.path project.path}" do
library_product_types = [:framework, :dynamic_library, :static_library]
results_by_native_target = Hash[pod_target_installation_results.map do |_, result|
[result.native_target, result]
end]
project.recreate_user_schemes(false) do |scheme, target|
next unless target.respond_to?(:symbol_type)
next unless library_product_types.include? target.symbol_type
installation_result = results_by_native_target[target]
next unless installation_result
installation_result.test_native_targets.each do |test_native_target|
scheme.add_test_target(test_native_target)
end
end
project.save
end
end
end

Ideally we would run_podfile_post_install_hooks after the PodsProjectWriter calls recreate_user_schemes on all the projects but before it calls save on all the projects.

I'd be willing to make a PR if this approach is acceptable.

Thanks!

@dnkoutso
Copy link
Contributor

dnkoutso commented Dec 2, 2019

We do not want to move that currently as it will break a ton of projects which they will need to add project.save to their hooks.

Additionally we actually prefer the user to be able to modify the project before project.save from CocoaPods is called because that would only write the project once which can be a slow operation and also cause various Xcode issues while its open.

@yusufoos
Copy link
Author

yusufoos commented Dec 2, 2019

I think you misunderstood, I'm proposing moving the hook to before project.save is called but after recreate_user_schemes is called. It would look something like this:

def write! 
   cleanup_projects(projects) 
  
   projects.each do |project| 
     UI.message "- Writing Xcode project file to #{UI.path project.path}" do 
       library_product_types = [:framework, :dynamic_library, :static_library] 
       results_by_native_target = Hash[pod_target_installation_results.map do |_, result| 
         [result.native_target, result] 
       end] 
       project.recreate_user_schemes(false) do |scheme, target| 
         next unless target.respond_to?(:symbol_type) 
         next unless library_product_types.include? target.symbol_type 
         installation_result = results_by_native_target[target] 
         next unless installation_result 
         installation_result.test_native_targets.each do |test_native_target| 
           scheme.add_test_target(test_native_target) 
         end 
       end 
     end 
   end

   run_podfile_post_install_hooks

   projects.each do |project| 
     project.save
   end

end 

@dnkoutso
Copy link
Contributor

dnkoutso commented Dec 2, 2019

ah...hmmm I think that would work we can try opening up a PR and see if tests fail for starters.

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