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 | ## |
Ray Essick | be5e36b | 2021-02-10 09:56:45 -0800 | [diff] [blame] | 38 | DEV_BRANCH=master |
Ray Essick | 0a6eb00 | 2021-04-30 11:33:43 -0700 | [diff] [blame^] | 39 | MAINLINE_BRANCH=sc-mainline-prod |
Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 40 | filelist_file=MainlineFiles.cfg |
| 41 | |
| 42 | ### |
| 43 | |
| 44 | REPO_ROOT=$1; shift |
| 45 | # the rest of the command line is the file list |
| 46 | PREUPLOAD_FILES="$*" |
| 47 | |
| 48 | RED=$(tput setaf 1) |
| 49 | NORMAL=$(tput sgr0) |
| 50 | |
| 51 | ## get the active branch: |
| 52 | ## * <localbranch> <shainfo> [goog/master] Fix to handle missing checks on error returned |
| 53 | ## strip this down to "master" |
Ray Essick | be5e36b | 2021-02-10 09:56:45 -0800 | [diff] [blame] | 54 | ## * b157501573_advisory 25521834a6 [goog/sc-dev] Merge "PlayerBase: add audio session ID" into sc-dev |
Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 55 | ## |
Ray Essick | be5e36b | 2021-02-10 09:56:45 -0800 | [diff] [blame] | 56 | current=`git branch -vv | grep -P "^\*[^\[]+\[goog/"|sed -e 's/^.*\[//' | sed -e 's/\].*$//'|sed -e 's/:.*$//'| sed -e 's/^goog\///'` |
Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 57 | if [ "${current}" = "" ] ; then |
| 58 | current=unknown |
| 59 | fi |
| 60 | |
| 61 | ## figure out whether which files are for mainline and which are not |
| 62 | if [ "${PREUPLOAD_FILES}" = "" ] ; then |
| 63 | # empty files? what's up there, i suppose we'll let that go |
| 64 | exit 0 |
| 65 | fi |
| 66 | |
| 67 | ## get the list of files out of the project's root |
| 68 | ## figure out which way I'm going .. |
| 69 | ## use list of files to scan PREUPLOAD_FILES |
| 70 | ## use PREUPLOAD_FILES to scan the list of good/bad from the project root |
| 71 | ## |
| 72 | ## remember to do an exclude, so I can say |
| 73 | ## include/these/files/ |
| 74 | ## EXCLUDE include/these/files/nested/ |
| 75 | ## |
| 76 | ## and it should all be prefix based stuff... |
| 77 | |
| 78 | if [ ! -f ${REPO_ROOT}/${REPO_PATH}/${filelist_file} ] ; then |
| 79 | echo "Poorly Configured project, missing ${filelist_file} in root of project" |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | # is 1st arg a prefix of 2nd arg |
| 84 | beginswith() { case $2 in "$1"*) true;; *) false;; esac; } |
| 85 | |
| 86 | exclusions="" |
| 87 | inclusions="" |
| 88 | while read p1 p2 |
| 89 | do |
| 90 | # ignore comment lines in the file |
| 91 | # ignore empty lines in the file |
| 92 | if beginswith "#" "${p1}" ; then |
| 93 | # ignore this line |
| 94 | true |
| 95 | elif [ -z "${p1}" ] ; then |
| 96 | # ignore blanks |
| 97 | true |
| 98 | elif [ ${p1} = "EXCLUDE" ] ; then |
| 99 | # add to the exclusion list |
| 100 | if [ ! -z ${p2} ] ; then |
| 101 | exlusions="${exclusions} ${p2}" |
| 102 | fi |
| 103 | elif [ ${p1} = "INCLUDE" ] ; then |
| 104 | # add to the inclusion list |
| 105 | if [ ! -z ${p2} ] ; then |
| 106 | inclusions="${inclusions} ${p2}" |
| 107 | fi |
| 108 | elif [ ! -z ${p1} ] ; then |
| 109 | inclusions="${inclusions} ${p1}" |
| 110 | fi |
| 111 | done < ${REPO_ROOT}/${REPO_PATH}/${filelist_file} |
| 112 | |
| 113 | # so we can play with array syntax |
| 114 | #INCLUSIONS=( ${inclusions} ) |
| 115 | #EXCLUSIONS=( ${exclusions} ) |
| 116 | |
| 117 | mainline_yes="" |
| 118 | mainline_no="" |
| 119 | |
| 120 | # is it part of the list of mainline files/directories? |
| 121 | for path in ${PREUPLOAD_FILES} ; do |
| 122 | #echo is ${path} a mainline file... |
| 123 | for aprefix in ${inclusions} .. ; do |
| 124 | #echo compare against ${aprefix} ... |
| 125 | if [ "${aprefix}" = ".." ] ; then |
| 126 | mainline_no="${mainline_no} ${path}" |
| 127 | elif beginswith ${aprefix} ${path} ; then |
| 128 | mainline_yes="${mainline_yes} ${path}" |
| 129 | break # on to next uploaded file |
| 130 | fi |
| 131 | done |
| 132 | done |
| 133 | |
| 134 | # TODO: audit the yes list to see if some should be moved to the no list |
| 135 | |
| 136 | # 3 situations |
| 137 | # -- everything is on mainline (mainline_yes non-empty, other empty) |
| 138 | # -- some is mainline, some is not (files_* both non-empty) |
| 139 | # -- none is mainline (mainline_yes empty, other non_empty |
| 140 | # -- both empty only happens if PREUPLOAD_FILES is empty, covered above |
| 141 | |
| 142 | if [ -z "${mainline_yes}" ] ; then |
| 143 | # no mainline files, everything else is non-mainline, let it go |
| 144 | exit 0 |
| 145 | fi |
| 146 | |
Ray Essick | be5e36b | 2021-02-10 09:56:45 -0800 | [diff] [blame] | 147 | # |
| 148 | # exit 0 is "all good, no output passed along to user" |
| 149 | # exit 77 is "a warning, pass along the output to the user" |
| 150 | # exit 1 will be a failure. |
| 151 | # |
Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 152 | result=0 |
Ray Essick | be5e36b | 2021-02-10 09:56:45 -0800 | [diff] [blame] | 153 | |
| 154 | # simple reminder that it should also land in mainline branch |
| 155 | # |
| 156 | if [ "${current}" != "${MAINLINE_BRANCH}" ] ; then |
| 157 | # simple reminder to ensure it hits mainline |
| 158 | result=77 |
| 159 | cat - <<EOF |
| 160 | You are uploading repo ${RED}${REPO_PATH}${NORMAL} to branch ${RED}${current}${NORMAL}. |
| 161 | The mainline branch for ${RED}${REPO_PATH}${NORMAL} is branch ${RED}${MAINLINE_BRANCH}${NORMAL}. |
| 162 | |
| 163 | Ensure an appropriate cherry pick or equivalent lands in branch ${RED}${MAINLINE_BRANCH}${NORMAL}. |
| 164 | Security bulletin timing or unreleased functionality may drive when this can be landed. |
| 165 | EOF |
| 166 | fi |
| 167 | |
| 168 | # watch for the mixed some mainline / some not CL |
| 169 | # we usually want to reject such mixed CLs |
| 170 | # |
| 171 | |
Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 172 | if [ ! -z "${mainline_no}" ] ; then |
| 173 | # mixed bag, suggest (not insist) that developer split them. |
| 174 | result=1 |
| 175 | cat - <<EOF |
Ray Essick | be5e36b | 2021-02-10 09:56:45 -0800 | [diff] [blame] | 176 | This change contains both mainline and non-mainline files. Please separate |
Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 177 | them into separate CLs. It may also be appropriate to update the list of mainline |
| 178 | files in ${RED}${REPO_ROOT}/${filelist_file}${NORMAL}. |
| 179 | |
| 180 | EOF |
| 181 | echo "===== Mainline files =====" |
| 182 | echo -e ${RED} |
| 183 | echo ${mainline_yes} | sed -e 's/ /
/g' |
| 184 | echo -e ${NORMAL} |
| 185 | |
| 186 | echo "===== Non-Mainline files =====" |
| 187 | echo -e ${RED} |
| 188 | echo ${mainline_no} | sed -e 's/ /
/g' |
| 189 | echo -e ${NORMAL} |
| 190 | |
Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 191 | cat - <<EOF |
| 192 | |
| 193 | If you are sure you want to proceed uploading to branch ${RED}${current}${NORMAL}, |
| 194 | re-run your repo upload command with the '--no-verify' option |
| 195 | |
| 196 | EOF |
| 197 | fi |
Ray Essick | be5e36b | 2021-02-10 09:56:45 -0800 | [diff] [blame] | 198 | |
| 199 | # result will be: |
| 200 | # 0: all good, no output passed to user |
| 201 | # 77: warnings (but we pass), output passed along to user |
| 202 | # else: failure, output passed along to the user |
| 203 | |
Ray Essick | 1ca2522 | 2020-05-26 14:20:40 -0700 | [diff] [blame] | 204 | exit ${result} |
| 205 | |