blob: 185ce1165e73fdfaae15006973c6b8a8c63d214c [file] [log] [blame]
Bijan Amirzada69b30be2014-02-26 17:08:10 -08001#!/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#
45me=${0##*/}
46mydir=${0%/*}
47
48# input/output files
49VERSIONFILE=${mydir}/../VERSION
50ABOUTFILE=${mydir}/../res/values/about.xml
51
52# default
53NAME=0
54CODE=0
55ABOUT=0
56QUIET=0
57
58# poor man's getopt()
59[[ " ${*} " =~ " --name " ]] && NAME=1
60[[ " ${*} " =~ " --code " ]] && CODE=1
61[[ " ${*} " =~ " --quiet " ]] && QUIET=1
62[[ " ${*} " =~ " --about " ]] && ABOUT=1
63
64function warning()
65{
66 (( ${QUIET} )) || echo "Warning: ${me}: $@" >&2
67}
68
69function error()
70{
71 ret=$1
72 shift
73 echo "Error: ${me}: $@" >&2
74 exit ${retval}
75}
76
Tarun Nainani5229d6a2015-03-24 13:16:29 -070077VERSIONINFO=$(cat ${VERSIONFILE}) || error 1 "couldn't read \"${VERSIONFILE}\""
78VERSIONINFO=( ${VERSIONINFO//;/ } )
Bijan Amirzada69b30be2014-02-26 17:08:10 -080079
Tarun Nainani5229d6a2015-03-24 13:16:29 -070080BASE_STRING=( ${VERSIONINFO[0]//=/ } )
81BASE_STRING=( ${BASE_STRING[1]//./ } )
82MAJOR=${BASE_STRING[0]}
83MINOR=${BASE_STRING[1]}
84
85BRANCH=( ${VERSIONINFO[1]//=/ } )
86BRANCH=${BRANCH[1]}
Bijan Amirzada69b30be2014-02-26 17:08:10 -080087BUILDID=unknown
88VERSION=${MAJOR}.${MINOR}
89
90# defaults
91HASH=unknown
92
93DATE=$(date) || warning "unable to get date"
94
95# collect information about branch, version, etc. from CHROME_SRC
96while [[ -d "${CHROME_SRC}" ]]
97do
98 pushd "${CHROME_SRC}" >/dev/null || error 1 "can't pushd ${CHROME_SRC}.."
99
100 # this had better work..
101 if ! HASH=$(git rev-parse --short HEAD)
102 then
103 HASH=unknown
104 warning "${CHROME_SRC} apparently not under git?"
105 break
106 fi
107
108 # collect branch and clean it up
Bijan Amirzada69b30be2014-02-26 17:08:10 -0800109 # tack on branch
110 VERSION=${VERSION}.${BRANCH}
111
112 # construct a version, start with a default
113 MERGE_BASE=$(git merge-base remotes/origin/master "${HASH}") || warning "can't find a merge-base with master for hash \"$HASH\""
114
115 # requires grafted tree and numeric branch name
116 if [[ -n ${MERGE_BASE} ]]
117 then
118 BUILDID=$(git log --oneline ${MERGE_BASE}.. | wc -l)
119 VERSION=${VERSION}.${BUILDID}
120 else
121 warning "using version ${VERSION}.. merge-base:\"${MERGE_BASE}\" branch: \"${BRANCH}\""
122 fi
123
Bijan Amirzada69b30be2014-02-26 17:08:10 -0800124 popd >/dev/null || error 1 "popd from $CHROME_SRC failed?"
125 break
126done
127
128if (( ${ABOUT} ))
129then
130 # add a support link, if configured
131 if [[ -n ${SWE_APK_SUPPORT} ]]
132 then
133 CONTACT="Please help us make your experience better by contacting the
134team at <a href=\"mailto:${SWE_APK_SUPPORT}\">${SWE_APK_SUPPORT}</a>\n"
135 fi
136
137 printf %s "<?xml version=\"1.0\" encoding=\"utf-8\"?>
138<resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">
Bijan Amirzada69b30be2014-02-26 17:08:10 -0800139 <!-- Text to display in about dialog -->
140 <string name=\"about_text\" formatted=\"false\">
141${CONTACT}
142Version: ${VERSION}\n
143Built: ${DATE}\n
144Host: ${HOSTNAME}\n
145User: ${USER}\n
146Hash: ${HASH} (${BRANCH})\n
Bijan Amirzada69b30be2014-02-26 17:08:10 -0800147</string>
148</resources>
149" > "${ABOUTFILE}" || error 1 "could not write to ${ABOUTFILE}"
150fi
151
152(( ${NAME} )) && echo "${VERSION} (${HASH})"
153
154# decimal-ify for printf
155[[ -n ${MAJOR//[0-9]/} ]] && MAJOR=0
156[[ -n ${MINOR//[0-9]/} ]] && MINOR=0
157[[ -n ${BRANCH//[0-9]/} ]] && BRANCH=0
158[[ -n ${BUILDID//[0-9]/} ]] && BUILDID=0
159
Tarun Nainani5229d6a2015-03-24 13:16:29 -0700160# This value should always be less than MAX int value "2147483647"
161(( ${CODE} )) && printf "%4d%04d\n" $((${BRANCH})) $((${BUILDID}))
162
Bijan Amirzada69b30be2014-02-26 17:08:10 -0800163
164exit 0