Przeglądaj źródła

Add make target generating an xcodeproj for Carthage.

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
Jonas Vautherin 7 lat temu
rodzic
commit
ea2babf140

+ 1 - 0
.travis.yml

@@ -58,3 +58,4 @@ script:
   - make test-plugin
   - make test-plugin
   - make test-echo
   - make test-echo
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then make xcodebuild; fi
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then make xcodebuild; fi
+  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then make clean && travis_wait 20 make build-carthage; fi

+ 12 - 3
Makefile

@@ -11,8 +11,14 @@ all:
 	cp .build/debug/protoc-gen-swiftgrpc .
 	cp .build/debug/protoc-gen-swiftgrpc .
 	
 	
 project:
 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
 test:	all
 	swift test $(CFLAGS)
 	swift test $(CFLAGS)
@@ -33,7 +39,10 @@ test-plugin:
 	diff -u /tmp/echo.grpc.swift Sources/Examples/Echo/Generated/echo.grpc.swift
 	diff -u /tmp/echo.grpc.swift Sources/Examples/Echo/Generated/echo.grpc.swift
 
 
 xcodebuild: project
 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:
 clean:
 	-rm -rf Packages
 	-rm -rf Packages

+ 15 - 0
add-swift-resolve-prebuild-phase.rb

@@ -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

+ 1 - 1
fix-project-settings.rb

@@ -1,5 +1,5 @@
 require 'xcodeproj'
 require 'xcodeproj'
-project_path = './SwiftGRPC.xcodeproj'
+project_path = ARGV[0]
 project = Xcodeproj::Project.open(project_path)
 project = Xcodeproj::Project.open(project_path)
 
 
 project.main_group.uses_tabs = '0'
 project.main_group.uses_tabs = '0'

+ 23 - 0
remove-unwanted-targets-for-carthage.rb

@@ -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