Bijan Amirzada | 69b30be | 2014-02-26 17:08:10 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2013, The Linux Foundation. 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 are |
| 7 | # met: |
| 8 | # * Redistributions of source code must retain the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer. |
| 10 | # * Redistributions in binary form must reproduce the above |
| 11 | # copyright notice, this list of conditions and the following |
| 12 | # disclaimer in the documentation and/or other materials provided |
| 13 | # with the distribution. |
| 14 | # * Neither the name of The Linux Foundation nor the names of its |
| 15 | # contributors may be used to endorse or promote products derived |
| 16 | # from this software without specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 19 | # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 22 | # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 25 | # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 27 | # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 28 | # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | # |
| 30 | # Construct the XML entity for the &about; entity in |
| 31 | # res/values/about.xml. |
| 32 | # |
| 33 | # Usage: |
| 34 | # generate_about.sh [OPTIONS] |
| 35 | # |
| 36 | # Generates SWE Android Browser's About box XML resource and |
| 37 | # emits manifest version name/code values |
| 38 | # |
| 39 | # Options: |
| 40 | # --name : emit suitable manifest version name |
| 41 | # --code : emit suitable manifest version code |
| 42 | # --about : generate res/values/about.xml |
| 43 | # |
| 44 | # |
| 45 | me=${0##*/} |
| 46 | mydir=${0%/*} |
| 47 | |
| 48 | # input/output files |
| 49 | VERSIONFILE=${mydir}/../VERSION |
| 50 | ABOUTFILE=${mydir}/../res/values/about.xml |
| 51 | |
| 52 | # default |
| 53 | NAME=0 |
| 54 | CODE=0 |
| 55 | ABOUT=0 |
| 56 | QUIET=0 |
| 57 | |
| 58 | # poor man's getopt() |
| 59 | [[ " ${*} " =~ " --name " ]] && NAME=1 |
| 60 | [[ " ${*} " =~ " --code " ]] && CODE=1 |
| 61 | [[ " ${*} " =~ " --quiet " ]] && QUIET=1 |
| 62 | [[ " ${*} " =~ " --about " ]] && ABOUT=1 |
| 63 | |
| 64 | function warning() |
| 65 | { |
| 66 | (( ${QUIET} )) || echo "Warning: ${me}: $@" >&2 |
| 67 | } |
| 68 | |
| 69 | function error() |
| 70 | { |
| 71 | ret=$1 |
| 72 | shift |
| 73 | echo "Error: ${me}: $@" >&2 |
| 74 | exit ${retval} |
| 75 | } |
| 76 | |
| 77 | |
| 78 | BASEVERSION=$(cat ${VERSIONFILE}) || error 1 "couldn't read \"${VERSIONFILE}\"" |
| 79 | BASEVERSION=( ${BASEVERSION//./ } ) |
| 80 | MAJOR=${BASEVERSION[0]} |
| 81 | MINOR=${BASEVERSION[1]} |
| 82 | BRANCH=unknown |
| 83 | BUILDID=unknown |
| 84 | VERSION=${MAJOR}.${MINOR} |
| 85 | |
| 86 | # defaults |
| 87 | HASH=unknown |
| 88 | |
| 89 | DATE=$(date) || warning "unable to get date" |
| 90 | |
| 91 | # collect information about branch, version, etc. from CHROME_SRC |
| 92 | while [[ -d "${CHROME_SRC}" ]] |
| 93 | do |
| 94 | pushd "${CHROME_SRC}" >/dev/null || error 1 "can't pushd ${CHROME_SRC}.." |
| 95 | |
| 96 | # this had better work.. |
| 97 | if ! HASH=$(git rev-parse --short HEAD) |
| 98 | then |
| 99 | HASH=unknown |
| 100 | warning "${CHROME_SRC} apparently not under git?" |
| 101 | break |
| 102 | fi |
| 103 | |
| 104 | # collect branch and clean it up |
| 105 | BRANCH=$(git branch | awk '/^\*/') |
| 106 | BRANCH=${BRANCH#\* } |
| 107 | |
| 108 | # try to get the best form of the branch, to |
| 109 | # catch detached HEADs, etc. |
| 110 | while read |
| 111 | do |
| 112 | REPLY=${REPLY// /} |
| 113 | [[ ${REPLY:0:1} == "(" ]] && continue |
| 114 | REPLY=${REPLY%->*} |
Karthikeyan Periasamy | efb7aee | 2014-10-31 10:37:36 -0700 | [diff] [blame] | 115 | git log -1 --oneline ${REPLY} | grep "${HASH}" &>/dev/null && BRANCH=${REPLY} && break; |
| 116 | done < <(git branch -a | grep -Ev "\*" 2>/dev/null) |
Bijan Amirzada | 69b30be | 2014-02-26 17:08:10 -0800 | [diff] [blame] | 117 | |
| 118 | if [[ ${BRANCH//(/} == ${BRANCH} ]] |
| 119 | then |
| 120 | # trim branch to a num, or a smaller name |
| 121 | BRANCH=${BRANCH##*/} |
| 122 | fi |
| 123 | |
| 124 | # tack on branch |
| 125 | VERSION=${VERSION}.${BRANCH} |
| 126 | |
| 127 | # construct a version, start with a default |
| 128 | MERGE_BASE=$(git merge-base remotes/origin/master "${HASH}") || warning "can't find a merge-base with master for hash \"$HASH\"" |
| 129 | |
| 130 | # requires grafted tree and numeric branch name |
| 131 | if [[ -n ${MERGE_BASE} ]] |
| 132 | then |
| 133 | BUILDID=$(git log --oneline ${MERGE_BASE}.. | wc -l) |
| 134 | VERSION=${VERSION}.${BUILDID} |
| 135 | else |
| 136 | warning "using version ${VERSION}.. merge-base:\"${MERGE_BASE}\" branch: \"${BRANCH}\"" |
| 137 | fi |
| 138 | |
Bijan Amirzada | 69b30be | 2014-02-26 17:08:10 -0800 | [diff] [blame] | 139 | popd >/dev/null || error 1 "popd from $CHROME_SRC failed?" |
| 140 | break |
| 141 | done |
| 142 | |
| 143 | if (( ${ABOUT} )) |
| 144 | then |
| 145 | # add a support link, if configured |
| 146 | if [[ -n ${SWE_APK_SUPPORT} ]] |
| 147 | then |
| 148 | CONTACT="Please help us make your experience better by contacting the |
| 149 | team at <a href=\"mailto:${SWE_APK_SUPPORT}\">${SWE_APK_SUPPORT}</a>\n" |
| 150 | fi |
| 151 | |
| 152 | printf %s "<?xml version=\"1.0\" encoding=\"utf-8\"?> |
| 153 | <resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\"> |
Bijan Amirzada | 69b30be | 2014-02-26 17:08:10 -0800 | [diff] [blame] | 154 | <!-- Text to display in about dialog --> |
| 155 | <string name=\"about_text\" formatted=\"false\"> |
| 156 | ${CONTACT} |
| 157 | Version: ${VERSION}\n |
| 158 | Built: ${DATE}\n |
| 159 | Host: ${HOSTNAME}\n |
| 160 | User: ${USER}\n |
| 161 | Hash: ${HASH} (${BRANCH})\n |
Bijan Amirzada | 69b30be | 2014-02-26 17:08:10 -0800 | [diff] [blame] | 162 | </string> |
| 163 | </resources> |
| 164 | " > "${ABOUTFILE}" || error 1 "could not write to ${ABOUTFILE}" |
| 165 | fi |
| 166 | |
| 167 | (( ${NAME} )) && echo "${VERSION} (${HASH})" |
| 168 | |
| 169 | # decimal-ify for printf |
| 170 | [[ -n ${MAJOR//[0-9]/} ]] && MAJOR=0 |
| 171 | [[ -n ${MINOR//[0-9]/} ]] && MINOR=0 |
| 172 | [[ -n ${BRANCH//[0-9]/} ]] && BRANCH=0 |
| 173 | [[ -n ${BUILDID//[0-9]/} ]] && BUILDID=0 |
| 174 | |
| 175 | (( ${CODE} )) && printf "%d%02d%06d%05d\n" $((${MAJOR})) $((${MINOR})) $((${BRANCH})) $((${BUILDID})) |
| 176 | |
| 177 | exit 0 |