|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Generates an ICU feature coverage support report. |
| 5 | + |
| 6 | +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 7 | +TOP_DIR="${TOP_DIR:-${DIR}/..}" |
| 8 | +cd $TOP_DIR |
| 9 | + |
| 10 | +C_API_HEADER_NAMES=( |
| 11 | + "ustring" |
| 12 | + "ucal" |
| 13 | + "udat" |
| 14 | + "udata" |
| 15 | + "uenum" |
| 16 | + "uloc" |
| 17 | + "ustring" |
| 18 | + "utext" |
| 19 | +) |
| 20 | + |
| 21 | +ICU_INCLUDE_PATH="$(icu-config --cppflags-searchpath | sed -e 's/-I//' | sed -e 's/ //g')" |
| 22 | + |
| 23 | +for header_basename in ${C_API_HEADER_NAMES[@]}; do |
| 24 | + header_fullname="${ICU_INCLUDE_PATH}/unicode/${header_basename}.h" |
| 25 | + echo $header_basename: $header_fullname |
| 26 | + ctags -x --c-kinds=fp $header_fullname | sed -e 's/\s.*$//' \ |
| 27 | + | grep -v U_DEFINE | sort | uniq \ |
| 28 | + > "${TOP_DIR}/coverage/${header_basename}_all.txt" |
| 29 | + |
| 30 | + # Extracts all mentions of functions such as "utext_close" for example from |
| 31 | + # rust docs of the form "/// Implements `utext_close` ... ". This is |
| 32 | + # simplistic but quite enough with a little bit of care. |
| 33 | + find . -path "*rust_icu_${header_basename}/src/*.rs" | \ |
| 34 | + xargs grep "/// Implements \`" | sed -e 's/.*`\(.*\)`.*$/\1/' | \ |
| 35 | + sort | uniq > "${TOP_DIR}/coverage/${header_basename}_implemented.txt" |
| 36 | +done |
| 37 | + |
| 38 | +# Now, write a report out. Again, simplistic, but gets the job done. |
| 39 | + |
| 40 | +REPORT_FILE="${TOP_DIR}/coverage/report.md" |
| 41 | +cat <<EOF > "${REPORT_FILE}" |
| 42 | +# Implementation coverage report |
| 43 | +
|
| 44 | +| Header | Implemented | |
| 45 | +| ------ | ----------- | |
| 46 | +EOF |
| 47 | +for header_basename in ${C_API_HEADER_NAMES[@]}; do |
| 48 | + total_functions="$(cat "${TOP_DIR}"/coverage/${header_basename}_all.txt | wc -l)" |
| 49 | + implemented_functions="$(cat "${TOP_DIR}"/coverage/${header_basename}_implemented.txt | wc -l)" |
| 50 | + echo "| \`${header_basename}.h\` | ${implemented_functions} / ${total_functions} | " >> "${REPORT_FILE}" |
| 51 | +done |
| 52 | + |
| 53 | +cat <<EOF >>"${REPORT_FILE}" |
| 54 | +# Unimplemented functions per header |
| 55 | +
|
| 56 | +EOF |
| 57 | +for header_basename in ${C_API_HEADER_NAMES[@]}; do |
| 58 | + cat <<EOF >>"${REPORT_FILE}" |
| 59 | +
|
| 60 | +# Header: \`${header_basename}.h\` |
| 61 | +
|
| 62 | +| Unimplemented | Implemented | |
| 63 | +| ------------- | ----------- | |
| 64 | +EOF |
| 65 | + for fun in $(cat "${TOP_DIR}/coverage/${header_basename}_implemented.txt"); do |
| 66 | + echo "| | \`${fun}\` |" >>"${REPORT_FILE}" |
| 67 | + done |
| 68 | + |
| 69 | + unimplemented="$(comm -23 \ |
| 70 | + "${TOP_DIR}/coverage/${header_basename}_all.txt" \ |
| 71 | + "${TOP_DIR}/coverage/${header_basename}_implemented.txt" | sort | uniq)" |
| 72 | + for fun in ${unimplemented}; do |
| 73 | + echo "| \`${fun}\` | |" >>"${REPORT_FILE}" |
| 74 | + done |
| 75 | +done |
| 76 | + |
0 commit comments