-
Notifications
You must be signed in to change notification settings - Fork 435
Add Cocoapod Support for SwiftGRPC #764
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
Merged
glbrntt
merged 8 commits into
grpc:master
from
Jake-Prickett:jake-prickett/grpc-swift-cocoapod-support
Apr 7, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cb338e8
Add Cocoapod Support for SwiftGRPC
jpricke1-ford 2741421
Add build_podspec script
jpricke1-ford 8856c87
Script Comment Cleanup
jpricke1-ford 177dea2
Update script to take in file path and add podspec files to repository
jpricke1-ford 04e73ad
Merge branch 'master' into jake-prickett/grpc-swift-cocoapod-support
Jake-Prickett 1cc3c6f
Adjust comment
jpricke1-ford c20e596
Added fix for default param value
jpricke1-ford feb557a
Adjust quotation mark usage and deployment target
jpricke1-ford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| Pod::Spec.new do |s| | ||
|
|
||
| s.name = 'CGRPCZlib' | ||
| s.module_name = 'CGRPCZlib' | ||
| s.version = '1.0.0-alpha.11' | ||
| s.license = { :type => 'Apache 2.0', :file => 'LICENSE' } | ||
| s.summary = 'Swift gRPC code generator plugin and runtime library' | ||
| s.homepage = 'https://www.grpc.io' | ||
| s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } | ||
|
|
||
| s.source = { :git => 'https://github.com/grpc/grpc-swift.git', :tag => s.version } | ||
|
|
||
| s.swift_version = '5.0' | ||
| s.ios.deployment_target = '10.0' | ||
| s.osx.deployment_target = '10.10' | ||
| s.tvos.deployment_target = '10.0' | ||
| s.source_files = 'Sources/CGRPCZlib/**/*.{swift,c,h}' | ||
|
|
||
| end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| Pod::Spec.new do |s| | ||
|
|
||
| s.name = 'gRPC-Swift' | ||
| s.module_name = 'GRPC' | ||
| s.version = '1.0.0-alpha.11' | ||
| s.license = { :type => 'Apache 2.0', :file => 'LICENSE' } | ||
| s.summary = 'Swift gRPC code generator plugin and runtime library' | ||
| s.homepage = 'https://www.grpc.io' | ||
| s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } | ||
|
|
||
| s.source = { :git => 'https://github.com/grpc/grpc-swift.git', :tag => s.version } | ||
|
|
||
| s.swift_version = '5.0' | ||
| s.ios.deployment_target = '10.0' | ||
| s.osx.deployment_target = '10.10' | ||
| s.tvos.deployment_target = '10.0' | ||
| s.source_files = 'Sources/GRPC/**/*.{swift,c,h}' | ||
|
|
||
| s.dependency 'Logging', '1.2.0' | ||
| s.dependency 'SwiftNIO', '2.15.0' | ||
| s.dependency 'SwiftNIOHTTP2', '1.11.0' | ||
| s.dependency 'SwiftNIOSSL', '2.7.1' | ||
| s.dependency 'SwiftNIOTransportServices', '1.3.0' | ||
| s.dependency 'SwiftProtobuf', '1.8.0' | ||
| s.dependency 'CGRPCZlib', s.version.to_s | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # Copyright 2020, gRPC Authors All rights reserved. | ||
Jake-Prickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
| import json | ||
| import random | ||
| import string | ||
| import argparse | ||
|
|
||
| class Dependency: | ||
| def __init__(self, name, version='s.version.to_s', useVerbatimVersion=True): | ||
| self.name = name | ||
| self.version = version | ||
| self.useVerbatimVersion = useVerbatimVersion | ||
|
|
||
| def as_podspec(self): | ||
| if self.useVerbatimVersion: | ||
| return " s.dependency '%s', %s\n" % (self.name, self.version) | ||
| else: | ||
| return " s.dependency '%s', '%s'\n" % (self.name, self.version) | ||
|
|
||
| class Pod: | ||
| def __init__(self, name, module_name, version, dependencies=None): | ||
| self.name = name | ||
| self.module_name = module_name | ||
| self.version = version | ||
|
|
||
| if dependencies is None: | ||
| dependencies = [] | ||
|
|
||
| self.dependencies = dependencies | ||
|
|
||
| def add_dependency(self, dependency): | ||
| self.dependencies.append(dependency) | ||
|
|
||
| def as_podspec(self): | ||
| print('\n') | ||
| print('Building Podspec for %s' % self.name) | ||
| print('-----------------------------------------------------------') | ||
|
|
||
| podspec = "Pod::Spec.new do |s|\n\n" | ||
| podspec += " s.name = '%s'\n" % self.name | ||
| podspec += " s.module_name = '%s'\n" % self.module_name | ||
| podspec += " s.version = '%s'\n" % self.version | ||
| podspec += " s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }\n" | ||
| podspec += " s.summary = 'Swift gRPC code generator plugin and runtime library'\n" | ||
| podspec += " s.homepage = 'https://www.grpc.io'\n" | ||
| podspec += " s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' }\n\n" | ||
|
|
||
| podspec += " s.source = { :git => 'https://github.com/grpc/grpc-swift.git', :tag => s.version }\n\n" | ||
|
|
||
| podspec += " s.swift_version = '5.0'\n" | ||
|
|
||
| podspec += " s.ios.deployment_target = '10.0'\n" | ||
| podspec += " s.osx.deployment_target = '10.10'\n" | ||
| podspec += " s.tvos.deployment_target = '10.0'\n" | ||
|
|
||
| podspec += " s.source_files = 'Sources/%s/**/*.{swift,c,h}'\n" % (self.module_name) | ||
|
|
||
| podspec += "\n" if len(self.dependencies) > 0 else "" | ||
|
|
||
| for dep in self.dependencies: | ||
| podspec += dep.as_podspec() | ||
|
|
||
| podspec += "\nend" | ||
| return podspec | ||
|
|
||
| class PodManager: | ||
| pods = [] | ||
|
|
||
| def __init__(self, directory, version, should_publish): | ||
| self.directory = directory | ||
| self.version = version | ||
| self.should_publish = should_publish | ||
|
|
||
| def write(self, pod, contents): | ||
| print(' Writing to %s/%s.podspec ' % (self.directory, pod)) | ||
| with open('%s/%s.podspec' % (self.directory, pod), 'w') as f: | ||
| f.write(contents) | ||
|
|
||
| def publish(self, pod_name): | ||
| os.system('pod repo update') | ||
Jake-Prickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| print(' Publishing %s.podspec' % (pod_name)) | ||
| os.system('pod repo push %s/%s.podspec' % (self.directory, pod_name)) | ||
|
|
||
| def build_pods(self): | ||
| CGRPCZlibPod = Pod('CGRPCZlib', 'CGRPCZlib', self.version) | ||
|
|
||
| GRPCPod = Pod('gRPC-Swift', 'GRPC', self.version, get_grpc_deps()) | ||
| GRPCPod.add_dependency(Dependency('CGRPCZlib')) | ||
|
|
||
| self.pods += [CGRPCZlibPod, GRPCPod] | ||
|
|
||
| def go(self): | ||
| self.build_pods() | ||
| # Create .podspec files and publish | ||
| for target in self.pods: | ||
| self.write(target.name, target.as_podspec()) | ||
| if self.should_publish: | ||
| self.publish(target.name) | ||
| else: | ||
| print(' Skipping Publishing...') | ||
|
|
||
| def process_package(string): | ||
| pod_mappings = { | ||
| 'swift-log': 'Logging', | ||
| 'swift-nio': 'SwiftNIO', | ||
| 'swift-nio-http2': 'SwiftNIOHTTP2', | ||
| 'swift-nio-ssl': 'SwiftNIOSSL', | ||
| 'swift-nio-transport-services': 'SwiftNIOTransportServices', | ||
| 'SwiftProtobuf': 'SwiftProtobuf' | ||
| } | ||
|
|
||
| return pod_mappings[string] | ||
|
|
||
| def get_grpc_deps(): | ||
| with open('Package.resolved') as f: | ||
| data = json.load(f) | ||
|
|
||
| deps = [] | ||
|
|
||
| for obj in data['object']['pins']: | ||
| package = process_package(obj['package']) | ||
| version = obj['state']['version'] | ||
|
|
||
| deps.append(Dependency(package, version, False)) | ||
|
|
||
| return deps | ||
|
|
||
| def dir_path(string): | ||
| if os.path.isdir(string): | ||
| return string | ||
| else: | ||
| raise NotADirectoryError(string) | ||
|
|
||
Jake-Prickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def main(): | ||
| # Setup | ||
|
|
||
| parser = argparse.ArgumentParser(description='Build Podspec files for SwiftGRPC') | ||
|
|
||
| parser.add_argument( | ||
| '-p', | ||
| '--path', | ||
| type=dir_path, | ||
| help='The directory where generated podspec files will be saved. If not passed, defaults to place in the current working directory.' | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| '-u', | ||
| '--upload', | ||
| action='store_true', | ||
| help='Determines if the newly built Podspec files should be pushed.' | ||
| ) | ||
|
|
||
| parser.add_argument('version') | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| should_publish = args.upload | ||
| version = args.version | ||
| path = args.path | ||
|
|
||
| if not path: | ||
| path = os.getcwd() | ||
|
|
||
| pod_manager = PodManager(path, version, should_publish) | ||
| pod_manager.go() | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should CGRPCZlib have a different summary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can, I was thinking having something more generic that might fit both would keep the generation script simple. What do you think @MrMage? I'm open to either way 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would use a slightly different description for each, to avoid confusing anyone who looks up either package at the CocoaPods site. I understand that would need a bit of additional code, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, that does make sense. Would you mind if I took that one up as a follow-up item and address it separately?