*** 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.