Makoto Onuki | 6cb0cdb | 2024-08-15 10:26:58 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2024 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | set -e |
| 17 | |
| 18 | SCRIPT_NAME="${0##*/}" |
| 19 | |
| 20 | usage() { |
| 21 | cat <<"EOF" |
| 22 | |
| 23 | $SCRIPT_NAME: Shrink / unshrink SystemUiRavenTests. |
| 24 | |
| 25 | SystemUiRavenTests has a lot of kotlin source files, so it's slow to build, |
| 26 | which is painful when you want to run it after updating ravenwood code |
| 27 | that SystemUiRavenTests depends on. (example: junit-src/) |
| 28 | |
| 29 | This script basically removes the test files in SystemUI/multivalentTests |
| 30 | that don't have @EnabledOnRavenwood. But if we actaully remove them, |
| 31 | soong would re-generate the ninja file, which will take a long time, |
| 32 | so instead it'll truncate them. |
| 33 | |
| 34 | This script will also tell git to ignore these files, so they won't shw up |
| 35 | in `git status`. |
| 36 | (Use `git ls-files -v | sed -ne "s/^[a-zS] //p"` to show ignored filse.) |
| 37 | |
| 38 | Usage: |
| 39 | $SCRIPT_NAME -s # Shrink the test files. |
| 40 | |
| 41 | $SCRIPT_NAME -u # Undo it. |
| 42 | |
| 43 | EOF |
| 44 | } |
| 45 | |
| 46 | TEST_PATH=${ANDROID_BUILD_TOP}/frameworks/base/packages/SystemUI/multivalentTests |
| 47 | cd "$TEST_PATH" |
| 48 | |
| 49 | command="" |
| 50 | case "$1" in |
| 51 | "-s") command=shrink ;; |
| 52 | "-u") command=unshrink ;; |
| 53 | *) usage ; exit 1 ;; |
| 54 | esac |
| 55 | |
| 56 | |
| 57 | echo "Listing test files...." |
| 58 | files=( $(find . -name '*Test.kt' -o -name '*Test.java') ) |
| 59 | |
| 60 | exemption='(BaseHeadsUpManagerTest)' |
| 61 | |
| 62 | shrink() { |
| 63 | local target=() |
| 64 | for file in ${files[@]}; do |
| 65 | # Check for exemption |
| 66 | if echo $file | egrep -q "$exemption"; then |
| 67 | echo " Skip exempted file" |
| 68 | continue |
| 69 | fi |
| 70 | |
| 71 | echo "Checking $file" |
| 72 | if ! [[ -f $file ]] ; then |
| 73 | echo " Skip non regular file" |
| 74 | continue |
| 75 | fi |
| 76 | |
| 77 | if ! [[ -s $file ]] ; then |
| 78 | echo " Skip empty file" |
| 79 | continue |
| 80 | fi |
| 81 | |
| 82 | if grep -q '@EnabledOnRavenwood' $file ; then |
| 83 | echo " Skip ravenwood test file". |
| 84 | continue |
| 85 | fi |
| 86 | |
| 87 | # It's a non ravenwood test file. Empty it. |
| 88 | : > $file |
| 89 | |
| 90 | # Tell git to ignore the file |
| 91 | |
| 92 | target+=($file) |
| 93 | |
| 94 | echo " Emptied" |
| 95 | |
| 96 | done |
| 97 | if (( ${#target[@]} == 0 )) ; then |
| 98 | echo "No files emptied." |
| 99 | return 0 |
| 100 | fi |
| 101 | |
| 102 | git update-index --skip-worktree ${target[@]} |
| 103 | |
| 104 | echo "Emptied ${#target[@]} files" |
| 105 | return 0 |
| 106 | } |
| 107 | |
| 108 | unshrink() { |
| 109 | local target=() |
| 110 | |
| 111 | # Collect empty files |
| 112 | for file in ${files[@]}; do |
| 113 | if [[ -s $file ]] ; then |
| 114 | continue |
| 115 | fi |
| 116 | |
| 117 | target+=($file) |
| 118 | : > $file |
| 119 | done |
| 120 | if (( ${#target[@]} == 0 )) ; then |
| 121 | echo "No files to restore." |
| 122 | return 0 |
| 123 | fi |
| 124 | # Un-ignore the files, and check out the original files |
| 125 | echo "Restoring ${#target[@]} files..." |
| 126 | git update-index --no-skip-worktree ${target[@]} |
| 127 | git checkout goog/main ${target[@]} |
| 128 | return 0 |
| 129 | } |
| 130 | |
| 131 | $command |