-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathinstall-swift.sh
executable file
·104 lines (94 loc) · 3.86 KB
/
install-swift.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
##
# Copyright IBM Corporation 2016,2017,2018
#
# 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 builds the Swift package on Travis CI.
# If running on the OS X platform, homebrew (http://brew.sh/) must be installed
# for this script to work.
# If any commands fail, we want the shell script to exit immediately.
set -e
# Determine SWIFT_SNAPSHOT for build
if [ -z $SWIFT_SNAPSHOT ]; then
echo ">> No 'SWIFT_SNAPSHOT' set, checking for existing Swift install..."
if which swift > /dev/null; then
SWIFT_SNAPSHOT=$(swift --version 2>/dev/null | grep 'Swift version' | sed 's/^.*Swift version \([0-9][0-9\.]*\) .*$/\1/; ')
echo ">> Use existing swift version: ${SWIFT_SNAPSHOT}"
else
echo ">> No 'SWIFT_SNAPSHOT' set and no existing install, checking for .swift-version file..."
if [ -f "$projectFolder/.swift-version" ]; then
echo ">> Found .swift-version file."
SWIFT_SNAPSHOT="$(cat $projectFolder/.swift-version)";
# Else use default
else
echo ">> No swift-version file found, using default value: $DEFAULT_SWIFT"
SWIFT_SNAPSHOT=$DEFAULT_SWIFT
fi
fi
fi
#If SWIFT_SNAPSHOT is a URL then we call the alternative download function
if [[ $SWIFT_SNAPSHOT == https* ]]; then
# Starts script to install Swift.
source ${projectFolder}/Package-Builder/${osName}/install_swift_from_url.sh
else
# reconcile version with naming conventions by prepending "swift-" if nesseccary
if [[ $SWIFT_SNAPSHOT == *"swift-"* ]]; then
export SWIFT_SNAPSHOT
else
echo ">> Normalizing SWIFT_VERSION from .swift-version file."
prefix="swift-"
export SWIFT_SNAPSHOT=$prefix$SWIFT_SNAPSHOT
fi
echo ">> SWIFT_SNAPSHOT: $SWIFT_SNAPSHOT"
if [[ ${SWIFT_SNAPSHOT} =~ ^.*RELEASE.*$ ]]; then
SNAPSHOT_TYPE=$(echo "$SWIFT_SNAPSHOT" | tr '[:upper:]' '[:lower:]')
elif [[ ${SWIFT_SNAPSHOT} =~ ^swift-.*-DEVELOPMENT.*$ ]]; then
SNAPSHOT_TYPE=${SWIFT_SNAPSHOT%-DEVELOPMENT*}-branch
elif [[ ${SWIFT_SNAPSHOT} =~ ^.*DEVELOPMENT.*$ ]]; then
SNAPSHOT_TYPE=development
else
SNAPSHOT_TYPE="$(echo "$SWIFT_SNAPSHOT" | tr '[:upper:]' '[:lower:]')-release"
SWIFT_SNAPSHOT="${SWIFT_SNAPSHOT}-RELEASE"
fi
# Swift has to be installed to run commands, if Swift isn't installed, skip checks.
if [[ $(swift --version) ]]; then
# Get the version already installed, if any. OS dependant.
if [[ "$OSTYPE" == "darwin"* ]]; then
SWIFT_PREINSTALL="swift-$(swift --version | awk '{print $4}')"
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
SWIFT_PREINSTALL="swift-$(swift --version | awk '{print $3}')"
else
echo "Unsupported OS. Exiting..."
exit 1
fi
fi
# Checks for if the needed version of swift matches the one already on the system.
if [[ $SWIFT_PREINSTALL == "" ]]; then
echo "Swift is not installed."
source ${projectFolder}/Package-Builder/${osName}/install_swift_binaries.sh
else
if [[ ${SWIFT_SNAPSHOT} == ${SWIFT_PREINSTALL} ]]; then
echo "Required Swift version is already installed, skipping download..."
elif [[ ${SWIFT_SNAPSHOT} == "${SWIFT_PREINSTALL}-RELEASE" ]]; then
echo "Required Swift version is already installed, skipping download..."
else
# Starts script to install Swift.
source ${projectFolder}/Package-Builder/${osName}/install_swift_binaries.sh
fi
fi
fi
# Output swift version
echo ">> Swift version shown below: "
swift -version
echo