| Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | #set -x | 
|  | 3 |  | 
|  | 4 | # used for projects where some files are mainline, some are not | 
|  | 5 | # we get a list of the files/directories out of the project's root. | 
|  | 6 | # | 
|  | 7 | # invocation   $0  ${repo_root} ${preupload_files} | 
|  | 8 | # | 
|  | 9 | # Example PREUPLOAD.cfg: | 
|  | 10 | # | 
|  | 11 | # [Hook Scripts] | 
|  | 12 | # mainline_hook = ${REPO_ROOT}/frameworks/av/tools/mainline_hook_partial.sh ${REPO_ROOT} ${PREUPLOAD_FILES} | 
|  | 13 | # | 
|  | 14 | # MainlineFiles.cfg syntax: | 
|  | 15 | # | 
|  | 16 | # ignore comment (#) lines and blank lines | 
|  | 17 | # rest are path prefixes starting at root of the project | 
|  | 18 | # (so OWNERS, not frameworks/av/OWNERS) | 
|  | 19 | # | 
|  | 20 | # path | 
|  | 21 | # INCLUDE path | 
|  | 22 | # EXCLUDE path | 
|  | 23 | # | 
|  | 24 | # 'path' and 'INCLUDE path' are identical -- they both indicate that this path | 
|  | 25 | # is part of mainline | 
|  | 26 | # EXCLUDE indicates that this is not part of mainline, | 
|  | 27 | # so 'foo/' and 'EXCLUDE foo/nope' | 
|  | 28 | # means everything under foo/ is part of mainline EXCEPT foo/nope. | 
|  | 29 | # INCLUDE/EXCLUDE/INCLUDE nested structuring is not supported | 
|  | 30 | # | 
|  | 31 | # matching is purely prefix | 
|  | 32 | # so 'foo' will match 'foo', 'foo.c', 'foo/bar/baz' | 
|  | 33 | # if you want to exclude a directory, best to use a pattern like "foo/" | 
|  | 34 | # | 
|  | 35 |  | 
|  | 36 | ## tunables: | 
|  | 37 | ## | 
|  | 38 | DEV_BRANCH=rvc-dev | 
|  | 39 | filelist_file=MainlineFiles.cfg | 
|  | 40 |  | 
|  | 41 | ### | 
|  | 42 |  | 
|  | 43 | REPO_ROOT=$1; shift | 
|  | 44 | # the rest of the command line is the file list | 
|  | 45 | PREUPLOAD_FILES="$*" | 
|  | 46 |  | 
|  | 47 | RED=$(tput setaf 1) | 
|  | 48 | NORMAL=$(tput sgr0) | 
|  | 49 |  | 
|  | 50 | ## get the active branch: | 
|  | 51 | ## * <localbranch> <shainfo> [goog/master] Fix to handle missing checks on error returned | 
|  | 52 | ## strip this down to "master" | 
|  | 53 | ## | 
|  | 54 | current=`git branch -vv | grep -P "^\*[^\[]+\[goog/"|sed -e 's/^.*\[//' | sed -e 's/:.*$//'| sed -e 's/^goog\///'` | 
|  | 55 | if [ "${current}" = "" ] ; then | 
|  | 56 | current=unknown | 
|  | 57 | fi | 
|  | 58 |  | 
|  | 59 | ## figure out whether which files are for mainline and which are not | 
|  | 60 | if [ "${PREUPLOAD_FILES}" = "" ] ; then | 
|  | 61 | # empty files? what's up there, i suppose we'll let that go | 
|  | 62 | exit 0 | 
|  | 63 | fi | 
|  | 64 |  | 
|  | 65 | ## get the list of files out of the project's root | 
|  | 66 | ## figure out which way I'm going .. | 
|  | 67 | ## use list of files to scan PREUPLOAD_FILES | 
|  | 68 | ## use PREUPLOAD_FILES to scan the list of good/bad from the project root | 
|  | 69 | ## | 
|  | 70 | ## remember to do an exclude, so I can say | 
|  | 71 | ## include/these/files/ | 
|  | 72 | ## EXCLUDE include/these/files/nested/ | 
|  | 73 | ## | 
|  | 74 | ## and it should all be prefix based stuff... | 
|  | 75 |  | 
|  | 76 | if [ ! -f ${REPO_ROOT}/${REPO_PATH}/${filelist_file} ] ; then | 
|  | 77 | echo "Poorly Configured project, missing ${filelist_file} in root of project" | 
|  | 78 | exit 1 | 
|  | 79 | fi | 
|  | 80 |  | 
|  | 81 | # is 1st arg a prefix of 2nd arg | 
|  | 82 | beginswith() { case $2 in "$1"*) true;; *) false;; esac; } | 
|  | 83 |  | 
|  | 84 | exclusions="" | 
|  | 85 | inclusions="" | 
|  | 86 | while read p1 p2 | 
|  | 87 | do | 
|  | 88 | # ignore comment lines in the file | 
|  | 89 | # ignore empty lines in the file | 
|  | 90 | if beginswith "#" "${p1}" ; then | 
|  | 91 | # ignore this line | 
|  | 92 | true | 
|  | 93 | elif [ -z "${p1}" ] ; then | 
|  | 94 | # ignore blanks | 
|  | 95 | true | 
|  | 96 | elif [ ${p1} = "EXCLUDE" ] ; then | 
|  | 97 | # add to the exclusion list | 
|  | 98 | if [ ! -z ${p2} ] ; then | 
|  | 99 | exlusions="${exclusions} ${p2}" | 
|  | 100 | fi | 
|  | 101 | elif [ ${p1} = "INCLUDE" ] ; then | 
|  | 102 | # add to the inclusion list | 
|  | 103 | if [ ! -z ${p2} ] ; then | 
|  | 104 | inclusions="${inclusions} ${p2}" | 
|  | 105 | fi | 
|  | 106 | elif [ ! -z ${p1} ] ; then | 
|  | 107 | inclusions="${inclusions} ${p1}" | 
|  | 108 | fi | 
|  | 109 | done < ${REPO_ROOT}/${REPO_PATH}/${filelist_file} | 
|  | 110 |  | 
|  | 111 | # so we can play with array syntax | 
|  | 112 | #INCLUSIONS=( ${inclusions} ) | 
|  | 113 | #EXCLUSIONS=( ${exclusions} ) | 
|  | 114 |  | 
|  | 115 | mainline_yes="" | 
|  | 116 | mainline_no="" | 
|  | 117 |  | 
|  | 118 | # is it part of the list of mainline files/directories? | 
|  | 119 | for path in ${PREUPLOAD_FILES} ; do | 
|  | 120 | #echo is ${path} a mainline file... | 
|  | 121 | for aprefix in ${inclusions} .. ; do | 
|  | 122 | #echo compare against ${aprefix} ... | 
|  | 123 | if [ "${aprefix}" = ".." ] ; then | 
|  | 124 | mainline_no="${mainline_no} ${path}" | 
|  | 125 | elif beginswith ${aprefix} ${path} ; then | 
|  | 126 | mainline_yes="${mainline_yes} ${path}" | 
|  | 127 | break       # on to next uploaded file | 
|  | 128 | fi | 
|  | 129 | done | 
|  | 130 | done | 
|  | 131 |  | 
|  | 132 | # TODO: audit the yes list to see if some should be moved to the no list | 
|  | 133 |  | 
|  | 134 | # 3 situations | 
|  | 135 | # -- everything is on mainline (mainline_yes non-empty, other empty) | 
|  | 136 | # -- some is mainline, some is not (files_* both non-empty) | 
|  | 137 | # -- none is mainline   (mainline_yes empty, other non_empty | 
|  | 138 | # -- both empty only happens if PREUPLOAD_FILES is empty, covered above | 
|  | 139 |  | 
|  | 140 | if [ -z "${mainline_yes}" ] ; then | 
|  | 141 | # no mainline files, everything else is non-mainline, let it go | 
|  | 142 | exit 0 | 
|  | 143 | fi | 
|  | 144 |  | 
|  | 145 | result=0 | 
|  | 146 | if [ ! -z "${mainline_no}" ] ; then | 
|  | 147 | # mixed bag, suggest (not insist) that developer split them. | 
|  | 148 | result=1 | 
|  | 149 | cat - <<EOF | 
|  | 150 | This CL contains files contains both mainline and non-mainline files.  Consider separating | 
|  | 151 | them into separate CLs. It may also be appropriate to update the list of mainline | 
|  | 152 | files in ${RED}${REPO_ROOT}/${filelist_file}${NORMAL}. | 
|  | 153 |  | 
|  | 154 | EOF | 
|  | 155 | echo "===== Mainline files =====" | 
|  | 156 | echo -e ${RED} | 
|  | 157 | echo ${mainline_yes} | sed -e 's/ /
/g' | 
|  | 158 | echo -e ${NORMAL} | 
|  | 159 |  | 
|  | 160 | echo "===== Non-Mainline files =====" | 
|  | 161 | echo -e ${RED} | 
|  | 162 | echo ${mainline_no} | sed -e 's/ /
/g' | 
|  | 163 | echo -e ${NORMAL} | 
|  | 164 |  | 
|  | 165 | fi | 
|  | 166 |  | 
|  | 167 | if [ "${current}" != "${DEV_BRANCH}" ] ; then | 
|  | 168 | # Change is not in the desired mainline dev branch | 
|  | 169 | result=1 | 
|  | 170 |  | 
|  | 171 | #echo -e "${RED}" | 
|  | 172 | cat - <<EOF | 
|  | 173 |  | 
|  | 174 | You are uploading repo  ${RED}${REPO_PATH}${NORMAL} to branch ${RED}${current}${NORMAL}. | 
|  | 175 | The source of truth for ${RED}${REPO_PATH}${NORMAL} is branch ${RED}${DEV_BRANCH}${NORMAL}. | 
|  | 176 |  | 
|  | 177 | Please upload this change to branch ${RED}${DEV_BRANCH}${NORMAL} unless one or more of | 
|  | 178 | the following apply: | 
|  | 179 | - this is a security bug prohibited from disclosure before the next dessert release. | 
|  | 180 | (moderate security bugs fall into this category). | 
|  | 181 | - this is new functionality prohibitied from disclosure before the next dessert release. | 
|  | 182 | EOF | 
|  | 183 | #echo -e "${NORMAL}" | 
|  | 184 |  | 
|  | 185 | fi | 
|  | 186 |  | 
|  | 187 | ## since stdout is buffered in a way that complicates the below, we're just going | 
|  | 188 | ## to tell the user what they can do to get around this check instead of asking them | 
|  | 189 | ## as part of this run of the command. | 
|  | 190 |  | 
|  | 191 | if [ ${result} != 0 ] ; then | 
|  | 192 | cat - <<EOF | 
|  | 193 |  | 
|  | 194 | If you are sure you want to proceed uploading to branch ${RED}${current}${NORMAL}, | 
|  | 195 | re-run your repo upload command with the '--no-verify' option | 
|  | 196 |  | 
|  | 197 | EOF | 
|  | 198 | fi | 
|  | 199 | exit ${result} | 
|  | 200 |  |