]> git.saurik.com Git - apple/system_cmds.git/blame - xscripts/darwinversion.sh
system_cmds-880.100.5.tar.gz
[apple/system_cmds.git] / xscripts / darwinversion.sh
CommitLineData
cf37c299
A
1#!/bin/sh
2
3# This script is intended to generate version information for single-file
4# products (i.e. things that don't ship in bundles). It takes an input file
5# with the suffix ".version" that defines:
6#
7# DARWIN_BUNDLE_IDENTIFIER
8# The CFBundleIdentifier for the product.
9# DARWIN_DISPLAY_NAME
10# The "marketing" name of the product ("Darwin System Bootstrapper" as opposed
11# to "launchd" or "Darwin Kernel" as opposed to "xnu").
12# DARWIN_DISPLAY_VERSION
13# The major release version (think "7.0" for iOS 7, "10.9" for Mavericks,
14# etc.).
15# DARWIN_INCREMENTAL_VERSION
16# The incremental version (think 12A132, svn revision, project tag, etc.).
17# DARWIN_COPYRIGHT
18# The copyright string.
19#
20# It produces a header (darwin_version.h) that declares:
21#
22# __darwin_builder_version
23# The integer representation of the version of OS X which built the project
24# (think 1090, 1091, etc.).
25# __darwin_builder_build
26# The integer representation of the build of OS X which built the project,
27# represented in hex (think 0x12A132).
28# __darwin_build_inc_version
29# A string representation of the given DARWIN_INCREMENTAL_VERSION.
30# __darwin_version_string
31# A composed version string which can serve as useful for identifying the
32# version, variant and origin of a given build. It is formatted as:
33#
34# $DARWIN_DISPLAY_NAME Version $DARWIN_DISPLAY_VERSION `date`; `whoami`:<objects>
35#
36# <objects> is a symbolic link in the OBJROOT pointing to the subdirectory
37# containing the objects for the target being built. The link's name is
38# formatted as:
39#
40# ${BASE_PRODUCT_NAME}/${DARWIN_VARIANT}_${UPPER_CASE_CURRENT_ARCH}
41#
42# The BASE_PRODUCT_NAME is the first part of the target's PRODUCT_NAME, prior
43# to a '.' character (so the base product name of "launchd.development" is
44# simply "launchd").
45#
46# This link points to the appropriate location in the build root. If the SDK
47# being built for is the Simulator, the variant is formatted as:
48#
49# ${DARWIN_VARIANT}_SIMULATOR_${UPPER_CASE_CURRENT_ARCH}
50#
51# It produces an XML Info.plist from this information and embeds it in the
52# __TEXT,__info_plist section of the resulting binary.
53
54. ${INPUT_FILE_PATH}
55
56baseproductname=${PRODUCT_NAME/.*/}
57builder_version=`sw_vers -productVersion`
58builder_build=`sw_vers -buildVersion`
59brewedondate=`date`
60brewedby=`whoami`
61
62if [ $SUDO_USER ]; then
63 brewedby="$SUDO_USER"
64fi
65
66release="Unknown"
67if [[ "$DARWIN_VARIANT" != "RELEASE" && -n "$RC_RELEASE" ]]; then
68 release="$RC_RELEASE"
69fi
70
71# Distill the version down to its base OS. The builders could be running 10.7.2,
72# for example, but the availability macros on OS X only handle major version
73# availability.
74builder_version_int=${builder_version/.}
75builder_version_int=${builder_version_int/.*}
76builder_version_int="${builder_version_int}0"
77
78# Builders don't typically run on later SU trains. They'll usually move to the
79# next major release.
80if [[ "$builder_build" =~ [g-zG-Z] ]]; then
81 builder_build="1A1"
82fi
83
84destdir="${DERIVED_SOURCES_DIR}/${CURRENT_ARCH}"
85mkdir -p "$destdir"
86
87thehfile="$destdir/darwin_version.h"
88thecfile="$destdir/darwin_version.c"
89
90# Hack to emulate how xnu's version works. It has the nice feature of printing
91# the OBJROOT of the current xnu, which is different based on build variant and
92# architecture. But in our case, the OBJROOT is buried a few levels deep, so we
93# create a symlink in the OBJROOT to point to that, or else we'd have to embed
94# a much longer path in the version.
95mkdir -p "${OBJROOT}/$baseproductname"
96cd "${OBJROOT}/$baseproductname"
97
98rootwithslash="${OBJROOT}/"
99objpath=`eval echo -n \\$OBJECT_FILE_DIR_\$CURRENT_VARIANT`
100
101capsarch=`echo $CURRENT_ARCH | tr "[:lower:]" "[:upper:]"`
102# Xcode does not provide an OBJECT_FILE_DIR_$CURRENT_VARIANT_$CURRENT_ARCH, so
103# we have to interpolate the last part of the path.
104objpath=$objpath/$CURRENT_ARCH
105subpath=${objpath#${rootwithslash}}
106
107if [[ "${PLATFORM_NAME}" =~ "simulator" ]]; then
108 linkname="${DARWIN_VARIANT}_SIMULATOR_${capsarch}"
109else
110 linkname="${DARWIN_VARIANT}_${capsarch}"
111fi
112
113objects=`basename ${OBJROOT}`
114if [[ "$objects" = "Objects" ]]; then
115 # Newer XBSs put the OBJROOT in an "Objects" subdirectory under the build
116 # root.
117 oldwd=`pwd`
118 cd "${OBJROOT}"
119 cd ..
120
121 objects=`dirname ${OBJROOT}`
122 objects=`basename $objects`
123 objects="${objects/_install/}"
124
125 ln -fs "Objects" "$objects"
126
127 cd "$oldwd"
128fi
129objects="$objects/$baseproductname/$linkname"
130
131ln -s ../${subpath} $linkname
132version_string="$DARWIN_DISPLAY_NAME Version $DARWIN_DISPLAY_VERSION: $brewedondate; $brewedby:$objects"
133
134# Generate the symbol root.
135binarywithsyms="$SYMROOT/$PRODUCT_NAME"
136if [[ $SYMROOT =~ ^/BinaryCache/ ]]; then
137 # XBS tosses symbols and roots into /BinaryCache on the builder, so sniff
138 # that out and generate the appropriate path. Otherwise, just use the given
139 # local SYMROOT.
140 symrootsubpath=${SYMROOT#"/BinaryCache/"}
141 binarywithsyms="~rc/Software/$release/BuildRecords/$symrootsubpath/$PRODUCT_NAME"
142fi
143
144echo "*** Stamping project build:"
145echo "*** Release: $release"
146echo "*** Builder Version: $builder_version"
147echo "*** Builder Build: $builder_build"
148echo "*** Project Version: $CURRENT_PROJECT_VERSION"
149echo "*** Version String: $version_string"
150echo "*** Object Root: $objects"
151echo "*** Debugging Binary: $binarywithsyms"
152
153# Generate Info.plist
154infoplist="$destdir"/Info.plist
155/usr/libexec/PlistBuddy -c "Add :CFBundleIdentifier string" -c "Save" $infoplist > /dev/null
156/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $DARWIN_BUNDLE_IDENTIFIER" -c "Save" $infoplist > /dev/null
157/usr/libexec/PlistBuddy -c "Add :CFBundleName string" -c "Save" $infoplist > /dev/null
158/usr/libexec/PlistBuddy -c "Set :CFBundleName $PRODUCT_NAME" -c "Save" $infoplist > /dev/null
159/usr/libexec/PlistBuddy -c "Add :CFBundleDisplayName string" -c "Save" $infoplist > /dev/null
160/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $DARWIN_DISPLAY_NAME" -c "Save" $infoplist > /dev/null
161/usr/libexec/PlistBuddy -c "Add :CFBundleExecutable string" -c "Save" $infoplist > /dev/null
162/usr/libexec/PlistBuddy -c "Set :CFBundleExecutable $EXECUTABLE_NAME" -c "Save" $infoplist > /dev/null
163/usr/libexec/PlistBuddy -c "Add :CFBundleInfoDictionaryVersion string" -c "Save" $infoplist > /dev/null
164/usr/libexec/PlistBuddy -c "Set :CFBundleInfoDictionaryVersion 6.0" -c "Save" $infoplist > /dev/null
165/usr/libexec/PlistBuddy -c "Add :CFBundleShortVersionString string" -c "Save" $infoplist > /dev/null
166/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $DARWIN_DISPLAY_VERSION" -c "Save" $infoplist > /dev/null
167/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string" -c "Save" $infoplist > /dev/null
168/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $DARWIN_INCREMENTAL_VERSION" -c "Save" $infoplist > /dev/null
169/usr/libexec/PlistBuddy -c "Add :NSHumanReadableCopyright string" -c "Save" $infoplist > /dev/null
170/usr/libexec/PlistBuddy -c "Set :NSHumanReadableCopyright $DARWIN_COPYRIGHT" -c "Save" $infoplist > /dev/null
171/usr/libexec/PlistBuddy -c "Add :DarwinVariant string" -c "Save" $infoplist > /dev/null
172/usr/libexec/PlistBuddy -c "Set :DarwinVariant $DARWIN_VARIANT" -c "Save" $infoplist > /dev/null
173# codesign can't deal with the Info.plist for each slice having different
174# content, so don't encode architecture-specific information for now.
175#
176# <rdar://problem/15459303>
177#/usr/libexec/PlistBuddy -c "Add :DarwinArchitecture string" -c "Save" $infoplist > /dev/null
178#/usr/libexec/PlistBuddy -c "Set :DarwinArchitecture $CURRENT_ARCH" -c "Save" $infoplist > /dev/null
179/usr/libexec/PlistBuddy -c "Add :DarwinBuilderVersion string" -c "Save" $infoplist > /dev/null
180/usr/libexec/PlistBuddy -c "Set :DarwinBuilderVersion $builder_version" -c "Save" $infoplist > /dev/null
181/usr/libexec/PlistBuddy -c "Add :DarwinBuilderBuild string" -c "Save" $infoplist > /dev/null
182/usr/libexec/PlistBuddy -c "Set :DarwinBuilderBuild $builder_build" -c "Save" $infoplist > /dev/null
183/usr/libexec/PlistBuddy -c "Add :DTSDKName string" -c "Save" $infoplist > /dev/null
184/usr/libexec/PlistBuddy -c "Set :DTSDKName $SDK_NAME" -c "Save" $infoplist > /dev/null
185/usr/libexec/PlistBuddy -c "Add :DTSDKBuild string" -c "Save" $infoplist > /dev/null
186/usr/libexec/PlistBuddy -c "Set :DTSDKBuild $PLATFORM_PRODUCT_BUILD_VERSION" -c "Save" $infoplist > /dev/null
187/usr/libexec/PlistBuddy -c "Add :DTXcodeBuild string" -c "Save" $infoplist > /dev/null
188/usr/libexec/PlistBuddy -c "Set :DTXcodeBuild $XCODE_PRODUCT_BUILD_VERSION" -c "Save" $infoplist > /dev/null
189/usr/libexec/PlistBuddy -c "Add :DTCompiler string" -c "Save" $infoplist > /dev/null
190/usr/libexec/PlistBuddy -c "Set :DTCompiler $DEFAULT_COMPILER" -c "Save" $infoplist > /dev/null
191/usr/libexec/PlistBuddy -c "Add :DTPlatformName string" -c "Save" $infoplist > /dev/null
192/usr/libexec/PlistBuddy -c "Set :DTPlatformName $PLATFORM_NAME" -c "Save" $infoplist > /dev/null
193/usr/libexec/PlistBuddy -c "Add :DTPlatformVersion string" -c "Save" $infoplist > /dev/null
194/usr/libexec/PlistBuddy -c "Set :DTPlatformVersion $IPHONEOS_DEPLOYMENT_TARGET" -c "Save" $infoplist > /dev/null
195/usr/libexec/PlistBuddy -c "Add :DTXcode string" -c "Save" $infoplist > /dev/null
196/usr/libexec/PlistBuddy -c "Set :DTXcode $XCODE_VERSION_ACTUAL" -c "Save" $infoplist > /dev/null
197infoplistcontents=`cat $infoplist`
198
199rm -f "$thehfile"
200echo "#ifndef __DARWIN_VERSION_H__" >> "$thehfile"
201echo "#define __DARWIN_VERSION_H__" >> "$thehfile"
202echo "const unsigned long __darwin_builder_version;" >> "$thehfile"
203echo "const unsigned long __darwin_builder_build;" >> "$thehfile"
204echo "const char *__darwin_build_inc_version;" >> "$thehfile"
205echo "const char *__darwin_version_string;" >> "$thehfile"
206echo "const char *__darwin_variant;" >> "$thehfile"
207echo "const char *__darwin_debug_binary;" >> "$thehfile"
208echo "#endif // __DARWIN_VERSION_H__" >> "$thehfile"
209echo "" >> "$thehfile"
210
211rm -f "$thecfile"
212echo "__attribute__((__used__)) const unsigned long __darwin_builder_version = $builder_version_int;" >> "$thecfile"
213echo "__attribute__((__used__)) const unsigned long __darwin_builder_build = 0x$builder_build;" >> "$thecfile"
214echo "__attribute__((__used__)) const char *__darwin_build_inc_version = \"$CURRENT_PROJECT_VERSION\";" >> "$thecfile"
215echo "__attribute__((__used__)) const char *__darwin_version_string = \"$version_string\";" >> "$thecfile"
216echo "__attribute__((__used__)) const char *__darwin_variant = \"$DARWIN_VARIANT\";" >> "$thecfile"
217echo "__attribute__((__used__)) const char *__darwin_version_string_heywhat = \"@(#)VERSION:$version_string\";" >> "$thecfile"
218echo "__attribute__((__used__)) const char *__darwin_debug_binary = \"$binarywithsyms\";" >> "$thecfile"
219
220# Embed the Info.plist in the __TEXT,__info_plist section.
221echo "__attribute__((__used__))" >> "$thecfile"
222
223echo "__attribute__((__section__(\"__TEXT,__info_plist\")))" >> "$thecfile"
224echo -n "static const char __darwin_info_plist[] = \"" >> "$thecfile"
225echo -n "$infoplistcontents" | sed -e 's/\"/\\"/g' | tr -d '\n' >> "$thecfile"
226echo "\";" >> "$thecfile"
227
228echo "" >> "$thecfile"