]>
git.saurik.com Git - apple/xnu.git/blob - tools/remote_build.sh
43e3ec44ea327f9eb0ac952bbc0ea12d3d46889b
3 # Script that rsyncs a source/build tree to a remote server, performs a build,
4 # and copies the result back
7 # This script is invoked instead of the initial recursive make(1) in ./Makefile.
8 # First it must cache all binaries that might be used during the build by
9 # calling "make print_exports" (any target would work) with an overriden xcrun(1)
10 # which caches tools an SDKs into ./BUILD/obj/BuildTools. When the combined
11 # source+build tree is rsync-ed to the remote server, we run a script to
12 # re-initiate the build using an overriden xcrun(1) which hands back
13 # cached tools in ./BUILD/obj/BuildTools instead of whatever Xcode tools are on
14 # the remote system (or if no Xcode tools are installed remotely). Finally,
15 # the build results are copied back locally.
30 _REMOTEBUILD_TARGET
=*)
31 TARGET
=`echo $arg | awk -F= '{print $2}'`
35 MAKE
=`echo $arg | awk -F= '{print $2}'`
39 # Don't restart another remote build remotely
57 # Remote build isn't chrooted or special in any way
66 REMOTEARGS
[$index]="\"$arg\""
71 ARGS
[$index]="REMOTEBUILD="
72 REMOTEARGS
[$index]="\"REMOTEBUILD=\""
74 # For some targets like installsrc, we can't to a remote build
97 if [ $SKIPREMOTE -eq 1 ]; then
98 exec "$MAKE" "$TARGET" "${ARGS[@]}"
102 SRCNAME
="$(basename $SRC)"
104 # Pick up build locations passed in the environment
109 if [ -z "${OBJROOT}" ]; then
110 die
"OBJROOT not set in environment"
112 mkdir -p "${OBJROOT}" || die
"Could not create ${OBJROOT}"
114 if [ -z "${SYMROOT}" ]; then
115 die
"SYMROOT not set in environment"
117 mkdir -p "${SYMROOT}" || die
"Could not create ${SYMROOT}"
119 if [ -z "${DSTROOT}" ]; then
120 die
"DSTROOT not set in environment"
122 mkdir -p "${DSTROOT}" || die
"Could not create ${DSTROOT}"
124 if [ "$REMOTEBUILD" = "$SPECIALREMOTEBUILD" ]; then
129 BUILDTOOLSDIR
="$OBJROOT"
130 REMOTE_BUILDTOOLSREL
="./BUILD/obj"
131 BUILDSCRIPTDIR
="$OBJROOT"
132 REMOTE_BUILDSCRIPTREL
="./BUILD/obj"
133 BUILDSCRIPTNAME
="build.sh"
134 if [ ! -d "${OBJROOT}/SETUP" ]; then
135 RSYNC_ARGS
="--delete-excluded"
139 if [ ! -e "${SYMROOT}/" ]; then
140 RSYNC_DELETE_SYMROOT
=1
142 RSYNC_DELETE_SYMROOT
=0
144 if [ ! -e "${DSTROOT}/" ]; then
145 RSYNC_DELETE_DSTROOT
=1
147 RSYNC_DELETE_DSTROOT
=0
152 echo "Caching build tools..." 1>&2
153 mkdir -p "${BUILDTOOLSDIR}" || die
"Could not create BUILDTOOLSDIR"
154 $MAKE print_exports
"${ARGS[@]}" XCRUN
="${SRC}/tools/xcrun_cache.sh -c \"${BUILDTOOLSDIR}\"" >/dev
/null
|| die
"Could not cache build tools"
156 # Cache the make(1) binary itself
157 MAKE_SDKROOT
=`"${SRC}/tools/xcrun_cache.sh" -u "${BUILDTOOLSDIR}" -sdk / -show-sdk-path`
158 "${SRC}/tools/xcrun_cache.sh" -c "${BUILDTOOLSDIR}" -sdk "${MAKE_SDKROOT}" -find make >/dev
/null
|| die
"Could not cache make"
160 # Create a canned build script that can restart the build on the remote server.
161 mkdir -p "${BUILDSCRIPTDIR}" || die
"Could not create BUILDSCRIPTDIR"
162 cat > "${BUILDSCRIPTDIR}/${BUILDSCRIPTNAME}" <<EOF
164 mkdir -p /private/tmp
165 mkdir -p /private/var/tmp
166 mkdir -p "\${TMPDIR}"
167 cd "${REMOTE_SRCREL}"
171 MAKE=\`\$PWD/tools/xcrun_cache.sh -u "\$PWD/${REMOTE_BUILDTOOLSREL}" -sdk / -find make\`
172 if [ -z "\${MAKE}" ]; then exit 1; fi
173 \${MAKE} ${TARGET} ${REMOTEARGS[@]} XCRUN="\$PWD/tools/xcrun_cache.sh -u \"\$PWD/${REMOTE_BUILDTOOLSREL}\""
175 if [ \$ret -eq 0 ]; then
176 if [ ${TARBUILDDIRS} -eq 1 ]; then
177 tar jcf ./BUILD/obj.tar.bz2 --exclude=\*.o --exclude=\*.cpo --exclude=\*.d --exclude=\*.cpd --exclude=\*.non_lto --exclude=\*.ctf --exclude=conf -C ./BUILD/obj . || exit 1
178 tar jcf ./BUILD/sym.tar.bz2 -C ./BUILD/sym . || exit 1
179 tar jcf ./BUILD/dst.tar.bz2 -C ./BUILD/dst . || exit 1
184 chmod a
+x
"${BUILDSCRIPTDIR}/${BUILDSCRIPTNAME}"
185 #echo "Build script is:"
186 #cat "${BUILDSCRIPTDIR}/${BUILDSCRIPTNAME}"
188 mkdir -p "${BUILDTOOLSDIR}/empty"
190 if [ "$REMOTEBUILD" = "$SPECIALREMOTEBUILD" ]; then
194 REMOTEBUILD
="$REMOTEBUILD"
195 REMOTEBUILDPATH
="$REMOTEBUILDPATH"
197 if [ -z "$REMOTEBUILDPATH" ]; then
199 case "${REMOTEBUILD}" in
201 WHOAMI
=`echo "${REMOTEBUILD}" | awk -F@ '{print $1}'`
204 REMOTEBUILDPATH
="/tmp/$WHOAMI"
207 # Construct a unique remote path
208 eval `stat -s "${SRC}"`
210 REMOTEBUILDPATH
="${REMOTEBUILDPATH}/$st_ino/${SRCNAME}/"
211 echo "Remote path is ${REMOTEBUILD}:${REMOTEBUILDPATH}" 1>&2
213 ssh $REMOTEBUILD "mkdir -p \"${REMOTEBUILDPATH}/BUILD/\"{obj,sym,dst}" || die
"Could not make remote build directory"
216 rsync
-azv --delete --exclude=\
*~
--exclude=.svn
--exclude=.git
--exclude=/BUILD .
$REMOTEBUILD:"${REMOTEBUILDPATH}" || die
"Could not rsync source tree"
218 # Copy partial OBJROOT (just build tools and build script), and optionally delete everything else
219 rsync
-azv --delete $RSYNC_ARGS --include=/build.sh
--include=/BuildTools
--include=/BuildTools
/\
*\
* --exclude=\
* "${OBJROOT}/" $REMOTEBUILD:"${REMOTEBUILDPATH}/BUILD/obj/" || die
"Could not rsync build tree"
221 # Delete remote SYMROOT if it has been deleted locally
222 if [ "$RSYNC_DELETE_SYMROOT" -eq 1 ]; then
223 rsync
-azv --delete "${BUILDTOOLSDIR}/empty/" $REMOTEBUILD:"${REMOTEBUILDPATH}/BUILD/sym/" || die
"Could not rsync delete SYMROOT"
226 # Delete remote DSTROOT if it has been deleted locally
227 if [ "$RSYNC_DELETE_DSTROOT" -eq 1 ]; then
228 rsync
-azv --delete "${BUILDTOOLSDIR}/empty/" $REMOTEBUILD:"${REMOTEBUILDPATH}/BUILD/dst/" || die
"Could not rsync delete DSTROOT"
232 echo ssh $REMOTEBUILD "/bin/bash -c 'cd \"${REMOTEBUILDPATH}\" && ${REMOTE_BUILDSCRIPTREL}/${BUILDSCRIPTNAME}'" 1>&2
233 ssh $REMOTEBUILD "/bin/bash -c 'cd \"${REMOTEBUILDPATH}\" && ${REMOTE_BUILDSCRIPTREL}/${BUILDSCRIPTNAME}'" || die
"Could not complete remote build"
235 # Copy back build results except for object files (which might be several GB)
236 echo "Copying results back..."
237 rsync
-azv --no-o --no-g --exclude=\
*.o
--exclude=\
*.cpo
--exclude=\
*.d
--exclude=\
*.cpd
--exclude=\
*.non_lto
--exclude=\
*.ctf
--exclude=conf
$REMOTEBUILD:"${REMOTEBUILDPATH}/BUILD/obj/" "${OBJROOT}/" || die
"Could not rsync build results"
238 rsync
-azv --no-o --no-g $REMOTEBUILD:"${REMOTEBUILDPATH}/BUILD/sym/" "${SYMROOT}/" || die
"Could not rsync build results"
239 rsync
-azv --no-o --no-g $REMOTEBUILD:"${REMOTEBUILDPATH}/BUILD/dst/" "${DSTROOT}/" || die
"Could not rsync build results"