Browse Source

Generate a Podspec for protoc plugin binaries (#869)

Wolfgang Lutz 5 years ago
parent
commit
419b441cb5
4 changed files with 55 additions and 29 deletions
  1. 1 1
      CGRPCZlib.podspec
  2. 12 3
      README.md
  3. 1 1
      gRPC-Swift.podspec
  4. 41 24
      scripts/build_podspecs.py

+ 1 - 1
CGRPCZlib.podspec

@@ -8,7 +8,7 @@ Pod::Spec.new do |s|
     s.homepage = 'https://www.grpc.io'
     s.homepage = 'https://www.grpc.io'
     s.authors  = { 'The gRPC contributors' => 'grpc-packages@google.com' }
     s.authors  = { 'The gRPC contributors' => 'grpc-packages@google.com' }
 
 
-    s.source = { :git => 'https://github.com/grpc/grpc-swift.git', :tag => s.version }
+    s.source = { :git => "https://github.com/grpc/grpc-swift.git", :tag => s.version }
 
 
     s.swift_version = '5.0'
     s.swift_version = '5.0'
     s.ios.deployment_target = '10.0'
     s.ios.deployment_target = '10.0'

+ 12 - 3
README.md

@@ -117,13 +117,22 @@ To install these plugins, just copy the two executables (`protoc-gen-swift` and
 that is part of your `PATH` environment variable. Alternatively the full path to
 that is part of your `PATH` environment variable. Alternatively the full path to
 the plugins can be specified when using `protoc`.
 the plugins can be specified when using `protoc`.
 
 
+Alternatively, you can get the latest precompiled version of the plugins by adding
+the following line to your `Podfile`:
+
+```ruby
+    pod 'gRPC-Swift-Plugins'
+```
+
+The plugins are available in the `Pods/gRPC-Swift-Plugins/` folder afterwards.
+
 ## Examples
 ## Examples
 
 
 gRPC Swift has a number of tutorials and examples available. They are split
 gRPC Swift has a number of tutorials and examples available. They are split
-across two directorys:
+across two directories:
 
 
 - [`/Sources/Examples`][examples-in-source] contains examples which do not
 - [`/Sources/Examples`][examples-in-source] contains examples which do not
-  require additional depenedencies and may be built using the Swift Package
+  require additional dependencies and may be built using the Swift Package
   Manager.
   Manager.
 - [`/Examples`][examples-out-of-source] contains examples which rely on
 - [`/Examples`][examples-out-of-source] contains examples which rely on
   external dependencies or may not be built by the Swift Package Manager (such
   external dependencies or may not be built by the Swift Package Manager (such
@@ -138,7 +147,7 @@ Some of the examples are accompanied by tutorials, including:
 
 
 ## Documentation
 ## Documentation
 
 
-The `docs` directory contains documenation, including:
+The `docs` directory contains documentation, including:
 
 
 - Options for the `protoc` plugin in [`docs/plugin.md`][docs-plugin]
 - Options for the `protoc` plugin in [`docs/plugin.md`][docs-plugin]
 - How to configure TLS in [`docs/tls.md`][docs-tls]
 - How to configure TLS in [`docs/tls.md`][docs-tls]

+ 1 - 1
gRPC-Swift.podspec

@@ -8,7 +8,7 @@ Pod::Spec.new do |s|
     s.homepage = 'https://www.grpc.io'
     s.homepage = 'https://www.grpc.io'
     s.authors  = { 'The gRPC contributors' => 'grpc-packages@google.com' }
     s.authors  = { 'The gRPC contributors' => 'grpc-packages@google.com' }
 
 
-    s.source = { :git => 'https://github.com/grpc/grpc-swift.git', :tag => s.version }
+    s.source = { :git => "https://github.com/grpc/grpc-swift.git", :tag => s.version }
 
 
     s.swift_version = '5.0'
     s.swift_version = '5.0'
     s.ios.deployment_target = '10.0'
     s.ios.deployment_target = '10.0'

+ 41 - 24
scripts/build_podspecs.py

@@ -50,16 +50,19 @@ class Dependency:
         self.use_verbatim_version = use_verbatim_version
         self.use_verbatim_version = use_verbatim_version
 
 
     def as_podspec(self):
     def as_podspec(self):
+        indent='    '
+        
         if self.use_verbatim_version:
         if self.use_verbatim_version:
-            return "    s.dependency '%s', %s\n" % (self.name, self.version)
+            return indent + "s.dependency '%s', %s\n" % (self.name, self.version)
 
 
-        return "    s.dependency '%s', '%s'\n" % (self.name, self.version)
+        return indent + "s.dependency '%s', '%s'\n" % (self.name, self.version)
 
 
 class Pod:
 class Pod:
-    def __init__(self, name, module_name, version, description, dependencies=None):
+    def __init__(self, name, module_name, version, description, dependencies=None, is_plugins_pod=False):
         self.name = name
         self.name = name
         self.module_name = module_name
         self.module_name = module_name
         self.version = version
         self.version = version
+        self.is_plugins_pod = is_plugins_pod
 
 
         if dependencies is None:
         if dependencies is None:
             dependencies = []
             dependencies = []
@@ -75,26 +78,30 @@ class Pod:
         print('Building Podspec for %s' % self.name)
         print('Building Podspec for %s' % self.name)
         print('-----------------------------------------------------------')
         print('-----------------------------------------------------------')
 
 
+        indent='    '
+        
         podspec = "Pod::Spec.new do |s|\n\n"
         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 = '%s'\n" % self.description
-        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.12'\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 ""
+        podspec += indent + "s.name = '%s'\n" % self.name
+        if not self.is_plugins_pod:
+            podspec += indent + "s.module_name = '%s'\n" % self.module_name
+        podspec += indent + "s.version = '%s'\n" % self.version
+        podspec += indent + "s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }\n"
+        podspec += indent + "s.summary = '%s'\n" % self.description
+        podspec += indent + "s.homepage = 'https://www.grpc.io'\n"
+        podspec += indent + "s.authors  = { 'The gRPC contributors' => \'grpc-packages@google.com' }\n\n"
+
+        if self.is_plugins_pod:
+            podspec += indent + "s.source = { :http => \"https://github.com/grpc/grpc-swift/releases/download/#{s.version}/protoc-grpc-swift-plugins-#{s.version}.zip\"}\n\n"
+            podspec += indent + "s.preserve_paths = '*'\n"
+        else:
+            podspec += indent + "s.source = { :git => \"https://github.com/grpc/grpc-swift.git\", :tag => s.version }\n\n"
+            podspec += indent + "s.swift_version = '5.0'\n"
+            podspec += indent + "s.ios.deployment_target = '10.0'\n"
+            podspec += indent + "s.osx.deployment_target = '10.12'\n"
+            podspec += indent + "s.tvos.deployment_target = '10.0'\n"
+            podspec += indent + "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:
         for dep in self.dependencies:
             podspec += dep.as_podspec()
             podspec += dep.as_podspec()
@@ -135,10 +142,20 @@ class PodManager:
             'Swift gRPC code generator plugin and runtime library',
             'Swift gRPC code generator plugin and runtime library',
             get_grpc_deps()
             get_grpc_deps()
         )
         )
+        
+        grpc_plugins_pod = Pod(
+            'gRPC-Swift-Plugins',
+            '',
+            self.version,
+            'Swift gRPC code generator plugin binaries',
+            [],
+            is_plugins_pod=True
+        )
 
 
-        grpc_pod.add_dependency(Dependency('CGRPCZlib'))
+        grpc_pod.add_dependency(Dependency(cgrpczlib_pod.name))
+        grpc_plugins_pod.add_dependency(Dependency(grpc_pod.name))
 
 
-        self.pods += [cgrpczlib_pod, grpc_pod]
+        self.pods += [cgrpczlib_pod, grpc_pod, grpc_plugins_pod]
 
 
     def go(self):
     def go(self):
         self.build_pods()
         self.build_pods()