Loading...
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | #!/bin/sh # # This shell-script is argument-compatible with xcrun(1) as invoked # by xnu's Makefiles. Additionally, it supports caching tools # in the local build directory. It is tightly coupled to exactly # the queries that MakeInc.cmd makes, in exactly the order it makes # them. ./tools/remote_build.sh invokes this indirectly in caching # mode, so '$(XCRUN) -sdk foo -find bar' copies 'bar' from wherever # it is on-disk into ./BUILD/BuildData, and returns that path to the # caller. In '-u' mode on a remote build server, cache tools # relative to the current build directory are returned without # actually calling through to xcrun(1), since the remote build # server may not even have Xcode installed. # SDKROOT="" FINDTOOL="" SDKQUERY="" VERBOSE="" OBJROOT="" CACHE=0 # echo "Calling $0 $@" 1>&2 while [ $# -gt 0 ]; do case "$1" in -c) CACHE=1 shift OBJROOT="$1" shift ;; -u) CACHE=0 shift OBJROOT="$1" shift ;; -sdk) shift SDKROOT="$1" shift ;; -verbose) VERBOSE="$1" shift set -x ;; -find) shift FINDTOOL="$1" shift ;; -show-sdk-path) SDKQUERY="$1" shift ;; -show-sdk-platform-path) SDKQUERY="$1" shift ;; -show-sdk-version) SDKQUERY="$1" shift ;; *) echo "Unrecognized argument $1" 1>&2 exit 1 esac done function CreateFile() { local string="$1" local filepath="$2" echo "${string}" > "${filepath}.new" cmp -s "${filepath}" "${filepath}.new" if [ $? -eq 0 ]; then rm "${filepath}.new" else mv "${filepath}.new" "${filepath}" fi } if [ $CACHE -eq 1 ]; then if [ -n "$SDKQUERY" ]; then # MakeInc.cmd makes SDK queries up-front first. Generally the # SDKROOT that is an input to these are one of: # "macosx" => Host SDK # "iphonehostXXX" => iPhone Host SDK # other shortcut or full path => Target SDK # # Once an initial lookup is made, subsequent SDKROOTs for # that same SDK may use a full path or cached path SDKTYPE="" case "$SDKROOT" in macosx) SDKTYPE="host" ;; iphonehost*) SDKTYPE="iphonehost" ;; *) if [ -f "$SDKROOT/.sdktype" ]; then SDKTYPE=`cat "$SDKROOT/.sdktype"` else SDKTYPE="target" fi ;; esac # A cached SDK path can be passed to xcrun, so # we need the original on-disk path if [ -f "$SDKROOT/.realsdkpath" ]; then REALSDKROOT=`cat "$SDKROOT/.realsdkpath"` else REALSDKROOT="$SDKROOT" fi SDKPROPERTY=`/usr/bin/xcrun $VERBOSE -sdk "$REALSDKROOT" "$SDKQUERY"` if [ $? -ne 0 ]; then exit $? fi case $SDKQUERY in -show-sdk-path) # Cache the SDK locally, and transform the resulting SDKPROPERTY if [ -z "$SDKPROPERTY" ]; then SDKPROPERTY="/" SDKNAME="Slash.sdk" else SDKNAME=$(basename "${SDKPROPERTY}") fi mkdir -p "${OBJROOT}/BuildTools/${SDKNAME}" mkdir -p "${OBJROOT}/BuildTools/${SDKNAME}/usr/include" rsync -aq --exclude=c++ --exclude=php --exclude=soc "${SDKPROPERTY}/usr/include/" "${OBJROOT}/BuildTools/${SDKNAME}/usr/include/" if [ "$SDKTYPE" = "iphonehost" ]; then mkdir -p "${OBJROOT}/BuildTools/${SDKNAME}/usr/local/lib/system" rsync -aq "${SDKPROPERTY}/usr/local/lib/system/" "${OBJROOT}/BuildTools/${SDKNAME}/usr/local/lib/system/" else mkdir -p "${OBJROOT}/BuildTools/${SDKNAME}/usr/lib" rsync -aq "${SDKPROPERTY}/usr/lib/libSystem"* "${OBJROOT}/BuildTools/${SDKNAME}/usr/lib/" rsync -aq "${SDKPROPERTY}/usr/lib/libc++"* "${OBJROOT}/BuildTools/${SDKNAME}/usr/lib/" rsync -aq "${SDKPROPERTY}/usr/lib/libstdc++"* "${OBJROOT}/BuildTools/${SDKNAME}/usr/lib/" mkdir -p "${OBJROOT}/BuildTools/${SDKNAME}/usr/lib/system" rsync -aq --exclude=\*_debug.dylib --exclude=\*_profile.dylib "${SDKPROPERTY}/usr/lib/system/" "${OBJROOT}/BuildTools/${SDKNAME}/usr/lib/system/" fi if [ -f "${SDKPROPERTY}/usr/local/libexec/availability.pl" ]; then mkdir -p "${OBJROOT}/BuildTools/${SDKNAME}/usr/local/libexec" rsync -aq "${SDKPROPERTY}/usr/local/libexec/availability.pl" "${OBJROOT}/BuildTools/${SDKNAME}/usr/local/libexec/" fi CreateFile "${SDKPROPERTY}" "${OBJROOT}/BuildTools/${SDKNAME}/.realsdkpath" CreateFile "${SDKTYPE}" "${OBJROOT}/BuildTools/${SDKNAME}/.sdktype" CreateFile "BuildTools/${SDKNAME}" "${OBJROOT}/BuildTools/.${SDKTYPE}sdk" echo "${OBJROOT}/BuildTools/${SDKNAME}" exit 0 ;; -show-sdk-platform-path) PLATFORMNAME=$(basename "${SDKPROPERTY}") mkdir -p "${OBJROOT}/BuildTools/${PLATFORMNAME}" if [ -f "${SDKPROPERTY}/usr/local/standalone/firmware/device_map.db" ]; then mkdir -p "${OBJROOT}/BuildTools/${PLATFORMNAME}/usr/local/standalone/firmware" rsync -aq "${SDKPROPERTY}/usr/local/standalone/firmware/device_map.db" \ "${OBJROOT}/BuildTools/${PLATFORMNAME}/usr/local/standalone/firmware/" fi CreateFile "BuildTools/${PLATFORMNAME}" "${OBJROOT}/BuildTools/.targetplatform" echo "${OBJROOT}/BuildTools/${PLATFORMNAME}" exit 0 ;; -show-sdk-version) CreateFile "${SDKPROPERTY}" "${OBJROOT}/BuildTools/.targetsdkversion" echo "${SDKPROPERTY}" exit 0 ;; esac elif [ -n "$FINDTOOL" ]; then # We assume SDK Queries have been performed first and subsequent # SDKROOTs used to find tools are all using cached SDKs in # the build directory, in which case metadata is present if [ ! -f "$SDKROOT/.realsdkpath" ]; then exit 1 fi REALSDKROOT=`cat "$SDKROOT/.realsdkpath"` if [ ! -f "$SDKROOT/.sdktype" ]; then exit 1 fi SDKTYPE=`cat "$SDKROOT/.sdktype"` TOOLPATH=`/usr/bin/xcrun $VERBOSE -sdk "$REALSDKROOT" -find "$FINDTOOL"` if [ $? -ne 0 ]; then exit $? fi # Keep the parent directory when caching tools, along with Host vs. Target TOOLNAME=$(basename "${TOOLPATH}") TOOLDIR=$(basename $(dirname "${TOOLPATH}")) if [ "$SDKTYPE" = "host" ]; then NEWTOOLPATH="${OBJROOT}/BuildTools/Host/${TOOLDIR}/${TOOLNAME}" mkdir -p "${OBJROOT}/BuildTools/Host" CreateFile "BuildTools/Host/${TOOLDIR}/${TOOLNAME}" "${OBJROOT}/BuildTools/Host/.${TOOLNAME}" else NEWTOOLPATH="${OBJROOT}/BuildTools/Target/${TOOLDIR}/${TOOLNAME}" mkdir -p "${OBJROOT}/BuildTools/Target" CreateFile "BuildTools/Target/${TOOLDIR}/${TOOLNAME}" "${OBJROOT}/BuildTools/Target/.${TOOLNAME}" fi mkdir -p $(dirname "${NEWTOOLPATH}") rsync -aq "${TOOLPATH}" "${NEWTOOLPATH}" case "${TOOLNAME}" in clang) mkdir -p $(dirname $(dirname "${NEWTOOLPATH}"))/lib/clang rsync -aq $(dirname "${TOOLPATH}")/ld $(dirname "${NEWTOOLPATH}")/ld rsync -aq $(dirname $(dirname "${TOOLPATH}"))/lib/clang/ $(dirname $(dirname "${NEWTOOLPATH}"))/lib/clang/ rsync -aq $(dirname $(dirname "${TOOLPATH}"))/lib/libLTO.dylib $(dirname $(dirname "${NEWTOOLPATH}"))/lib/libLTO.dylib ;; bison) mkdir -p $(dirname $(dirname "${NEWTOOLPATH}"))/share/bison rsync -aq $(dirname $(dirname "${TOOLPATH}"))/share/bison/ $(dirname $(dirname "${NEWTOOLPATH}"))/share/bison/ ;; esac echo "${NEWTOOLPATH}" exit 0 else echo "Unrecognized option" 1>&2 exit 1 fi fi # When using cached SDK information, first try to do # an initial classification, and then read properties from # cached locations SDKTYPE="" case "$SDKROOT" in macosx) SDKTYPE="host" ;; iphonehost*) SDKTYPE="iphonehost" ;; *) if [ -f "$SDKROOT/.sdktype" ]; then SDKTYPE=`cat "$SDKROOT/.sdktype"` else SDKTYPE="target" fi ;; esac if [ -n "$FINDTOOL" ]; then TOOLNAME=$(basename "${FINDTOOL}") if [ "${SDKTYPE}" = "host" ]; then RELPATH=`cat ${OBJROOT}/BuildTools/Host/.${TOOLNAME}` else RELPATH=`cat ${OBJROOT}/BuildTools/Target/.${TOOLNAME}` fi echo "${OBJROOT}/${RELPATH}" else case $SDKQUERY in -show-sdk-path) RELPATH=`cat ${OBJROOT}/BuildTools/.${SDKTYPE}sdk` echo "${OBJROOT}/${RELPATH}" ;; -show-sdk-platform-path) RELPATH=`cat ${OBJROOT}/BuildTools/.targetplatform` echo "${OBJROOT}/${RELPATH}" ;; -show-sdk-version) echo `cat ${OBJROOT}/BuildTools/.targetsdkversion` ;; esac fi |