1#!/bin/bash 2# Copyright (c) 2014 Google Inc. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6set -e 7 8# `xcodebuild -version` output looks like 9# Xcode 4.6.3 10# Build version 4H1503 11# or like 12# Xcode 4.2 13# Build version 4C199 14# or like 15# Xcode 3.2.6 16# Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0 17# BuildVersion: 10M2518 18# Convert that to '0463', '0420' and '0326' respectively. 19function xcodeversion() { 20 xcodebuild -version | awk '/Xcode ([0-9]+\.[0-9]+(\.[0-9]+)?)/ { 21 version = $2 22 gsub(/\./, "", version) 23 if (length(version) < 3) { 24 version = version "0" 25 } 26 if (length(version) < 4) { 27 version = "0" version 28 } 29 } 30 END { print version }' 31} 32 33# Returns true if |string1| is smaller than |string2|. 34# This function assumes that both strings represent Xcode version numbers 35# as returned by |xcodeversion|. 36function smaller() { 37 local min="$(echo -ne "${1}\n${2}\n" | sort -n | head -n1)" 38 test "${min}" != "${2}" 39} 40 41if [[ "$(xcodeversion)" < "0500" ]]; then 42 # Xcode version is older than 5.0, check that SDKROOT is set but empty. 43 [[ -z "${SDKROOT}" && -z "${SDKROOT-_}" ]] 44else 45 # Xcode version is newer than 5.0, check that SDKROOT is set. 46 [[ "${SDKROOT}" == "$(xcodebuild -version -sdk '' Path)" ]] 47fi 48