On 10/23/2015 11:11 AM, Jeff Law wrote:
On 10/23/2015 06:24 AM, Andrew MacLeod wrote:
Hmm. yeah, It was mostly intended to show you what structure you have
and are getting indirectly, not so much indicate that you actually
include things directly twice. It utilizes a common function which
returns unique header files (find_unique_include_list) and just
processes those. A quick tweak should resolve that to just linearly
parse and process.
It may not be worth the trouble.
There were maybe a half-dozen files with repeated direct includes and
they stood out as not being as mechanical as the others (with respect
to reviewing the changes). I suspect that in the future it won't
happen much, if at all, and we won't be looking at 15k line patches to
clean things up.
It also occurs to me the reason you only found one options.h in the
previous note... show-headers probably didn't know where to look for
your build directory to delve into tm.h. It defaults to ../../build
which is what I use. I will also tweak that to attempt to automatically
find a build directory below ../.. and failing that, have you
specify one.
Yea, I almost asked about procedures for the tool to find tm.h as it
was relatively common for tm.h to include something indirectly and
make later stuff redundant. But after a while, I got pretty good at
knowing what was in tm.h and how that would effect what headers became
redundant as tm.h got included earlier (via target.h). Similarly for
optabs.h moving around and making other stuff redundant.
Apply this diff to the contents of contrib/headers
Duplicates are now treated as they are seen instead of ignored.
Rather than hardcoding ../../build/gcc, the tool now makes an attempt to
find a "gcc/tm.h" from ../.. It will print a message if it fails to
find one. In which case you can use -i to specify a directory to look in
Andrew
*** headerutils.py 2015-10-23 11:55:46.652867427 -0400
--- /home/amacleod/headers/headerutils.py 2015-10-23 11:57:13.247023166
-0400
*************** def ii_write (fname, obj):
*** 216,221 ****
--- 216,258 ----
pickle.dump (obj[5], f)
f.close ()
+ # execute a system command which returns file names
+ def execute_command (command):
+ files = list()
+ f = os.popen (command)
+ for x in f:
+ if x[0:2] == "./":
+ fn = x.rstrip()[2:]
+ else:
+ fn = x.rstrip()
+ files.append(fn)
+ return files
+
+ # Try to locate a build directory from PATH
+ def find_gcc_bld_dir (path):
+ blddir = ""
+ # Look for blddir/gcc/tm.h
+ command = "find " + path + " -mindepth 2 -maxdepth 3 -name tm.h"
+ files = execute_command (command)
+ for y in files:
+ p = os.path.dirname (y)
+ if os.path.basename (p) == "gcc":
+ blddir = p
+ break
+ # If not found, try looking a bit deeper
+ # Dont look this deep initially because a lot of cross target builds may
show
+ # up in the list before a native build... but those are better than nothing.
+ if not blddir:
+ command = "find " + path + " -mindepth 3 -maxdepth 5 -name tm.h"
+ files = execute_command (command)
+ for y in files:
+ p = os.path.dirname (y)
+ if os.path.basename (p) == "gcc":
+ blddir = p
+ break
+
+ return blddir
+
# Find files matching pattern NAME, return in a list.
# CURRENT is True if you want to include the current directory
*************** def find_gcc_files (name, current, deepe
*** 235,247 ****
command = "find -maxdepth 4 -mindepth 2 -name " + name + " -not -path
\"./testsuite/*\""
if command != "":
! f = os.popen (command)
! for x in f:
! if x[0] == ".":
! fn = x.rstrip()[2:]
! else:
! fn = x
! files.append(fn)
return files
--- 272,278 ----
command = "find -maxdepth 4 -mindepth 2 -name " + name + " -not -path
\"./testsuite/*\""
if command != "":
! files = execute_command (command)
return files
*** show-headers 2015-10-23 11:55:46.655867328 -0400
--- /home/amacleod/headers/show-headers 2015-10-23 11:53:43.668906942 -0400
*************** sawcore = False
*** 17,26 ****
# list of headers to emphasize
highlight = list ()
# search path for headers
! incl_dirs = [".", "../include", "../../build/gcc", "../libcpp/include" ]
# extra search paths to look in *after* the directory the source file is in.
- extra_dirs = [ "common", "c-family", "c", "cp", "config" ]
# append (1) to the end of the first line which includes INC in list INC.
def append_1 (output, inc):
--- 17,26 ----
# list of headers to emphasize
highlight = list ()
+ bld_dir = ""
# search path for headers
! incl_dirs = ["../include", "../libcpp/include", "common", "c-family", "c",
"cp", "config" ]
# extra search paths to look in *after* the directory the source file is in.
# append (1) to the end of the first line which includes INC in list INC.
def append_1 (output, inc):
*************** def process_include (inc, indent):
*** 75,89 ****
! blddir = [ "." ]
usage = False
src = list()
for x in sys.argv[1:]:
if x[0:2] == "-i":
bld = x[2:]
! print "Build dir : " + bld
! blddir.append (bld)
elif x[0:2] == "-s":
highlight.append (os.path.basename (x[2:]))
elif x[0:2] == "-h":
--- 75,88 ----
! extradir = list()
usage = False
src = list()
for x in sys.argv[1:]:
if x[0:2] == "-i":
bld = x[2:]
! extradir.append (bld)
elif x[0:2] == "-s":
highlight.append (os.path.basename (x[2:]))
elif x[0:2] == "-h":
*************** if usage:
*** 104,129 ****
print " is included in a source file. Should be run from the source
directory"
print " files from find-include-depends"
print " -s : search for a header, and point it out."
! print " -i : Specifies 1 or more directories to search for includes."
sys.exit(0)
- if len(blddir) > 1:
- incl_dirs = blddir
x = src[0]
- # if source is in a subdirectory, add the subdirectory to the search list
srcpath = os.path.dirname(x)
if srcpath:
! incl_dirs.append (srcpath)
! for yy in extra_dirs:
! incl_dirs.append (yy)
output = list()
sawcore = False
! incl = find_unique_include_list (x)
! for inc in incl:
! process_include (inc, 1)
print "\n" + x
for line in output:
print line
--- 103,142 ----
print " is included in a source file. Should be run from the source
directory"
print " files from find-include-depends"
print " -s : search for a header, and point it out."
! print " -i : Specifies additonal directories to search for includes."
sys.exit(0)
+ if extradir:
+ incl_dirs = extradir + incl_dirs;
+
+ blddir = find_gcc_bld_dir ("../..")
+
+ if blddir:
+ print "Using build directory: " + blddir
+ incl_dirs.insert (0, blddir)
+ else:
+ print "Could not find a build directory, better results if you specify one
with -i"
+
+ # search path is now ".", blddir, extradirs_from_-i, built_in_incl_dirs
+ incl_dirs.insert (0, ".")
+
+ # if source is in a subdirectory, prepend the subdirectory to the search list
x = src[0]
srcpath = os.path.dirname(x)
if srcpath:
! incl_dirs.insert (0, srcpath)
output = list()
sawcore = False
!
! data = open (x).read().splitlines()
! for line in data:
! d = find_pound_include (line, True, True)
! if d and d[-2:] == ".h":
! process_include (d, 1)
!
print "\n" + x
for line in output:
print line
*** README 2015-10-23 11:55:46.655867328 -0400
--- /home/amacleod/headers/README 2015-10-23 11:58:50.100841918 -0400
*************** show-headers
*** 62,68 ****
is indented, and when any duplicate headers are seen, they have their
duplicate number shown
! -i may be used to specify alternate search directories for headers to parse.
-s specifies headers to look for and emphasize in the output.
This tool must be run in the core gcc source directory.
--- 62,68 ----
is indented, and when any duplicate headers are seen, they have their
duplicate number shown
! -i may be used to specify additional search directories for headers to
parse.
-s specifies headers to look for and emphasize in the output.
This tool must be run in the core gcc source directory.