Updated V8 from git://github.com/v8/v8.git to 3e6ec7e018bbf2c63ef04b85ff688198ea204c04
[profile/ivi/qtjsbackend.git] / src / 3rdparty / v8 / tools / common-includes.sh
1 # Copyright 2012 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are
4 # met:
5 #
6 #     * Redistributions of source code must retain the above copyright
7 #       notice, this list of conditions and the following disclaimer.
8 #     * Redistributions in binary form must reproduce the above
9 #       copyright notice, this list of conditions and the following
10 #       disclaimer in the documentation and/or other materials provided
11 #       with the distribution.
12 #     * Neither the name of Google Inc. nor the names of its
13 #       contributors may be used to endorse or promote products derived
14 #       from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 # This file contains common function definitions for various other shell
29 # scripts in this directory. It is not meant to be executed by itself.
30
31 # Important: before including this file, the following variables must be set:
32 # - BRANCHNAME
33 # - PERSISTFILE_BASENAME
34
35 TEMP_BRANCH=$BRANCHNAME-temporary-branch-created-by-script
36 VERSION_FILE="src/version.cc"
37 CHANGELOG_ENTRY_FILE="$PERSISTFILE_BASENAME-changelog-entry"
38 PATCH_FILE="$PERSISTFILE_BASENAME-patch"
39 PATCH_OUTPUT_FILE="$PERSISTFILE_BASENAME-patch-output"
40 COMMITMSG_FILE="$PERSISTFILE_BASENAME-commitmsg"
41 TOUCHED_FILES_FILE="$PERSISTFILE_BASENAME-touched-files"
42 TRUNK_REVISION_FILE="$PERSISTFILE_BASENAME-trunkrevision"
43 START_STEP=0
44 CURRENT_STEP=0
45
46 die() {
47   [[ -n "$1" ]] && echo "Error: $1"
48   echo "Exiting."
49   exit 1
50 }
51
52 confirm() {
53   echo -n "$1 [Y/n] "
54   read ANSWER
55   if [[ -z "$ANSWER" || "$ANSWER" == "Y" || "$ANSWER" == "y" ]] ; then
56     return 0
57   else
58     return 1
59   fi
60 }
61
62 delete_branch() {
63   local MATCH=$(git branch | grep "$1" | awk '{print $NF}' | grep -x $1)
64   if [ "$MATCH" == "$1" ] ; then
65     confirm "Branch $1 exists, do you want to delete it?"
66     if [ $? -eq 0 ] ; then
67       git branch -D $1 || die "Deleting branch '$1' failed."
68       echo "Branch $1 deleted."
69     else
70       die "Can't continue. Please delete branch $1 and try again."
71     fi
72   fi
73 }
74
75 # Persist and restore variables to support canceling/resuming execution
76 # of this script.
77 persist() {
78   local VARNAME=$1
79   local FILE="$PERSISTFILE_BASENAME-$VARNAME"
80   local VALUE="${!VARNAME}"
81   if [ -z "$VALUE" ] ; then
82     VALUE="__EMPTY__"
83   fi
84   echo "$VALUE" > $FILE
85 }
86
87 restore() {
88   local VARNAME=$1
89   local FILE="$PERSISTFILE_BASENAME-$VARNAME"
90   local VALUE="$(cat $FILE)"
91   [[ -z "$VALUE" ]] && die "Variable '$VARNAME' could not be restored."
92   if [ "$VALUE" == "__EMPTY__" ] ; then
93     VALUE=""
94   fi
95   eval "$VARNAME=\"$VALUE\""
96 }
97
98 restore_if_unset() {
99   local VARNAME=$1
100   [[ -z "${!VARNAME}" ]] && restore "$VARNAME"
101 }
102
103 initial_environment_checks() {
104   # Cancel if this is not a git checkout.
105   [[ -d .git ]] \
106     || die "This is not a git checkout, this script won't work for you."
107
108   # Cancel if EDITOR is unset or not executable.
109   [[ -n "$EDITOR" && -x "$(which $EDITOR)" ]] \
110     || die "Please set your EDITOR environment variable, you'll need it."
111 }
112
113 common_prepare() {
114   # Check for a clean workdir.
115   [[ -z "$(git status -s -uno)" ]] \
116     || die "Workspace is not clean. Please commit or undo your changes."
117
118   # Persist current branch.
119   CURRENT_BRANCH=$(git status -s -b -uno | grep "^##" | awk '{print $2}')
120   persist "CURRENT_BRANCH"
121
122   # Fetch unfetched revisions.
123   git svn fetch || die "'git svn fetch' failed."
124
125   # Get ahold of a safe temporary branch and check it out.
126   if [ "$CURRENT_BRANCH" != "$TEMP_BRANCH" ] ; then
127     delete_branch $TEMP_BRANCH
128     git checkout -b $TEMP_BRANCH
129   fi
130
131   # Delete the branch that will be created later if it exists already.
132   delete_branch $BRANCHNAME
133 }
134
135 common_cleanup() {
136   restore_if_unset "CURRENT_BRANCH"
137   git checkout -f $CURRENT_BRANCH
138   [[ "$TEMP_BRANCH" != "$CURRENT_BRANCH" ]] && git branch -D $TEMP_BRANCH
139   [[ "$BRANCHNAME" != "$CURRENT_BRANCH" ]] && git branch -D $BRANCHNAME
140   # Clean up all temporary files.
141   rm -f "$PERSISTFILE_BASENAME"*
142 }
143
144 # These two functions take a prefix for the variable names as first argument.
145 read_and_persist_version() {
146   for v in MAJOR_VERSION MINOR_VERSION BUILD_NUMBER PATCH_LEVEL; do
147     VARNAME="$1${v%%_*}"
148     VALUE=$(grep "#define $v" "$VERSION_FILE" | awk '{print $NF}')
149     eval "$VARNAME=\"$VALUE\""
150     persist "$VARNAME"
151   done
152 }
153 restore_version_if_unset() {
154   for v in MAJOR MINOR BUILD PATCH; do
155     restore_if_unset "$1$v"
156   done
157 }
158
159 upload_step() {
160   let CURRENT_STEP+=1
161   if [ $START_STEP -le $CURRENT_STEP ] ; then
162     echo ">>> Step $CURRENT_STEP: Upload for code review."
163     echo -n "Please enter the email address of a V8 reviewer for your patch: "
164     read REVIEWER
165     git cl upload -r "$REVIEWER" --send-mail \
166       || die "'git cl upload' failed, please try again."
167   fi
168 }
169
170 wait_for_lgtm() {
171   echo "Please wait for an LGTM, then type \"LGTM<Return>\" to commit your \
172 change. (If you need to iterate on the patch or double check that it's \
173 sane, do so in another shell, but remember to not change the headline of \
174 the uploaded CL."
175   unset ANSWER
176   while [ "$ANSWER" != "LGTM" ] ; do
177     [[ -n "$ANSWER" ]] && echo "That was not 'LGTM'."
178     echo -n "> "
179     read ANSWER
180   done
181 }
182
183 # Takes a file containing the patch to apply as first argument.
184 apply_patch() {
185   patch $REVERSE_PATCH -p1 < "$1" > "$PATCH_OUTPUT_FILE" || \
186     { cat "$PATCH_OUTPUT_FILE" && die "Applying the patch failed."; }
187   tee < "$PATCH_OUTPUT_FILE" >(grep "patching file" \
188                                | awk '{print $NF}' >> "$TOUCHED_FILES_FILE")
189   rm "$PATCH_OUTPUT_FILE"
190 }
191
192 stage_files() {
193   # Stage added and modified files.
194   TOUCHED_FILES=$(cat "$TOUCHED_FILES_FILE")
195   for FILE in $TOUCHED_FILES ; do
196     git add "$FILE"
197   done
198   # Stage deleted files.
199   DELETED_FILES=$(git status -s -uno --porcelain | grep "^ D" \
200                                                  | awk '{print $NF}')
201   for FILE in $DELETED_FILES ; do
202     git rm "$FILE"
203   done
204   rm -f "$TOUCHED_FILES_FILE"
205 }