patch-carthage-project.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. require 'xcodeproj'
  2. project_path = ARGV[0]
  3. project = Xcodeproj::Project.open(project_path)
  4. # 1) Remove targets that we do not want Carthage to build, and set the deployment target to 9.0.
  5. carthage_targets = ["BoringSSL", "CgRPC", "SwiftGRPC", "SwiftProtobuf"]
  6. targets_to_remove = project.targets.select { |target| !carthage_targets.include?(target.name) }
  7. targets_to_remove.each do |target|
  8. target.remove_from_project
  9. end
  10. project.save
  11. # 2) Add SwiftProtobuf to the build actions list
  12. schemePath = Xcodeproj::XCScheme.shared_data_dir(project_path) + "SwiftGRPC-Package.xcscheme"
  13. scheme = Xcodeproj::XCScheme.new(schemePath)
  14. target = project.targets.select { |target| target.name == "SwiftProtobuf" }.first
  15. newBuildAction = Xcodeproj::XCScheme::BuildAction::Entry.new(target)
  16. newBuildAction.build_for_archiving = true
  17. newBuildAction.build_for_profiling = true
  18. newBuildAction.build_for_running = true
  19. newBuildAction.build_for_testing = true
  20. scheme.build_action.add_entry(newBuildAction)
  21. # 3) Add a "Pre-Actions" script to the "BuildAction" of SwiftGRPC-Package.xcscheme.
  22. # The Pre-Actions script will resolve the SPM dependencies and fix the corresponding paths in SwiftGRPC-Carthage.xcodeproj before the BuildAction
  23. buildActions = scheme.build_action.xml_element
  24. preActions = REXML::Element.new("PreActions")
  25. executionAction = REXML::Element.new("ExecutionAction", preActions)
  26. executionAction.add_attribute("ActionType","Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction")
  27. actionContent = REXML::Element.new("ActionContent", executionAction)
  28. actionContent.add_attribute("title", "Run Script")
  29. scriptText = "cd ${PROJECT_DIR}; swift package resolve; ruby fix-carthage-paths.rb SwiftGRPC-Carthage.xcodeproj"
  30. actionContent.add_attribute("scriptText", scriptText)
  31. environmentBuildable = REXML::Element.new("EnvironmentBuildable", actionContent)
  32. buildableReference = REXML::Element.new("BuildableReference", environmentBuildable)
  33. buildableReference.add_attribute("BuildableIdentifier","primary")
  34. buildableReference.add_attribute("BlueprintIdentifier","SwiftProtobuf::SwiftProtobuf")
  35. buildableReference.add_attribute("BuildableName","SwiftProtobuf.framework")
  36. buildableReference.add_attribute("BlueprintName","SwiftProtobuf")
  37. buildableReference.add_attribute("ReferencedContainer","container:SwiftGRPC-Carthage.xcodeproj")
  38. buildActions.unshift(preActions)
  39. scheme.save!