#!/usr/bin/env python # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Copyright (C) Darren Hart , 2010 import sys import getopt import os import os.path import re def usage(): print 'Usage: %s -d FILENAME [-d FILENAME]* -m METADIR [-m MATADIR]*' % os.path.basename(sys.argv[0]) print ' -d FILENAME documentation file to search' print ' -h, --help display this help and exit' print ' -m METADIR meta directory to search for recipes' def recipe_bbvars(recipe): ''' Return a unique set of every bbvar encountered in the recipe ''' prog = re.compile("[A-Z_]+") bbvars = set() try: r = open(recipe) except IOError as (errno, strerror): print 'WARNING: Failed to open recipe ', recipe print strerror for line in r: # Strip any comments from the line line = line.rsplit('#')[0] bbvars = bbvars.union(set(prog.findall(line))) r.close() return bbvars def collect_bbvars(metadir): ''' Walk the metadir and collect the bbvars from each recipe found ''' bbvars = set() for root,dirs,files in os.walk(metadir): for name in files: if name.find(".bb") >= 0: bbvars = bbvars.union(recipe_bbvars(os.path.join(root,name))) return bbvars def bbvar_is_documented(var, docfiles): prog = re.compile(".*($|[^A-Z_])%s([^A-Z_]|$)" % (var)) for doc in docfiles: try: f = open(doc) except IOError as (errno, strerror): print 'WARNING: Failed to open doc ', doc print strerror for line in f: if prog.match(line): return True f.close() return False def main(): docfiles = [] metadirs = [] bbvars = set() undocumented = [] # Collect and validate input try: opts, args = getopt.getopt(sys.argv[1:], "d:hm:", ["help"]) except getopt.GetoptError, err: print '%s' % str(err) usage() sys.exit(2) for o, a in opts: if o in ('-h', '--help'): usage() sys.exit(0) elif o == '-d': if os.path.isfile(a): docfiles.append(a) else: print 'ERROR: documentation file %s is not a regular file' % (a) sys.exit(3) elif o == '-m': if os.path.isdir(a): metadirs.append(a) else: print 'ERROR: meta directory %s is not a directory' % (a) sys.exit(4) else: assert False, "unhandled option" if len(docfiles) == 0: print 'ERROR: no docfile specified' usage() sys.exit(5) if len(metadirs) == 0: print 'ERROR: no metadir specified' usage() sys.exit(6) # Collect all the variable names from the recipes in the metadirs for m in metadirs: bbvars = bbvars.union(collect_bbvars(m)) # Check each var for documentation for v in bbvars: if not bbvar_is_documented(v, docfiles): undocumented.append(v) undocumented.sort() # Report all undocumented variables print 'Found %d undocumented bb variables (out of %d):' % (len(undocumented), len(bbvars)) for v in undocumented: print v if __name__ == "__main__": main()