BaseTools: Collect full Header files for struct finding.

Currently, only parts of the Header files can be collected which
caused some struct definition can not be found. To solve this issue,
Header files full collection has been added in this file to support
the struct finding.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
Chen, Christine
2020-11-24 16:40:23 +08:00
committed by mergify[bot]
parent f69a2b9a42
commit 8501bb0c05

View File

@ -370,7 +370,7 @@ class PATH(object):
def __init__(self,path): def __init__(self,path):
self.path=path self.path=path
self.rootdir=self.get_root_dir() self.rootdir=self.get_root_dir()
self.usefuldir=[] self.usefuldir=set()
self.lstinf = {} self.lstinf = {}
for path in self.rootdir: for path in self.rootdir:
for o_root, o_dir, o_file in os.walk(os.path.join(path, "OUTPUT"), topdown=True, followlinks=False): for o_root, o_dir, o_file in os.walk(os.path.join(path, "OUTPUT"), topdown=True, followlinks=False):
@ -381,7 +381,7 @@ class PATH(object):
for LST in l_file: for LST in l_file:
if os.path.splitext(LST)[1] == '.lst': if os.path.splitext(LST)[1] == '.lst':
self.lstinf[os.path.join(l_root, LST)] = os.path.join(o_root, INF) self.lstinf[os.path.join(l_root, LST)] = os.path.join(o_root, INF)
self.usefuldir.append(path) self.usefuldir.add(path)
def get_root_dir(self): def get_root_dir(self):
rootdir=[] rootdir=[]
@ -410,7 +410,7 @@ class PATH(object):
def header(self,struct): def header(self,struct):
header={} header={}
head_re = re.compile('typedef.*} %s;[\n]+(.*?)(?:typedef|formset)'%struct,re.M|re.S) head_re = re.compile('typedef.*} %s;[\n]+(.*)(?:typedef|formset)'%struct,re.M|re.S)
head_re2 = re.compile(r'#line[\s\d]+"(\S+h)"') head_re2 = re.compile(r'#line[\s\d]+"(\S+h)"')
for i in list(self.lstinf.keys()): for i in list(self.lstinf.keys()):
with open(i,'r') as lst: with open(i,'r') as lst:
@ -421,9 +421,21 @@ class PATH(object):
if head: if head:
format = head[0].replace('\\\\','/').replace('\\','/') format = head[0].replace('\\\\','/').replace('\\','/')
name =format.split('/')[-1] name =format.split('/')[-1]
head = self.makefile(name).replace('\\','/') head = self.headerfileset.get(name)
header[struct] = head if head:
head = head.replace('\\','/')
header[struct] = head
return header return header
@property
def headerfileset(self):
headerset = dict()
for root,dirs,files in os.walk(self.path):
for file in files:
if os.path.basename(file) == 'deps.txt':
with open(os.path.join(root,file),"r") as fr:
for line in fr.readlines():
headerset[os.path.basename(line).strip()] = line.strip()
return headerset
def makefile(self,filename): def makefile(self,filename):
re_format = re.compile(r'DEBUG_DIR.*(?:\S+Pkg)\\(.*\\%s)'%filename) re_format = re.compile(r'DEBUG_DIR.*(?:\S+Pkg)\\(.*\\%s)'%filename)
@ -433,6 +445,7 @@ class PATH(object):
dir = re_format.findall(read) dir = re_format.findall(read)
if dir: if dir:
return dir[0] return dir[0]
return None
class mainprocess(object): class mainprocess(object):
@ -479,7 +492,7 @@ class mainprocess(object):
WARNING.append("Warning: No <HeaderFiles> for struct %s"%struct) WARNING.append("Warning: No <HeaderFiles> for struct %s"%struct)
title2 = '%s%s|{0}|%s|0xFCD00000{\n <HeaderFiles>\n %s\n <Packages>\n%s\n}\n' % (PCD_NAME, c_name, struct, '', self.LST.package()[self.lst_dict[lstfile]]) title2 = '%s%s|{0}|%s|0xFCD00000{\n <HeaderFiles>\n %s\n <Packages>\n%s\n}\n' % (PCD_NAME, c_name, struct, '', self.LST.package()[self.lst_dict[lstfile]])
header_list.append(title2) header_list.append(title2)
else: elif struct not in lst._ignore:
struct_dict ={} struct_dict ={}
print("ERROR: Struct %s can't found in lst file" %struct) print("ERROR: Struct %s can't found in lst file" %struct)
ERRORMSG.append("ERROR: Struct %s can't found in lst file" %struct) ERRORMSG.append("ERROR: Struct %s can't found in lst file" %struct)