aboutsummaryrefslogtreecommitdiff
path: root/BuildScripts/PListCompiler.sh
blob: 844c0874bd484b6b303210c4f9c1751f478d8e21 (plain)
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
#!/bin/bash
# PlistCompiler.sh

# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License.  You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations under
# the License.

# Takes a file (usually with a suffix of .plistsrc) and "compiles it" using
# the gcc preprocessor.
# The best way to use PlistCompiler is to add a custom build rule to your target
# in Xcode with the following settings:
# Process: "Source files with names matching:" "*.plistsrc"
# using: "Custom script:"
# "Path/to/PlistCompiler/relative/to/${SRCROOT}'
# with output files:
# ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${INPUT_FILE_BASE}.plist
# You can control the include paths by setting the 
# GTM_PLIST_COMPILER_INCLUDE_PATHS environment variable to a colon delimited
# path string. It defaults to "."


set -o errexit
set -o nounset

PWD=$(pwd)
GTM_PLIST_COMPILER_INCLUDE_PATHS=${GTM_PLIST_COMPILER_INCLUDE_PATHS:=${PWD}}

if [[ $# -ne 2 && $# -ne 0 ]] ; then
  echo "usage: ${0} INPUT OUTPUT" >&2
  exit 1
fi

if [[ $# -eq 2 ]] ; then
  SCRIPT_INPUT_FILE="${1}"
  SCRIPT_OUTPUT_FILE="${2}"
else
  SCRIPT_INPUT_FILE="${INPUT_FILE_PATH}"
  SCRIPT_OUTPUT_FILE="${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${INPUT_FILE_BASE}.plist"
fi

# Split up the passed in include paths
SaveIFS=$IFS
IFS=":"

declare -a SPLIT_INCLUDE_PATHS
for a in ${GTM_PLIST_COMPILER_INCLUDE_PATHS};
do
  SPLIT_INCLUDE_PATHS[${#SPLIT_INCLUDE_PATHS[@]}]=-I
  SPLIT_INCLUDE_PATHS[${#SPLIT_INCLUDE_PATHS[@]}]="${a}"
done
IFS=$SaveIFS

NAME=$(basename $0)
TEMP=$(mktemp -t "${NAME}")

# run gcc and strip out lines starting with # that the preprocessor leaves behind.
gcc ${SPLIT_INCLUDE_PATHS[@]} -E -x c "${SCRIPT_INPUT_FILE}" -o "${TEMP}"
sed 's/^#.*//g' "${TEMP}" > "${SCRIPT_OUTPUT_FILE}"
rm -f "${TEMP}"