Skip to content

Commit 2844096

Browse files
Lukasaweissi
authored andcommitted
Add Cocoapods podspec generation. (apple#568)
Motivation: A number of users have asked for the ability to install SwiftNIO via Cocoapods. This is an entirely reasonable request, so let's do it. Modifications: - Added a script that can generate, and optionally upload, podspecs. - Made a slight modification to the dependency script to provide target-specific dependencies. Result: Users can use cocoapods if they prefer.
1 parent b6473b3 commit 2844096

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Package.pins
66
*.pem
77
/docs
88
Package.resolved
9+
.podspecs

scripts/build_podspecs.sh

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftNIO open source project
5+
##
6+
## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
set -eu
17+
18+
function usage() {
19+
echo "$0 [-u] VERSION"
20+
echo
21+
echo "OPTIONS:"
22+
echo " -u: Additionally, upload the podspecs as they are generated"
23+
}
24+
25+
OPTIND=1
26+
upload=false
27+
while getopts ":u" opt; do
28+
case $opt in
29+
u)
30+
upload=true
31+
;;
32+
\?)
33+
usage
34+
exit 1
35+
;;
36+
esac
37+
done
38+
shift "$((OPTIND-1))"
39+
40+
if [[ $# -eq 0 ]]; then
41+
echo "Must provide target version"
42+
exit 1
43+
fi
44+
45+
version=$1
46+
newline=$'\n'
47+
48+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
49+
tmpfile=$(mktemp -d /tmp/.build_podspecsXXXXXX)
50+
echo "Building podspecs in $tmpfile"
51+
52+
# We have a name transformation here. We want the pod names to be
53+
# SwiftX or CX, but our target names aren't. We add SwiftX to the front
54+
# of all NIO targets, and then remove it in the source files declaration
55+
# if needed.
56+
targets=( $("${here}/list_topsorted_dependencies.sh" -l -r | grep -v "NIOPriorityQueue" | sed 's/^NIO/SwiftNIO/') )
57+
58+
for target in "${targets[@]}"; do
59+
echo "Building podspec for $target"
60+
61+
dependencies=()
62+
63+
while read -r raw_dependency; do
64+
dependencies+=( "${newline} s.dependency '$raw_dependency', s.version.to_s" )
65+
done < <("${here}/list_topsorted_dependencies.sh" -d "${target#Swift}" | grep -v "NIOPriorityQueue" | sed 's/^NIO/SwiftNIO/')
66+
67+
libraries=""
68+
69+
if [[ "$target" == "CNIOZlib" ]]; then
70+
libraries="s.libraries = 'z'"
71+
fi
72+
73+
cat > "${tmpfile}/${target}.podspec" <<- EOF
74+
Pod::Spec.new do |s|
75+
s.name = '$target'
76+
s.version = '$version'
77+
s.license = { :type => 'Apache 2.0', :file => 'LICENSE.txt' }
78+
s.summary = 'Event-driven network application framework for high performance protocol servers & clients, non-blocking.'
79+
s.homepage = 'https://github.com/apple/swift-nio'
80+
s.author = 'Apple Inc.'
81+
s.source = { :git => 'https://github.com/apple/swift-nio.git', :tag => s.version.to_s }
82+
s.documentation_url = 'https://apple.github.io/swift-nio/docs/current/NIO/index.html'
83+
s.module_name = '${target#Swift}'
84+
85+
s.swift_version = '4.1'
86+
s.cocoapods_version = '>=1.1.0'
87+
s.ios.deployment_target = '10.0'
88+
s.osx.deployment_target = '10.10'
89+
s.tvos.deployment_target = '10.0'
90+
91+
s.source_files = 'Sources/${target#Swift}/**/*.{swift,c,h}'
92+
${dependencies[*]-}
93+
$libraries
94+
end
95+
EOF
96+
97+
if $upload; then
98+
echo "Uploading ${tmpfile}/${target}.podspec"
99+
pod trunk push "${tmpfile}/${target}.podspec"
100+
fi
101+
102+
done

scripts/list_topsorted_dependencies.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function usage() {
2323
echo "OPTIONS:"
2424
echo " -l: Only dependencies of library targets"
2525
echo " -r: Reverse the output"
26+
echo " -d <PACKAGE>: Prints the dependencies of the given package"
2627
}
2728

2829
function tac_compat() {
@@ -33,14 +34,18 @@ tmpfile=$(mktemp /tmp/.list_topsorted_dependencies_XXXXXX)
3334

3435
only_libs=false
3536
do_reversed=false
36-
while getopts "lr" opt; do
37+
package_dependency=""
38+
while getopts "lrd:" opt; do
3739
case $opt in
3840
l)
3941
only_libs=true
4042
;;
4143
r)
4244
do_reversed=true
4345
;;
46+
d)
47+
package_dependency="$OPTARG"
48+
;;
4449
\?)
4550
usage
4651
exit 1
@@ -53,6 +58,12 @@ if $do_reversed; then
5358
transform=tac_compat
5459
fi
5560

61+
if [[ ! -z "$package_dependency" ]]; then
62+
swift package dump-package | jq -r ".targets |
63+
map(select(.name == \"$package_dependency\" and .type == \"regular\") | .dependencies | map(.name)) | .[] | .[]"
64+
exit 0
65+
fi
66+
5667
(
5768
cd "$here/.."
5869
if $only_libs; then

0 commit comments

Comments
 (0)