Skip to content

Commit

Permalink
BXC-16 - Support Ice 3.7 layout
Browse files Browse the repository at this point in the history
  • Loading branch information
externl committed Jul 6, 2017
1 parent 281e97a commit ee9aa0f
Showing 1 changed file with 92 additions and 51 deletions.
143 changes: 92 additions & 51 deletions icebuilder
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
#!/bin/bash
#!/usr/bin/env bash
# **********************************************************************
#
# Copyright (c) 2008-2017 ZeroC, Inc. All rights reserved.
#
# **********************************************************************
set -eo pipefail

readonly ICE_BUILDER_XCODE_VERSION=3.0.2
readonly ICE_BUILDER_XCODE_VERSION=3.1.0

calledFromXcode() {
logDebug()
{
[ -z "$DEBUG" ] || echo "$*"
}

logError()
{
echo "$*" >&2
}

calledFromXcode()
{
if [[ -z $XCODE_PRODUCT_BUILD_VERSION || -z $DERIVED_FILE_DIR || -z $INPUT_FILE_PATH ]]; then
return 1
fi
return 0
}

# Run slice sliceCompiler. We always include Ice slice file directory as well as the INPUT_FILE_DIR.
compileSliceFile() {
compileSliceFile()
{
logDebug "Compiling slice file: $INPUT_FILE_NAME"
set -x # print the executed slice compiler command
$sliceCompiler -I"$INPUT_FILE_DIR" \
Expand All @@ -30,9 +42,10 @@ compileSliceFile() {
# These are expected to the be the destination of the slice compiler generated header
# and source files. Both files must share the same base directory, as this is how we
# determine the output directory to pass to the slice compiler.
setOutputDir() {
setOutputDir()
{
if [ "$SCRIPT_OUTPUT_FILE_COUNT" -ne 2 ]; then
echo "Please specify a header and source output file."
logError "Please specify a header and source output file."
return 1
fi

Expand All @@ -45,14 +58,15 @@ setOutputDir() {
local -r outputFileDir1=$(dirname "$outputFile1")

if [ "$outputFileDir0" != "$outputFileDir1" ]; then
echo "Output files must be in the same directory."
logError "Output files must be in the same directory."
return 1
fi

outputDir="$outputFileDir0"
}

main() {
main()
{
if ! calledFromXcode; then
logError "Ice Builder for Xcode must be executed from an Xcode environment."
exit 0
Expand All @@ -62,77 +76,100 @@ main() {
exit 1
fi

if ! findIceSDK; then
logError "Unable to find an Ice or Ice Touch SDK. An Ice or Ice Touch SDK must be added to the list of 'Additional SDKs'."
exit 1
fi
# Always check user specified Ice home. Fail if the specified
# directory does not exist or is not a valid Ice installation
if [ -n "$iceHome" ]; then
if ! setIceHomeDir "$iceHome"; then
logError "${iceHome} is not a valid Ice distribution."
exit 1
fi
else
# Try the following in order:
# 1. Search $ADDITIONAL_SDK_DIRS for a IceTouch-like SDK layout
# 2. Search for an Ice installation in `/usr/local`
if setIceSDKDir; then
logDebug "Ice SDK (absolute path): $iceSDKDir"
elif setIceHomeDir '/usr/local'; then
logDebug "Ice Home: $iceHomeDir"
else
logError "Unable to find valid Ice, Ice SDK, or Ice Touch distribution."
exit 1
fi

logDebug "Ice SDK (absolute path): $iceSDK"
fi

readonly iceVersion=$("$sliceCompiler" -v 2>&1)
logDebug "Ice version: $iceVersion"

# Compile Slice file
compileSliceFile
}

logDebug() {
[ -z "$DEBUG" ] || echo "$*"
}

logError() {
echo "$*" >&2
# Check if given directory is a valid Ice installation and set required variables
setIceHomeDir()
{
iceHomeDir="$1"

# source build
sliceDir="${iceHomeDir}/slice"
sliceCompiler="${iceHomeDir}/cpp/bin/slice2${language}"
[ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0

# "usr" style install
sliceDir="${iceHomeDir}/share/ice/slice"
sliceCompiler="${iceHomeDir}/bin/slice2${language}"
[ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0

# "opt" style install
sliceDir="${iceHomeDir}/slice"
sliceCompiler="${iceHomeDir}/bin/slice2${language}"
[ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0

# Unable to find Ice home; unset variables
iceHomeDir=
sliceDir=
sliceCompiler=
return 1
}

findIceSDK() {
for sdk in $ADDITIONAL_SDK_DIRS; do
# Find SDK from ADDITIONAL_SDK_DIRS and set required variables
setIceSDKDir()
{
for sdk in $ADDITIONAL_SDK_DIRS
do
local -r sdkDir=$(dirname "$sdk")

# IceTouch == IceTouch 1.3 and 3.6
# IceSDK == Ice 3.7 beta
if [[ "$sdk" =~ "IceTouch" ]] || [[ "$sdk" =~ "IceSDK" ]]; then
iceSDK="$sdk"
iceSDKDir="$sdk"
sliceDir="${sdkDir}/slice" # Slice file directory included the SDK
sliceCompiler="${sdkDir}/bin/slice2${language}" # Either 'slice2cpp' or 'slice2objc'
if ! validateSDK; then
logError "Unable to validate Ice SDK."
continue # Keep looking
fi
return 0
else
continue

# Check that the slice directory exists, and that the slice compiler exists and is executable
[ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0
fi
done
# Unable to find sdk

# Unable to find Ice SDK; unset variables
iceSDKDir=
sliceDir=
sliceCompiler=
return 1
}

printUsage() {
printUsage()
{
cat <<EOF
Usage: $(basename "$0") [options] [-- <slice compiler flags>]
Options:
--cpp Use slice2cpp. Default is slice2objc.
-h, --help Show this message.
-v, --version Display Ice Builder for Xcode version.
--cpp Use slice2cpp. Default is slice2objc.
--ice-home Location of Ice install.
-- ARGS Pass agruments directly to the slice compiler.
EOF
}

validateSDK() {
logDebug "Slice file directory: $sliceDir"
if [ ! -d "$sliceDir" ]; then
logError "Ice SDK slice files can not be found: $sliceDir"
return 1
fi

logDebug "Slice compiler: $sliceCompiler"
if [ ! -e "$sliceCompiler" ]; then
logError "Slice compiler '$sliceCompiler' does not exist"
return 1
fi
}

versionGt() {
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1";
}

#
# Process arguments and run slice compiler
#
Expand All @@ -151,6 +188,10 @@ while [[ $# -gt 0 ]]; do
printUsage
exit
;;
--ice-home)
shift
iceHome="$1"
;;
-v|--version)
echo "$ICE_BUILDER_XCODE_VERSION"
exit
Expand Down

0 comments on commit ee9aa0f

Please sign in to comment.