-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathbuild-toolchain-tensorflow
executable file
·197 lines (182 loc) · 5.59 KB
/
build-toolchain-tensorflow
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
#
# SWIFT_ENABLE_TENSORFLOW
#
# utils/build-toolchain-tensorflow - documents process for building a toolchain
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
function usage() {
echo "$0 [OPTIONS]"
echo ""
echo "OPTIONS"
echo ""
echo "-h --help"
echo "Show help information."
echo ""
echo "-n --dry-run"
echo "Do a dry run."
echo ""
echo "-t --test"
echo "Run tests."
echo ""
echo "-r <version>, --release <version>"
echo "Build a release toolchain with the specified version name."
echo ""
echo "--tensorflow-swift-apis"
echo "Build and install the tensorflow-swift-apis library in the toolchain. (Default)."
echo ""
echo "--no-tensorflow-swift-apis"
echo "Do not build and install the tensorflow-swift-apis library in the toolchain."
echo ""
if [[ "$(uname -s)" == "Darwin" ]] ; then
echo "-p --pkg"
echo "Build a installer package."
echo ""
fi
}
cd "$(dirname $0)/.." || exit
SRC_DIR=$PWD
# Set defaults.
DRY_RUN=
BUNDLE_PREFIX=
INSTALLER_PACKAGE=
SWIFT_PACKAGE_BASE=
SWIFT_PACKAGE_TENSORFLOW_SWIFT_APIS=,tensorflow_swift_apis
SWIFT_PACKAGE_NOTEST=
SWIFT_PACKAGE_INSTALLER=
S4TF_RELEASE_VERSION=
if [[ -z ${SWIFT_PACKAGE} ]]; then
case $(uname -s) in
Darwin)
SWIFT_PACKAGE_BASE=tensorflow_osx
SWIFT_PACKAGE_NOTEST=,no_test
;;
Linux)
SWIFT_PACKAGE_BASE=tensorflow_linux
SWIFT_PACKAGE_NOTEST=,no_test
;;
*)
echo "Unrecognised platform $(uname -s)"
exit 1
;;
esac
fi
# Process command line arguments.
FIRST_ARG_PROCESSED=0
while [ $# -ne 0 ]; do
case "$1" in
-n|--dry-run)
DRY_RUN="-n"
;;
-t|--test)
SWIFT_PACKAGE_NOTEST=
;;
-h|--help)
usage
exit 0
;;
-r|--release)
shift
S4TF_RELEASE_VERSION=$1
if [ -z "$S4TF_RELEASE_VERSION" ]; then
echo "Missing release version name after --release. See --help."
exit 1
fi
;;
-p|--pkg)
INSTALLER_PACKAGE=1
if [ "$(uname -s)" == "Darwin" ]; then
SWIFT_PACKAGE_INSTALLER=,installer
else
echo "--pkg is not supported on \"$(uname -s)\". See --help."
exit 1
fi
;;
-g|--gpu)
# Warn, for backwards compatibility with existing callers.
# TODO: Remove when we have fixed up all callers.
echo "Warning: --gpu deprecated."
;;
-x|--x10)
# Warn, for backwards compatibility with existing callers.
# TODO: Remove when we have fixed up all callers.
echo "Warning: --x10 deprecated."
;;
--tensorflow-swift-apis)
SWIFT_PACKAGE_TENSORFLOW_SWIFT_APIS=,tensorflow_swift_apis
;;
--no-tensorflow-swift-apis)
SWIFT_PACKAGE_TENSORFLOW_SWIFT_APIS=
;;
*)
if [ ${FIRST_ARG_PROCESSED} -ne 0 ]; then
echo "Unrecognised argument \"$1\""
exit 1
fi
;;
esac
FIRST_ARG_PROCESSED=1
shift
done
SWIFT_PACKAGE="${SWIFT_PACKAGE_BASE}${SWIFT_PACKAGE_TENSORFLOW_SWIFT_APIS}${SWIFT_PACKAGE_NOTEST}${SWIFT_PACKAGE_INSTALLER}"
# Get host name.
HOST=
if [ "$(uname -s)" == "Darwin" ]; then
HOST=osx
elif [ "$(uname -s)" == "Linux" ]; then
linux_platform="$(lsb_release -i | cut -f2 | tr '[:upper:]' '[:lower:]')"
linux_version="$(lsb_release -r | cut -f2)"
HOST="${linux_platform}${linux_version}"
fi
# Report the commands being run.
set -x
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
DAY=$(date +"%d")
TOOLCHAIN_VERSION_DATE="5.0.${YEAR}${MONTH}${DAY}"
# Set toolchain name based on whether this is a normal or release toolchain.
if [[ -z ${S4TF_RELEASE_VERSION} ]]; then
TOOLCHAIN_NAME="swift-tensorflow-DEVELOPMENT-${YEAR}-${MONTH}-${DAY}-a"
DISPLAY_NAME_SHORT="Swift for TensorFlow Development Snapshot"
DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}"
else
TOOLCHAIN_NAME="swift-tensorflow-RELEASE-${S4TF_RELEASE_VERSION}"
DISPLAY_NAME_SHORT="Swift for TensorFlow ${S4TF_RELEASE_VERSION} Release"
DISPLAY_NAME="${DISPLAY_NAME_SHORT}"
fi
ARCHIVE="${TOOLCHAIN_NAME}-${HOST}.tar.gz"
SYM_ARCHIVE="${TOOLCHAIN_NAME}-osx-symbols.tar.gz"
BUNDLE_PREFIX=com.google.swift
BUNDLE_IDENTIFIER="${BUNDLE_PREFIX}.${YEAR}${MONTH}${DAY}"
SWIFT_INSTALLABLE_PACKAGE="${SRC_DIR}/${ARCHIVE}"
SWIFT_INSTALL_DIR="${SRC_DIR}/swift-nightly-install"
SWIFT_INSTALL_SYMROOT="${SRC_DIR}/swift-nightly-symroot"
SWIFT_TOOLCHAIN_DIR="/Library/Developer/Toolchains/${TOOLCHAIN_NAME}.xctoolchain"
SYMBOLS_PACKAGE="${SRC_DIR}/${SYM_ARCHIVE}"
DRY_RUN="${DRY_RUN}"
# Instructs swift-driver, et al to use local clones.
export SWIFTCI_USE_LOCAL_DEPS=1
if [ ${INSTALLER_PACKAGE} ]; then
INSTALLER_PACKAGE="darwin_toolchain_installer_package=${TOOLCHAIN_NAME}-osx.pkg"
fi
./utils/build-script ${DRY_RUN} --preset="${SWIFT_PACKAGE}" \
--cmake-c-launcher=`which sccache` \
--cmake-cxx-launcher=`which sccache` \
install_destdir="${SWIFT_INSTALL_DIR}" \
installable_package="${SWIFT_INSTALLABLE_PACKAGE}" \
install_toolchain_dir="${SWIFT_TOOLCHAIN_DIR}" \
install_symroot="${SWIFT_INSTALL_SYMROOT}" \
symbols_package="${SYMBOLS_PACKAGE}" \
darwin_toolchain_bundle_identifier="${BUNDLE_IDENTIFIER}" \
darwin_toolchain_display_name="${DISPLAY_NAME}" \
darwin_toolchain_display_name_short="${DISPLAY_NAME_SHORT}" \
darwin_toolchain_xctoolchain_name="${TOOLCHAIN_NAME}" \
darwin_toolchain_version="${TOOLCHAIN_VERSION_DATE}" \
darwin_toolchain_alias="Swift for TensorFlow" \
${INSTALLER_PACKAGE}