]>
Commit | Line | Data |
---|---|---|
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 | ||
56 | baseproductname=${PRODUCT_NAME/.*/} | |
57 | builder_version=`sw_vers -productVersion` | |
58 | builder_build=`sw_vers -buildVersion` | |
59 | brewedondate=`date` | |
60 | brewedby=`whoami` | |
61 | ||
62 | if [ $SUDO_USER ]; then | |
63 | brewedby="$SUDO_USER" | |
64 | fi | |
65 | ||
66 | release="Unknown" | |
67 | if [[ "$DARWIN_VARIANT" != "RELEASE" && -n "$RC_RELEASE" ]]; then | |
68 | release="$RC_RELEASE" | |
69 | fi | |
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. | |
74 | builder_version_int=${builder_version/.} | |
75 | builder_version_int=${builder_version_int/.*} | |
76 | builder_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. | |
80 | if [[ "$builder_build" =~ [g-zG-Z] ]]; then | |
81 | builder_build="1A1" | |
82 | fi | |
83 | ||
84 | destdir="${DERIVED_SOURCES_DIR}/${CURRENT_ARCH}" | |
85 | mkdir -p "$destdir" | |
86 | ||
87 | thehfile="$destdir/darwin_version.h" | |
88 | thecfile="$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. | |
95 | mkdir -p "${OBJROOT}/$baseproductname" | |
96 | cd "${OBJROOT}/$baseproductname" | |
97 | ||
98 | rootwithslash="${OBJROOT}/" | |
99 | objpath=`eval echo -n \\$OBJECT_FILE_DIR_\$CURRENT_VARIANT` | |
100 | ||
101 | capsarch=`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. | |
104 | objpath=$objpath/$CURRENT_ARCH | |
105 | subpath=${objpath#${rootwithslash}} | |
106 | ||
107 | if [[ "${PLATFORM_NAME}" =~ "simulator" ]]; then | |
108 | linkname="${DARWIN_VARIANT}_SIMULATOR_${capsarch}" | |
109 | else | |
110 | linkname="${DARWIN_VARIANT}_${capsarch}" | |
111 | fi | |
112 | ||
113 | objects=`basename ${OBJROOT}` | |
114 | if [[ "$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" | |
128 | fi | |
129 | objects="$objects/$baseproductname/$linkname" | |
130 | ||
131 | ln -s ../${subpath} $linkname | |
132 | version_string="$DARWIN_DISPLAY_NAME Version $DARWIN_DISPLAY_VERSION: $brewedondate; $brewedby:$objects" | |
133 | ||
134 | # Generate the symbol root. | |
135 | binarywithsyms="$SYMROOT/$PRODUCT_NAME" | |
136 | if [[ $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" | |
142 | fi | |
143 | ||
144 | echo "*** Stamping project build:" | |
145 | echo "*** Release: $release" | |
146 | echo "*** Builder Version: $builder_version" | |
147 | echo "*** Builder Build: $builder_build" | |
148 | echo "*** Project Version: $CURRENT_PROJECT_VERSION" | |
149 | echo "*** Version String: $version_string" | |
150 | echo "*** Object Root: $objects" | |
151 | echo "*** Debugging Binary: $binarywithsyms" | |
152 | ||
153 | # Generate Info.plist | |
154 | infoplist="$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 | |
197 | infoplistcontents=`cat $infoplist` | |
198 | ||
199 | rm -f "$thehfile" | |
200 | echo "#ifndef __DARWIN_VERSION_H__" >> "$thehfile" | |
201 | echo "#define __DARWIN_VERSION_H__" >> "$thehfile" | |
202 | echo "const unsigned long __darwin_builder_version;" >> "$thehfile" | |
203 | echo "const unsigned long __darwin_builder_build;" >> "$thehfile" | |
204 | echo "const char *__darwin_build_inc_version;" >> "$thehfile" | |
205 | echo "const char *__darwin_version_string;" >> "$thehfile" | |
206 | echo "const char *__darwin_variant;" >> "$thehfile" | |
207 | echo "const char *__darwin_debug_binary;" >> "$thehfile" | |
208 | echo "#endif // __DARWIN_VERSION_H__" >> "$thehfile" | |
209 | echo "" >> "$thehfile" | |
210 | ||
211 | rm -f "$thecfile" | |
212 | echo "__attribute__((__used__)) const unsigned long __darwin_builder_version = $builder_version_int;" >> "$thecfile" | |
213 | echo "__attribute__((__used__)) const unsigned long __darwin_builder_build = 0x$builder_build;" >> "$thecfile" | |
214 | echo "__attribute__((__used__)) const char *__darwin_build_inc_version = \"$CURRENT_PROJECT_VERSION\";" >> "$thecfile" | |
215 | echo "__attribute__((__used__)) const char *__darwin_version_string = \"$version_string\";" >> "$thecfile" | |
216 | echo "__attribute__((__used__)) const char *__darwin_variant = \"$DARWIN_VARIANT\";" >> "$thecfile" | |
217 | echo "__attribute__((__used__)) const char *__darwin_version_string_heywhat = \"@(#)VERSION:$version_string\";" >> "$thecfile" | |
218 | echo "__attribute__((__used__)) const char *__darwin_debug_binary = \"$binarywithsyms\";" >> "$thecfile" | |
219 | ||
220 | # Embed the Info.plist in the __TEXT,__info_plist section. | |
221 | echo "__attribute__((__used__))" >> "$thecfile" | |
222 | ||
223 | echo "__attribute__((__section__(\"__TEXT,__info_plist\")))" >> "$thecfile" | |
224 | echo -n "static const char __darwin_info_plist[] = \"" >> "$thecfile" | |
225 | echo -n "$infoplistcontents" | sed -e 's/\"/\\"/g' | tr -d '\n' >> "$thecfile" | |
226 | echo "\";" >> "$thecfile" | |
227 | ||
228 | echo "" >> "$thecfile" |