It is sometimes useful to add comments at the top of a source file. This patch changes hidden API list generation to ignore lines beginning with a hash. Note that due to the sorting constraints on hidden API lists, comments can be only at the top of the files. Test: m appcompat Change-Id: I1bc6fd44d1b1f10a5adc45093d7f7ed5a0c5a54f
25 lines
517 B
Bash
Executable File
25 lines
517 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
if [ -z "$1" ]; then
|
|
source_list=/dev/stdin
|
|
dest_list=/dev/stdout
|
|
else
|
|
source_list="$1"
|
|
dest_list="$1"
|
|
fi
|
|
# Load the file
|
|
readarray A < "$source_list"
|
|
# Sort
|
|
IFS=$'\n'
|
|
# Stash away comments
|
|
C=( $(grep -E '^#' <<< "${A[*]}") )
|
|
A=( $(grep -v -E '^#' <<< "${A[*]}") )
|
|
# Sort entries
|
|
A=( $(LC_COLLATE=C sort -f <<< "${A[*]}") )
|
|
A=( $(uniq <<< "${A[*]}") )
|
|
# Concatenate comments and entries
|
|
A=( ${C[*]} ${A[*]} )
|
|
unset IFS
|
|
# Dump array back into the file
|
|
printf '%s\n' "${A[@]}" > "$dest_list"
|