Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add DATE to Xcode xcconfig file

I have an Xcode config file, Config.xcconfig that contains this row only:

BUILD_DATE=`date "+%B %Y"`

I added this configuration to project in correct way, i hope.

enter image description here

I want to use the content of BUILD_DATE variable in the Application-info.plist file. How?

I tried get value using ${BUILD_DATE} but result is the string ``date "+%B %Y"` not the value!

enter image description here

From terminal, result is correct:

alp$ BUILD_DATE=`date "+%B %Y"`
alp$ echo $BUILD_DATE
March 2013
alp$ 

but in Xcode no!

enter image description here

How can i fix this?

like image 625
elp Avatar asked Oct 22 '22 15:10

elp


1 Answers

You cannot get the build date using the backtick command as the .xcconfig file is not interpreted as a shell script.

Your best bet is to use a similar approach the Bump Build Number script in this SO question (that I asked a while back), which provides a solution for using an external build script to update the .plist file.

For example:

#!/bin/sh

if [ $# -ne 1 ]; then
    echo usage: $0 plist-file
    exit 1
fi

plist="$1"
build_date=$(date "+%B %Y")

/usr/libexec/Plistbuddy -c "Set BUILD_DATE \"$build_date\"" "$plist"

and invoke it from the Xcode Build Script using something like:

"${PROJECT_DIR}/tools/set_build_date.sh" "${PROJECT_DIR}/${INFOPLIST_FILE}"
like image 143
trojanfoe Avatar answered Oct 29 '22 18:10

trojanfoe