summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAmanda Brindle <amanda.r.brindle@intel.com>2017-10-30 14:57:04 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-11-08 22:24:04 +0000
commit70b3fffe5a9f337994c6444a6b6612237056a37f (patch)
treeece23e81857edf47625193a185a0a748fa739ead /scripts
parenta3cccf2a6ee8acddf1387d48fb1b6c56b1c95407 (diff)
downloadpoky-70b3fffe5a9f337994c6444a6b6612237056a37f.tar.gz
scripts/contrib/bbvars.py: Rewrite to use tinfoil
Use tinfoil to collect all variable names globally and in each recipe. No longer show the count of variables if they are undocumented. Fixes [YOCTO #2086] (From OE-Core rev: b947de583964020b488cb1c382877624e96d4319) Signed-off-by: Amanda Brindle <amanda.r.brindle@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/contrib/bbvars.py90
1 files changed, 66 insertions, 24 deletions
diff --git a/scripts/contrib/bbvars.py b/scripts/contrib/bbvars.py
index d8d0594776..556f6529f8 100755
--- a/scripts/contrib/bbvars.py
+++ b/scripts/contrib/bbvars.py
@@ -23,6 +23,14 @@ import os
23import os.path 23import os.path
24import re 24import re
25 25
26# Set up sys.path to let us import tinfoil
27scripts_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
28lib_path = scripts_path + '/lib'
29sys.path.insert(0, lib_path)
30import scriptpath
31scriptpath.add_bitbake_lib_path()
32import bb.tinfoil
33
26def usage(): 34def usage():
27 print('Usage: %s -d FILENAME [-d FILENAME]* -m METADIR [-m MATADIR]*' % os.path.basename(sys.argv[0])) 35 print('Usage: %s -d FILENAME [-d FILENAME]* -m METADIR [-m MATADIR]*' % os.path.basename(sys.argv[0]))
28 print(' -d FILENAME documentation file to search') 36 print(' -d FILENAME documentation file to search')
@@ -66,19 +74,23 @@ def collect_bbvars(metadir):
66 bbvars[key] = 1 74 bbvars[key] = 1
67 return bbvars 75 return bbvars
68 76
69def bbvar_is_documented(var, docfiles): 77def bbvar_is_documented(var, documented_vars):
70 prog = re.compile(".*($|[^A-Z_])%s([^A-Z_]|$)" % (var)) 78 ''' Check if variable (var) is in the list of documented variables(documented_vars) '''
71 for doc in docfiles: 79 if var in documented_vars:
72 try: 80 return True
73 f = open(doc) 81 else:
74 except IOError as err: 82 return False
75 print('WARNING: Failed to open doc ', doc) 83
76 print(err.args[1]) 84def collect_documented_vars(docfiles):
77 for line in f: 85 ''' Walk the docfiles and collect the documented variables '''
78 if prog.match(line): 86 documented_vars = []
79 return True 87 prog = re.compile(".*($|[^A-Z_])<glossentry id=\'var-")
80 f.close() 88 var_prog = re.compile('<glossentry id=\'var-(.*)\'>')
81 return False 89 for d in docfiles:
90 with open(d) as f:
91 documented_vars += var_prog.findall(f.read())
92
93 return documented_vars
82 94
83def bbvar_doctag(var, docconf): 95def bbvar_doctag(var, docconf):
84 prog = re.compile('^%s\[doc\] *= *"(.*)"' % (var)) 96 prog = re.compile('^%s\[doc\] *= *"(.*)"' % (var))
@@ -101,7 +113,7 @@ def bbvar_doctag(var, docconf):
101def main(): 113def main():
102 docfiles = [] 114 docfiles = []
103 metadirs = [] 115 metadirs = []
104 bbvars = {} 116 bbvars = set()
105 undocumented = [] 117 undocumented = []
106 docconf = "" 118 docconf = ""
107 onlydoctags = False 119 onlydoctags = False
@@ -153,33 +165,63 @@ def main():
153 usage() 165 usage()
154 sys.exit(7) 166 sys.exit(7)
155 167
156 # Collect all the variable names from the recipes in the metadirs 168 prog = re.compile("^[^a-z]*$")
157 for m in metadirs: 169 with bb.tinfoil.Tinfoil() as tinfoil:
158 for key,cnt in collect_bbvars(m).items(): 170 tinfoil.prepare(config_only=False)
159 if key in bbvars: 171 parser = bb.codeparser.PythonParser('parser', None)
160 bbvars[key] = bbvars[key] + cnt 172 datastore = tinfoil.config_data
173
174 def bbvars_update(data):
175 if prog.match(data):
176 bbvars.add(data)
177 if tinfoil.config_data.getVarFlag(data, 'python'):
178 try:
179 parser.parse_python(tinfoil.config_data.getVar(data))
180 except bb.data_smart.ExpansionError:
181 pass
182 for var in parser.references:
183 if prog.match(var):
184 bbvars.add(var)
161 else: 185 else:
162 bbvars[key] = cnt 186 try:
187 expandedVar = datastore.expandWithRefs(datastore.getVar(data, False), data)
188 for var in expandedVar.references:
189 if prog.match(var):
190 bbvars.add(var)
191 except bb.data_smart.ExpansionError:
192 pass
193
194 # Use tinfoil to collect all the variable names globally
195 for data in datastore:
196 bbvars_update(data)
197
198 # Collect variables from all recipes
199 for recipe in tinfoil.all_recipe_files():
200 print("Checking %s" % recipe)
201 for data in tinfoil.parse_recipe_file(recipe):
202 bbvars_update(data)
203
204 documented_vars = collect_documented_vars(docfiles)
163 205
164 # Check each var for documentation 206 # Check each var for documentation
165 varlen = 0 207 varlen = 0
166 for v in bbvars.keys(): 208 for v in bbvars:
167 if len(v) > varlen: 209 if len(v) > varlen:
168 varlen = len(v) 210 varlen = len(v)
169 if not bbvar_is_documented(v, docfiles): 211 if not bbvar_is_documented(v, documented_vars):
170 undocumented.append(v) 212 undocumented.append(v)
171 undocumented.sort() 213 undocumented.sort()
172 varlen = varlen + 1 214 varlen = varlen + 1
173 215
174 # Report all undocumented variables 216 # Report all undocumented variables
175 print('Found %d undocumented bb variables (out of %d):' % (len(undocumented), len(bbvars))) 217 print('Found %d undocumented bb variables (out of %d):' % (len(undocumented), len(bbvars)))
176 header = '%s%s%s' % (str("VARIABLE").ljust(varlen), str("COUNT").ljust(6), str("DOCTAG").ljust(7)) 218 header = '%s%s' % (str("VARIABLE").ljust(varlen), str("DOCTAG").ljust(7))
177 print(header) 219 print(header)
178 print(str("").ljust(len(header), '=')) 220 print(str("").ljust(len(header), '='))
179 for v in undocumented: 221 for v in undocumented:
180 doctag = bbvar_doctag(v, docconf) 222 doctag = bbvar_doctag(v, docconf)
181 if not onlydoctags or not doctag == "": 223 if not onlydoctags or not doctag == "":
182 print('%s%s%s' % (v.ljust(varlen), str(bbvars[v]).ljust(6), doctag)) 224 print('%s%s' % (v.ljust(varlen), doctag))
183 225
184 226
185if __name__ == "__main__": 227if __name__ == "__main__":