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