2 ##===- utils/llvmdo - Counts Lines Of Code -------------------*- Script -*-===##
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 ##===----------------------------------------------------------------------===##
10 # This script is a general purpose "apply" function for the source files in LLVM
11 # It uses "find" to locate all the source files and then applies the user's
12 # command to them. As such, this command is often not used by itself much but
13 # the other find related tools (countloc.sh,llvmgrep,getsrcs.sh,userloc.sh) are
14 # all based on this script. This script defines "what is a source file" in
15 # LLVM and so should be maintained if new directories, new file extensions,
16 # etc. are used in LLVM as it progresses.
19 # llvmdo [-topdir DIR] [-dirs "DIRNAMES..."] [-code-only] PROGRAM ARGS...
21 # The -topdir option allows you to specify the llvm source root directly. If it
22 # is not specified then it will be obtained with llvm-config which must be built
25 # The -dirs argument allows you to specify the set of directories that are
26 # searched. The default list of directories searched is:
27 # include lib tools utils runtime autoconf docs test examples projects
28 # Note that you must use quotes around the list of directory names.
30 # The -code-only option specifies that only those files that are considered
31 # "code" should be visited. HTML documentation is considered code, but things
32 # like README files, etc. are not.
34 # Finally, you simply specify whatever program you want to run against each
35 # file and the arguments to give it. The PROGRAM will be given the file name
36 # as its last argument.
37 ##===----------------------------------------------------------------------===##
39 if test $# -lt 1 ; then
40 echo "Usage: llvmdo [-topdir DIR] [-dirs "DIRNAMES...
"] [-code-only] PROGRAM ARGS..."
44 if test "$1" = "-topdir" ; then
48 TOPDIR
=`llvm-config --src-root`
51 if test "$1" = "-dirs" ; then
54 elif test -z "$LLVMDO_DIRS" ; then
55 LLVMDO_DIRS
="include lib tools utils runtime autoconf docs test examples projects cmake"
58 if test "$1" = "-code-only" ; then
65 if test "$1" = "" ; then
66 echo "Missing program name to run"
71 if test ! -x "$PROGRAM" ; then
72 echo "Can't execute $1"
80 -path docs/doxygen/* -o \
81 -path docs/CommandGuide/html/* -o \
82 -path docs/CommandGuide/man/* -o \
83 -path docs/CommandGuide/ps/* -o \
84 -path docs/CommandGuide/man/* -o \
85 -path docs/HistoricalNotes/* -o \
88 -path lib/Support/bzip2/* -o \
89 -path projects/llvm-test/* \
103 -o -name *.gnuplot' \
128 -o -name check-each-file \
129 -o -name codgen-diff \
130 -o -name llvm-native-gcc \
131 -o -name llvm-native-gxx \
133 -o -path include/llvm/ADT/ilist \
134 -o -path test/\*.ll \
135 -o -path test/Scripts/not \
136 -o -path runtime/\*.ll \
138 if test -z "$CODE_ONLY" ; then
139 files_to_match
="$files_to_match \
145 -o -name COPYING.LIB \
159 -o -name aclocal.m4 \
160 -o -name acinclude.m4 \
161 -o -name *LoopSimplifyCrash.ll \
162 -o -name *AST-Remove.ll \
163 -o -name PPCPerfectShuffle.h \
166 if test -d "$TOPDIR" ; then
168 # Have to use the right "find" on a per-platform basis. Most platforms have
169 # Gnu find as "find", but Solaris does not.
171 SunOS
) find_prog
=gfind
;;
174 # Turn off file name generation (globbing) so that substitution of the
175 # variables doesn't cause the shell to create lists of file names
177 $find_prog $LLVMDO_DIRS -type f \
178 \
( $paths_to_ignore \
) -prune \
179 -o \
( \
( $files_to_match \
) \
! \
( $files_to_ignore \
) \
180 -exec $PROGRAM "$@" {} \
; \
)
182 echo "Can't find LLVM top directory in $TOPDIR"