Skip to content

Commit

Permalink
Add make target generating an xcodeproj for Carthage.
Browse files Browse the repository at this point in the history
An xcodeproj needs to be present in the repo for Carthage to work.
Only 4 frameworks are enabled for Carthage builds:

- BoringSSL
- CgRPC
- SwiftGRPC
- SwiftProtobuf

The other targets are removed from SwiftGRPC-Carthage.xcodeproj.

Moreover, a prebuild script is added to the build phases of the
cartage xcodeproj file in order to download the dependencies required
by Package.swift.

The Carthage-compatible xcodeproj can be generated with the following:

    $ make project-carthage
  • Loading branch information
JonasVautherin committed Aug 12, 2018
1 parent d8b2b51 commit ea2babf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ script:
- make test-plugin
- make test-echo
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then make xcodebuild; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then make clean && travis_wait 20 make build-carthage; fi
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ all:
cp .build/debug/protoc-gen-swiftgrpc .

project:
swift package $(CFLAGS) generate-xcodeproj
@-ruby fix-project-settings.rb || echo "Consider running 'sudo gem install xcodeproj' to automatically set correct indentation settings for the generated project."
swift package $(CFLAGS) generate-xcodeproj --output SwiftGRPC.xcodeproj
@-ruby fix-project-settings.rb SwiftGRPC.xcodeproj || echo "Consider running 'sudo gem install xcodeproj' to automatically set correct indentation settings for the generated project."

project-carthage:
swift package generate-xcodeproj --output SwiftGRPC-Carthage.xcodeproj
@-ruby fix-project-settings.rb SwiftGRPC-Carthage.xcodeproj || echo "You may need to install xcodeproj ('sudo gem install xcodeproj')!"
@ruby remove-unwanted-targets-for-carthage.rb SwiftGRPC-Carthage.xcodeproj || echo "xcodeproj ('sudo gem install xcodeproj') is required in order to generate the Carthage-compatible project!"
@ruby add-swift-resolve-prebuild-phase.rb || echo "xcodeproj ('sudo gem install xcodeproj') is required in order to generate the Carthage-compatible project!"

test: all
swift test $(CFLAGS)
Expand All @@ -33,7 +39,10 @@ test-plugin:
diff -u /tmp/echo.grpc.swift Sources/Examples/Echo/Generated/echo.grpc.swift

xcodebuild: project
xcodebuild -configuration "Debug" -parallelizeTargets -target SwiftGRPC -target Echo -target Simple -target protoc-gen-swiftgrpc build
xcodebuild -project SwiftGRPC.xcodeproj -configuration "Debug" -parallelizeTargets -target SwiftGRPC -target Echo -target Simple -target protoc-gen-swiftgrpc build

build-carthage:
carthage build --no-skip-current

clean:
-rm -rf Packages
Expand Down
15 changes: 15 additions & 0 deletions add-swift-resolve-prebuild-phase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'xcodeproj'
project_path = './SwiftGRPC-Carthage.xcodeproj'
project = Xcodeproj::Project.open(project_path)

swift_protobuf_target = project.targets.select { |target| target.name == "SwiftProtobuf" }[0]
swift_protobuf_build_phases = swift_protobuf_target.build_phases

swift_protobuf_target.new_shell_script_build_phase

new_script_phase = swift_protobuf_build_phases.pop
new_script_phase.shell_script = "swift package resolve"

swift_protobuf_build_phases.unshift(new_script_phase)

project.save
2 changes: 1 addition & 1 deletion fix-project-settings.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'xcodeproj'
project_path = './SwiftGRPC.xcodeproj'
project_path = ARGV[0]
project = Xcodeproj::Project.open(project_path)

project.main_group.uses_tabs = '0'
Expand Down
23 changes: 23 additions & 0 deletions remove-unwanted-targets-for-carthage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'xcodeproj'
project_path = ARGV[0]
project = Xcodeproj::Project.open(project_path)

carthage_targets = ["BoringSSL", "CgRPC", "SwiftGRPC", "SwiftProtobuf"]
targets_to_remove = []

project.targets.each do |target|
if !carthage_targets.include?(target.name)
targets_to_remove << target
else
puts target.name
target.build_configurations.each do |config|
config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = "9.0"
end
end
end

targets_to_remove.each do |target|
target.remove_from_project
end

project.save

0 comments on commit ea2babf

Please sign in to comment.