Caroline Tice | b02b811 | 2015-11-11 14:28:53 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This script is supposed to verify which compiler (GCC or clang) was |
| 4 | # used to build the packages in a ChromeOS image. To use the script, |
| 5 | # just pass the path to the tree containing the *.debug files for a |
| 6 | # ChromeOS image. It then reads the debug info in each .debug file |
| 7 | # it can find, checking the AT_producer field to determine whether |
| 8 | # the package was built with clang or GCC. It counts the total |
| 9 | # number of .debug files found as well as how many are built with |
| 10 | # each compiler. It writes out these statistics when it is done. |
| 11 | # |
| 12 | # For a locally-built ChromeOS image, the debug directory is usually: |
| 13 | # ${chromeos_root}/chroot/build/${board}/usr/lib/debug (from outside |
| 14 | # chroot) |
| 15 | # or |
| 16 | # /build/${board}/usr/lib/debug (from inside chroot) |
| 17 | # |
| 18 | # For a buildbot-built image you can usually download the debug tree |
| 19 | # (using 'gsutil cp') from |
| 20 | # gs://chromeos-archive-image/<path-to-your-artifact-tree>/debug.tgz |
| 21 | # After downloading it somewhere, you will need to uncompress and |
| 22 | # untar it before running this script. |
| 23 | # |
| 24 | |
| 25 | DEBUG_TREE=$1 |
| 26 | |
| 27 | clang_count=0 |
| 28 | gcc_count=0 |
| 29 | file_count=0 |
| 30 | |
| 31 | # Verify the argument. |
| 32 | |
| 33 | if [[ $# != 1 ]]; then |
| 34 | echo "Usage error:" |
| 35 | echo "compiler-test.sh <debug_directory>" |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | |
| 40 | if [[ ! -d ${DEBUG_TREE} ]] ; then |
| 41 | echo "Cannot find ${DEBUG_TREE}." |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | cd ${DEBUG_TREE} |
| 46 | for f in `find . -name "*.debug" -type f` ; do |
| 47 | at_producer=`readelf --debug-dump=info $f | head -25 | grep AT_producer `; |
| 48 | if echo ${at_producer} | grep -q 'GNU C' ; then |
| 49 | ((gcc_count++)) |
| 50 | elif echo ${at_producer} | grep -q 'clang'; then |
| 51 | ((clang_count++)); |
| 52 | fi; |
| 53 | ((file_count++)) |
| 54 | done |
| 55 | |
| 56 | echo "GCC count: ${gcc_count}" |
| 57 | echo "Clang count: ${clang_count}" |
| 58 | echo "Total file count: ${file_count}" |
| 59 | |
| 60 | |
| 61 | exit 0 |