| Jihoon Kang | c32d1f5 | 2023-12-14 19:11:16 +0000 | [diff] [blame] | 1 | #!/bin/bash -e | 
|  | 2 | # | 
|  | 3 | # Copyright 2023 Google Inc. All rights reserved. | 
|  | 4 | # | 
|  | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 6 | # you may not use this file except in compliance with the License. | 
|  | 7 | # You may obtain a copy of the License at | 
|  | 8 | # | 
|  | 9 | #     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 10 | # | 
|  | 11 | # Unless required by applicable law or agreed to in writing, software | 
|  | 12 | # distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 14 | # See the License for the specific language governing permissions and | 
|  | 15 | # limitations under the License. | 
|  | 16 |  | 
|  | 17 | # Convert a list of flags in the input file to a list of metalava options | 
|  | 18 | # that will keep the APIs for those flags will hiding all other flagged | 
|  | 19 | # APIs. | 
|  | 20 |  | 
|  | 21 | FLAGS="$1" | 
|  | 22 |  | 
|  | 23 | FLAGGED="android.annotation.FlaggedApi" | 
|  | 24 |  | 
|  | 25 | # Convert the list of feature flags in the input file to Metalava options | 
|  | 26 | # of the form `--revert-annotation !android.annotation.FlaggedApi("<flag>")` | 
|  | 27 | # to prevent the annotated APIs from being hidden, i.e. include the annotated | 
|  | 28 | # APIs in the SDK snapshots. This also preserves the line comments, they will | 
|  | 29 | # be ignored by Metalava but might be useful when debugging. | 
|  | 30 | while read -r line; do | 
|  | 31 | key=$(echo "$line" | cut -d= -f1) | 
|  | 32 | value=$(echo "$line" | cut -d= -f2) | 
|  | 33 |  | 
|  | 34 | # Skip if value is not true and line does not start with '#' | 
|  | 35 | if [[ ( $value != "true" ) && ( $line =~ ^[^#] )]]; then | 
|  | 36 | continue | 
|  | 37 | fi | 
|  | 38 |  | 
|  | 39 | # Escape and quote the key for sed | 
|  | 40 | escaped_key=$(echo "$key" | sed "s/'/\\\'/g; s/ /\\ /g") | 
|  | 41 |  | 
|  | 42 | echo $line | sed "s|^[^#].*$|--revert-annotation '!$FLAGGED(\"$escaped_key\")'|" | 
|  | 43 | done < "$FLAGS" | 
|  | 44 |  | 
|  | 45 | # Revert all flagged APIs, unless listed above. | 
|  | 46 | echo "--revert-annotation $FLAGGED" |