3 # Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # Trim any trailing \r or \n from the given variable.
30 local old_value=$(eval echo "\$$1");
31 local value=$(echo "$old_value" | sed 's/[\r\n]*$//')
35 if [[ -n "$WEBKIT_LIBRARIES" ]]; then
36 FALLBACK_VERSION_PATH=`cygpath -u "$WEBKIT_LIBRARIES\\tools\\scripts\\VERSION"`
37 FALLBACK_VERSION=$(cat "$FALLBACK_VERSION_PATH");
39 COPYRIGHT_END_YEAR_PATH=`cygpath -u "$WEBKIT_LIBRARIES\\tools\\scripts\\COPYRIGHT-END-YEAR"`
40 COPYRIGHT_END_YEAR=$(cat "$COPYRIGHT_END_YEAR_PATH");
41 chomp COPYRIGHT_END_YEAR
44 OUTPUT_FILE=$(cygpath -u "$1")/include/autoversion.h
45 mkdir -p "$(dirname "$OUTPUT_FILE")"
47 # Take the initial version number from RC_ProjectSourceVersion if it
48 # exists, otherwise fall back to the version number stored in the source.
49 ENVIRONMENT_VERSION="$RC_ProjectSourceVersion";
50 if [[ -z "$ENVIRONMENT_VERSION" ]]; then
51 # Try the original all-caps version of the environment variable
52 ENVIRONMENT_VERSION="$RC_PROJECTSOURCEVERSION";
55 PROPOSED_VERSION=${ENVIRONMENT_VERSION:-$FALLBACK_VERSION}
56 chomp PROPOSED_VERSION
58 # Split out the three components of the dotted version number. We pad
59 # the input with trailing dots to handle the case where the input version
60 # has fewer components than we expect.
61 BUILD_MAJOR_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 1)
62 BUILD_MINOR_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 2)
63 BUILD_TINY_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 3)
65 # Cut the major component down to three characters by dropping any
66 # extra leading digits, then adjust the major version portion of the
67 # version string to match.
68 CHARACTERS_TO_DROP=$(( ${#BUILD_MAJOR_VERSION} > 3 ? ${#BUILD_MAJOR_VERSION} - 3 : 0 ))
69 BUILD_MAJOR_VERSION=${BUILD_MAJOR_VERSION:$CHARACTERS_TO_DROP}
70 PROPOSED_VERSION=${PROPOSED_VERSION:$CHARACTERS_TO_DROP}
72 # Have the minor and tiny components default to zero if not present.
73 BUILD_MINOR_VERSION=${BUILD_MINOR_VERSION:-0}
74 BUILD_TINY_VERSION=${BUILD_TINY_VERSION:-0}
76 # Split the first component further by using the first digit for the
77 # major version and the remaining two characters as the minor version.
78 # The minor version is shifted down to the tiny version, with the tiny
79 # version becoming the variant version.
80 MAJOR_VERSION=${BUILD_MAJOR_VERSION:0:1}
81 MINOR_VERSION=${BUILD_MAJOR_VERSION:1}
82 TINY_VERSION=${BUILD_MINOR_VERSION}
83 VARIANT_VERSION=${BUILD_TINY_VERSION}
85 VERSION_TEXT=${PROPOSED_VERSION}
86 VERSION_TEXT_SHORT=${VERSION_TEXT}
88 if [ -z ${ENVIRONMENT_VERSION} ]; then
89 # If we didn't pull the version number from the environment then we're doing
90 # an engineering build and we'll stamp the build with some more information.
93 SVN_REVISION=$(svn info | grep '^Revision' | sed 's/^Revision: //')
98 VERSION_TEXT_SHORT="${VERSION_TEXT_SHORT}+"
99 VERSION_TEXT="${VERSION_TEXT_SHORT} ${USER} - ${BUILD_DATE} - r${SVN_REVISION}"
102 cat > "$OUTPUT_FILE" <<EOF
103 #define __VERSION_TEXT__ "${VERSION_TEXT}"
104 #define __BUILD_NUMBER__ "${VERSION_TEXT}"
105 #define __BUILD_NUMBER_SHORT__ "${VERSION_TEXT_SHORT}"
106 #define __VERSION_MAJOR__ ${MAJOR_VERSION}
107 #define __VERSION_MINOR__ ${MINOR_VERSION}
108 #define __VERSION_TINY__ ${TINY_VERSION}
109 #define __VERSION_BUILD__ ${VARIANT_VERSION}
110 #define __BUILD_NUMBER_MAJOR__ ${BUILD_MAJOR_VERSION}
111 #define __BUILD_NUMBER_MINOR__ ${BUILD_MINOR_VERSION}
112 #define __BUILD_NUMBER_VARIANT__ ${BUILD_TINY_VERSION}
113 #define __SVN_REVISION__ ${SVN_REVISION}
116 if [[ -n "${COPYRIGHT_END_YEAR}" ]]; then
117 cat >> "$OUTPUT_FILE" <<EOF
118 #define __COPYRIGHT_YEAR_END_TEXT__ "${COPYRIGHT_END_YEAR}"