Home | History | Annotate | Download | only in scripts
      1 #!/usr/bin/bash
      2 
      3 # Copyright (C) 2007, 2009 Apple Inc.  All rights reserved.
      4 #
      5 # Redistribution and use in source and binary forms, with or without
      6 # modification, are permitted provided that the following conditions
      7 # are met:
      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.
     13 #
     14 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, 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 COMPUTER, 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. 
     25 
     26 
     27 # Trim any trailing \r or \n from the given variable.
     28 chomp()
     29 {
     30     local old_value=$(eval echo "\$$1");
     31     local value=$(echo "$old_value" | sed 's/[\r\n]*$//')
     32     eval $1=\$value;
     33 }
     34 
     35 if [[ -n "$WEBKITLIBRARIESDIR" ]]; then
     36     FALLBACK_VERSION_PATH=`cygpath -u "$WEBKITLIBRARIESDIR\\tools\\scripts\\VERSION"`
     37     FALLBACK_VERSION=$(cat "$FALLBACK_VERSION_PATH");
     38 
     39     COPYRIGHT_END_YEAR_PATH=`cygpath -u "$WEBKITLIBRARIESDIR\\tools\\scripts\\COPYRIGHT-END-YEAR"`
     40     COPYRIGHT_END_YEAR=$(cat "$COPYRIGHT_END_YEAR_PATH");
     41     chomp COPYRIGHT_END_YEAR
     42 fi
     43 
     44 OUTPUT_FILE=$(cygpath -u "$1")/include/autoversion.h
     45 mkdir -p "$(dirname "$OUTPUT_FILE")"
     46 
     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 PROPOSED_VERSION=${ENVIRONMENT_VERSION:-$FALLBACK_VERSION}
     51 chomp PROPOSED_VERSION
     52 
     53 # Split out the three components of the dotted version number.  We pad
     54 # the input with trailing dots to handle the case where the input version
     55 # has fewer components than we expect.
     56 BUILD_MAJOR_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 1)
     57 BUILD_MINOR_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 2)
     58 BUILD_TINY_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 3)
     59 
     60 # Cut the major component down to three characters by dropping any
     61 # extra leading digits, then adjust the major version portion of the
     62 # version string to match.
     63 CHARACTERS_TO_DROP=$(( ${#BUILD_MAJOR_VERSION} > 3 ? ${#BUILD_MAJOR_VERSION} - 3 : 0 ))
     64 BUILD_MAJOR_VERSION=${BUILD_MAJOR_VERSION:$CHARACTERS_TO_DROP}
     65 PROPOSED_VERSION=${PROPOSED_VERSION:$CHARACTERS_TO_DROP}
     66 
     67 # Have the minor and tiny components default to zero if not present.
     68 BUILD_MINOR_VERSION=${BUILD_MINOR_VERSION:-0}
     69 BUILD_TINY_VERSION=${BUILD_TINY_VERSION:-0}
     70 
     71 # Split the first component further by using the first digit for the
     72 # major version and the remaining two characters as the minor version.
     73 # The minor version is shifted down to the tiny version, with the tiny
     74 # version becoming the variant version.
     75 MAJOR_VERSION=${BUILD_MAJOR_VERSION:0:1}
     76 MINOR_VERSION=${BUILD_MAJOR_VERSION:1}
     77 TINY_VERSION=${BUILD_MINOR_VERSION}
     78 VARIANT_VERSION=${BUILD_TINY_VERSION}
     79 
     80 VERSION_TEXT=${PROPOSED_VERSION}
     81 VERSION_TEXT_SHORT=${VERSION_TEXT}
     82 
     83 if [ -z ${ENVIRONMENT_VERSION} ]; then
     84     # If we didn't pull the version number from the environment then we're doing
     85     # an engineering build and we'll stamp the build with some more information.
     86 
     87     BUILD_DATE=$(date)
     88     SVN_REVISION=$(svn info | grep '^Revision' | sed 's/^Revision: //')
     89 
     90     chomp BUILD_DATE
     91     chomp SVN_REVISION
     92 
     93     VERSION_TEXT_SHORT="${VERSION_TEXT_SHORT}+"
     94     VERSION_TEXT="${VERSION_TEXT_SHORT} ${USER} - ${BUILD_DATE} - r${SVN_REVISION}"
     95 fi
     96 
     97 cat > "$OUTPUT_FILE" <<EOF
     98 #define __VERSION_TEXT__ "${VERSION_TEXT}"
     99 #define __BUILD_NUMBER__ "${VERSION_TEXT}"
    100 #define __BUILD_NUMBER_SHORT__ "${VERSION_TEXT_SHORT}"
    101 #define __VERSION_MAJOR__ ${MAJOR_VERSION}
    102 #define __VERSION_MINOR__ ${MINOR_VERSION}
    103 #define __VERSION_TINY__ ${TINY_VERSION}
    104 #define __VERSION_BUILD__ ${VARIANT_VERSION}
    105 #define __BUILD_NUMBER_MAJOR__ ${BUILD_MAJOR_VERSION}
    106 #define __BUILD_NUMBER_MINOR__ ${BUILD_MINOR_VERSION}
    107 #define __BUILD_NUMBER_VARIANT__ ${BUILD_TINY_VERSION}
    108 #define __SVN_REVISION__ ${SVN_REVISION}
    109 EOF
    110 
    111 if [[ -n "${COPYRIGHT_END_YEAR}" ]]; then
    112 cat >> "$OUTPUT_FILE" <<EOF
    113 #define __COPYRIGHT_YEAR_END_TEXT__ "${COPYRIGHT_END_YEAR}"
    114 EOF
    115 fi
    116