Browse Source

Add/update scripts for vendoring dependencies (#396)

Updating vendored dependencies is a lengthy process at the moment. This PR:
- Adds a new `vendor-all.sh` script that allows one to upgrade all vendored dependencies (gRPC Core, nanopb, BoringSSL) by simply calling:

```
cd scripts
./vendor-all.sh v1.14.0
```

- Moves other vendoring scripts into `scripts/`
- Updates temporary paths used for cloning `grpc` to use `scripts/tmp` instead of `third_party`
Michael Rebello 6 years ago
parent
commit
9745a760f8

+ 1 - 0
.gitignore

@@ -12,6 +12,7 @@ third_party/**
 /test.out
 /test.out
 /echo.pid
 /echo.pid
 /SwiftGRPC.xcodeproj
 /SwiftGRPC.xcodeproj
+/scripts/tmp/
 Examples/EchoWeb/dist
 Examples/EchoWeb/dist
 Examples/EchoWeb/node_modules
 Examples/EchoWeb/node_modules
 Examples/EchoWeb/package-lock.json
 Examples/EchoWeb/package-lock.json

+ 1 - 1
README.md

@@ -39,7 +39,7 @@ Then, run `pod install` from command line and use your project's generated
 
 
 ## Manual integration
 ## Manual integration
 
 
-When not using CocoaPods, Swift gRPC includes **vendored copies** of the
+When not using CocoaPods, Swift gRPC includes **[vendored copies](./scripts/vendor-all.sh)** of the
 gRPC Core library and BoringSSL (an OpenSSL fork that is used by
 gRPC Core library and BoringSSL (an OpenSSL fork that is used by
 the gRPC Core). These are built automatically in Swift Package
 the gRPC Core). These are built automatically in Swift Package
 Manager builds.
 Manager builds.

+ 0 - 2
patch-carthage-project.rb

@@ -48,5 +48,3 @@ buildableReference.add_attribute("ReferencedContainer","container:SwiftGRPC-Cart
 buildActions.unshift(preActions)
 buildActions.unshift(preActions)
 
 
 scheme.save!
 scheme.save!
-
-

+ 0 - 0
swift-vendoring.sh.template → scripts/swift-vendoring.sh.template


+ 53 - 0
scripts/vendor-all.sh

@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# Copyright 2019, gRPC Authors All rights reserved.
+#
+# 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.
+
+# This script may be used to update the vendored versions of SwiftGRPC's
+# dependencies for use with Swift Package Manager.
+# As part of this process, BoringSSL and gRPC Core are both vendored by
+# invoking their respective vendoring scripts in this directory.
+#
+# Usage: `$ ./vendor-all.sh v1.14.0` # Or whatever the gRPC core version is
+
+set -euxo pipefail
+
+TMP_DIR=./tmp
+GRPC_VERSION="$1"
+
+mkdir -p $TMP_DIR
+rm -rf $TMP_DIR/grpc
+cd $TMP_DIR
+
+# Clone gRPC Core, update its submodules, and check out the specified version.
+git clone git@github.com:grpc/grpc.git
+cd grpc
+git submodule update --init --recursive
+git checkout $GRPC_VERSION
+cd ../..
+
+# Update the vendored version of BoringSSL (removing previous versions).
+./vendor-boringssl.sh
+
+# Copy the vendoring template into the gRPC Core's directory of templates.
+# Then, run the gRPC Core's generator on that template.
+cp ./swift-vendoring.sh.template $TMP_DIR/grpc/templates
+cd $TMP_DIR/grpc
+./tools/buildgen/generate_projects.sh
+cd ../..
+
+# Finish copying the vendored version of the gRPC Core.
+./vendor-grpc.sh
+
+echo "UPDATED vendored dependencies to $GRPC_VERSION"

+ 8 - 15
vendor-boringssl.sh → scripts/vendor-boringssl.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 #!/bin/sh
-#
-# Copyright 2016, gRPC Authors All rights reserved.
+
+# Copyright 2019, gRPC Authors All rights reserved.
 #
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # you may not use this file except in compliance with the License.
@@ -13,21 +13,14 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
-#
+
 # This script creates a vendored copy of BoringSSL that is
 # This script creates a vendored copy of BoringSSL that is
 # suitable for building with the Swift Package Manager.
 # suitable for building with the Swift Package Manager.
 #
 #
-# Usage: 
-#   1. Clone github.com/grpc/grpc into the third_party directory.
-#   2. Get gRPC submodules by running "git submodule update --init"
-#      inside the gRPC directory.
-#   3. Run this script in the grpc-swift directory. It will place 
-#      a local copy of the BoringSSL sources in Sources/BoringSSL.
-#      Any prior contents of Sources/BoringSSL will be deleted.
-#
+# For usage, see `vendor-all.sh`.
 
 
-SRCROOT=third_party/grpc/third_party/boringssl
-DSTROOT=Sources/BoringSSL
+SRCROOT=./tmp/grpc/third_party/boringssl
+DSTROOT=../Sources/BoringSSL
 
 
 echo "REMOVING any previously-vendored BoringSSL code"
 echo "REMOVING any previously-vendored BoringSSL code"
 rm -rf $DSTROOT/include
 rm -rf $DSTROOT/include
@@ -56,7 +49,7 @@ EXCLUDES=(
 'example_*.c'
 'example_*.c'
 )
 )
 
 
-for pattern in "${PATTERNS[@]}" 
+for pattern in "${PATTERNS[@]}"
 do
 do
   for i in $SRCROOT/$pattern; do
   for i in $SRCROOT/$pattern; do
     path=${i#$SRCROOT}
     path=${i#$SRCROOT}
@@ -70,7 +63,7 @@ done
 echo "COPYING err_data.c from gRPC project"
 echo "COPYING err_data.c from gRPC project"
 cp ./third_party/grpc/src/boringssl/err_data.c $DSTROOT
 cp ./third_party/grpc/src/boringssl/err_data.c $DSTROOT
 
 
-for exclude in "${EXCLUDES[@]}" 
+for exclude in "${EXCLUDES[@]}"
 do
 do
   echo "EXCLUDING $exclude"
   echo "EXCLUDING $exclude"
   find $DSTROOT -d -name "$exclude" -exec rm -rf {} \;
   find $DSTROOT -d -name "$exclude" -exec rm -rf {} \;

+ 26 - 30
vendor-grpc.sh → scripts/vendor-grpc.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 #!/bin/sh
-#
-# Copyright 2016, gRPC Authors All rights reserved.
+
+# Copyright 2019, gRPC Authors All rights reserved.
 #
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # you may not use this file except in compliance with the License.
@@ -13,31 +13,27 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
-#
+
 # This script vendors the gRPC Core library into the
 # This script vendors the gRPC Core library into the
 # CgRPC module in a form suitable for building with
 # CgRPC module in a form suitable for building with
 # the Swift Package Manager.
 # the Swift Package Manager.
 #
 #
+# For usage, see `vendor-all.sh`.
 
 
-#
-# Read the list of files to vendor from the gRPC project.
-#
-# The file that is included here is a generated file.
-# To generate it, copy swift-vendoring.sh.template from
-# the grpc-swift directory to grpc/templates and then
-# run tools/buildgen/generate_projects.sh in the grpc
-# directory.
-#
-source third_party/grpc/swift-vendoring.sh 
+source ./tmp/grpc/swift-vendoring.sh
+
+TMP_DIR=./tmp
+DSTROOT=../Sources
+DSTASSETS=../Assets
 
 
 #
 #
 # Remove previously-vendored code.
 # Remove previously-vendored code.
 #
 #
 echo "REMOVING any previously-vendored gRPC code"
 echo "REMOVING any previously-vendored gRPC code"
-rm -rf Sources/CgRPC/src
-rm -rf Sources/CgRPC/grpc
-rm -rf Sources/CgRPC/third_party
-rm -rf Sources/CgRPC/include/grpc
+rm -rf $DSTROOT/CgRPC/src
+rm -rf $DSTROOT/CgRPC/grpc
+rm -rf $DSTROOT/CgRPC/third_party
+rm -rf $DSTROOT/CgRPC/include/grpc
 
 
 #
 #
 # Copy grpc headers and source files
 # Copy grpc headers and source files
@@ -45,41 +41,41 @@ rm -rf Sources/CgRPC/include/grpc
 echo "COPYING public gRPC headers"
 echo "COPYING public gRPC headers"
 for src in "${public_headers[@]}"
 for src in "${public_headers[@]}"
 do
 do
-	dest="Sources/CgRPC/$src"
+	dest="$DSTROOT/CgRPC/$src"
 	dest_dir=$(dirname $dest)
 	dest_dir=$(dirname $dest)
 	mkdir -pv $dest_dir
 	mkdir -pv $dest_dir
-	cp third_party/grpc/$src $dest
+	cp $TMP_DIR/grpc/$src $dest
 done
 done
 
 
-echo "COPYING private grpc headers"
+echo "COPYING private gRPC headers"
 for src in "${private_headers[@]}"
 for src in "${private_headers[@]}"
 do
 do
-	dest="Sources/CgRPC/$src"
+	dest="$DSTROOT/CgRPC/$src"
 	dest_dir=$(dirname $dest)
 	dest_dir=$(dirname $dest)
 	mkdir -pv $dest_dir
 	mkdir -pv $dest_dir
-	cp third_party/grpc/$src $dest
+	cp $TMP_DIR/grpc/$src $dest
 done
 done
 
 
-echo "COPYING grpc source files"
+echo "COPYING gRPC source files"
 for src in "${source_files[@]}"
 for src in "${source_files[@]}"
 do
 do
-	dest="Sources/CgRPC/$src"
+	dest="$DSTROOT/CgRPC/$src"
 	dest_dir=$(dirname $dest)
 	dest_dir=$(dirname $dest)
 	mkdir -pv $dest_dir
 	mkdir -pv $dest_dir
-	cp third_party/grpc/$src $dest
+	cp $TMP_DIR/grpc/$src $dest
 done
 done
 
 
 echo "COPYING additional nanopb headers"
 echo "COPYING additional nanopb headers"
-cp third_party/grpc/third_party/nanopb/*.h Sources/CgRPC/third_party/nanopb/
+cp $TMP_DIR/grpc/third_party/nanopb/*.h $DSTROOT/CgRPC/third_party/nanopb/
 
 
 echo "ADDING additional compiler flags to nanopb/pb.h"
 echo "ADDING additional compiler flags to nanopb/pb.h"
-perl -pi -e 's/\/\* #define PB_FIELD_16BIT 1 \*\//#define PB_FIELD_16BIT 1/' Sources/CgRPC/third_party/nanopb/pb.h
+perl -pi -e 's/\/\* #define PB_FIELD_16BIT 1 \*\//#define PB_FIELD_16BIT 1/' $DSTROOT/CgRPC/third_party/nanopb/pb.h
 
 
 echo "ADDING additional compiler flags to tsi/ssl_transport_security.cc"
 echo "ADDING additional compiler flags to tsi/ssl_transport_security.cc"
-perl -pi -e 's/#define TSI_OPENSSL_ALPN_SUPPORT 1/#define TSI_OPENSSL_ALPN_SUPPORT 0/' Sources/CgRPC/src/core/tsi/ssl_transport_security.cc
+perl -pi -e 's/#define TSI_OPENSSL_ALPN_SUPPORT 1/#define TSI_OPENSSL_ALPN_SUPPORT 0/' $DSTROOT/CgRPC/src/core/tsi/ssl_transport_security.cc
 
 
 echo "DISABLING ARES"
 echo "DISABLING ARES"
-perl -pi -e 's/#define GRPC_ARES 1/#define GRPC_ARES 0/' Sources/CgRPC/include/grpc/impl/codegen/port_platform.h
+perl -pi -e 's/#define GRPC_ARES 1/#define GRPC_ARES 0/' $DSTROOT/CgRPC/include/grpc/impl/codegen/port_platform.h
 
 
 echo "COPYING roots.pem"
 echo "COPYING roots.pem"
-cp third_party/grpc/etc/roots.pem Assets/roots.pem
+cp $TMP_DIR/grpc/etc/roots.pem $DSTASSETS/roots.pem