forked from grpc/grpc-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-carthage-project.rb
64 lines (51 loc) · 2.87 KB
/
patch-carthage-project.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'xcodeproj'
project_path = ARGV[0]
project = Xcodeproj::Project.open(project_path)
# 1) Remove targets that we do not want Carthage to build, and set the deployment target to 9.0.
carthage_targets = ["BoringSSL", "CgRPC", "SwiftGRPC", "SwiftProtobuf"]
targets_to_remove = project.targets.select { |target| !carthage_targets.include?(target.name) }
targets_to_remove.each do |target|
target.remove_from_project
end
# 2) Prevent linking of nghttp2 library
project.targets.each do |target|
target.build_configurations.each do |conf|
current_ldflags = target.build_settings(conf.name)["OTHER_LDFLAGS"]
if current_ldflags.is_a? String
target.build_settings(conf.name)["OTHER_LDFLAGS"] = "" if current_ldflags.downcase().include?("nghttp2")
else
cleaned_ldflags = current_ldflags.select { |flag| !flag.downcase().include?("nghttp2") }
target.build_settings(conf.name)["OTHER_LDFLAGS"] = cleaned_ldflags
end
end
end
project.save
# 3) Add SwiftProtobuf to the build actions list
schemePath = Xcodeproj::XCScheme.shared_data_dir(project_path) + "SwiftGRPC-Package.xcscheme"
scheme = Xcodeproj::XCScheme.new(schemePath)
target = project.targets.select { |target| target.name == "SwiftProtobuf" }.first
newBuildAction = Xcodeproj::XCScheme::BuildAction::Entry.new(target)
newBuildAction.build_for_archiving = true
newBuildAction.build_for_profiling = true
newBuildAction.build_for_running = true
newBuildAction.build_for_testing = true
scheme.build_action.add_entry(newBuildAction)
# 4) Add a "Pre-Actions" script to the "BuildAction" of SwiftGRPC-Package.xcscheme.
# The Pre-Actions script will resolve the SPM dependencies and fix the corresponding paths in SwiftGRPC-Carthage.xcodeproj before the BuildAction
buildActions = scheme.build_action.xml_element
preActions = REXML::Element.new("PreActions")
executionAction = REXML::Element.new("ExecutionAction", preActions)
executionAction.add_attribute("ActionType","Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction")
actionContent = REXML::Element.new("ActionContent", executionAction)
actionContent.add_attribute("title", "Run Script")
scriptText = "cd ${PROJECT_DIR}; swift package resolve; ruby fix-carthage-paths.rb SwiftGRPC-Carthage.xcodeproj"
actionContent.add_attribute("scriptText", scriptText)
environmentBuildable = REXML::Element.new("EnvironmentBuildable", actionContent)
buildableReference = REXML::Element.new("BuildableReference", environmentBuildable)
buildableReference.add_attribute("BuildableIdentifier","primary")
buildableReference.add_attribute("BlueprintIdentifier","SwiftProtobuf::SwiftProtobuf")
buildableReference.add_attribute("BuildableName","SwiftProtobuf.framework")
buildableReference.add_attribute("BlueprintName","SwiftProtobuf")
buildableReference.add_attribute("ReferencedContainer","container:SwiftGRPC-Carthage.xcodeproj")
buildActions.unshift(preActions)
scheme.save!