Update vpc_parser.py

Adds a natural way to parse a single VPC file

Used in an upcoming commit.
This commit is contained in:
halotroop2288 2023-01-08 14:15:45 -08:00 committed by Caroline Joy Bell
parent ca168b6f4b
commit ee9e377721
No known key found for this signature in database
GPG Key ID: F90D5CBC4764E559

View File

@ -101,84 +101,98 @@ def fix_dos_path( path ):
return find_path+file return find_path+file
return find_path+filename return find_path+filename
def parse_vpcs( env ,vpcs, basedir ): def parse_vpcs( env, vpcs, basedir ):
back_path = os.path.abspath('.') defines = []
os.chdir(env.SUBPROJECT_PATH[0]) includes = []
sources = []
for vpc in vpcs:
contents = parse_vpc(env, vpc, basedir)
defines += contents["defines"]
includes += contents["includes"]
sources += contents["sources"]
return {'defines':defines, 'includes':includes, 'sources': sources}
def parse_vpc( env, vpc, basedir ):
sources = [] sources = []
defines = [] defines = []
includes = [] includes = []
for vpc in vpcs: back_path = os.path.abspath('.')
f=open(vpc, 'r').read().replace('\\\n', ';') os.chdir(env.SUBPROJECT_PATH[0])
re.sub(r'//.*', '', f) f=open(vpc, 'r').read().replace('\\\n', ';')
l = f.split('\n')
iBrackets = 0 re.sub(r'//.*', '', f)
l = f.split('\n')
next_br = False iBrackets = 0
ret = {}
cur_key = ''
for i in l: next_br = False
if i == '': continue ret = {}
cur_key = ''
s = match_statement.search(i) for i in l:
if s and not compute_statement(env.DEFINES+defines, s.group(0)): if i == '': continue
continue
if i.startswith('$') and iBrackets == 0: s = match_statement.search(i)
ret.update({i:[]}) if s and not compute_statement(env.DEFINES+defines, s.group(0)):
cur_key = i continue
next_br = True
elif i == '{':
iBrackets += 1
next_br = False
elif i == '}':
iBrackets -= 1
elif iBrackets > 0:
ret[cur_key].append(i)
if next_br: if i.startswith('$') and iBrackets == 0:
next_br = False ret.update({i:[]})
cur_key = i
next_br = True
elif i == '{':
iBrackets += 1
next_br = False
elif i == '}':
iBrackets -= 1
elif iBrackets > 0:
ret[cur_key].append(i)
key = project_key(ret) if next_br:
l=ret[key] next_br = False
for i in l: key = project_key(ret)
if '-$File' in i and '.h"' not in i: l=ret[key]
for k in i.split(';'):
k = k.replace('$SRCDIR', basedir)
s = fix_dos_path(k.split('"')[1])
for j in range(len(sources)): for i in l:
if sources[j] == s: if '-$File' in i and '.h"' not in i:
del sources[j] for k in i.split(';'):
break k = k.replace('$SRCDIR', basedir)
s = fix_dos_path(k.split('"')[1])
elif '$File' in i and '.h"' not in i: for j in range(len(sources)):
for j in i.split(';'): if sources[j] == s:
j = j.replace('$SRCDIR', basedir) del sources[j]
s = fix_dos_path(j.split('"')[1]) break
sources.append(s)
elif '$File' in i and '.h"' not in i:
for j in i.split(';'):
j = j.replace('$SRCDIR', basedir)
s = fix_dos_path(j.split('"')[1])
sources.append(s)
for i in ret['$Configuration']:
if '$PreprocessorDefinitions' in i:
i = i.replace('$BASE', '')
s = i.split('"')[1]
s = re.split(';|,', s)
for j in s:
if j != '' and j not in defines:
defines.append(j)
if '$AdditionalIncludeDirectories' in i:
i = i.replace('$BASE', '').replace('$SRCDIR', basedir)
s = i.split('"')[1]
s = re.split(';|,', s)
for j in s:
j = j.replace('\\','/')
if j != '' and j not in includes:
includes.append(j)
for i in ret['$Configuration']:
if '$PreprocessorDefinitions' in i:
i = i.replace('$BASE', '')
s = i.split('"')[1]
s = re.split(';|,', s)
for j in s:
if j != '' and j not in defines:
defines.append(j)
if '$AdditionalIncludeDirectories' in i:
i = i.replace('$BASE', '').replace('$SRCDIR', basedir)
s = i.split('"')[1]
s = re.split(';|,', s)
for j in s:
j = j.replace('\\','/')
if j != '' and j not in includes:
includes.append(j)
os.chdir(back_path) os.chdir(back_path)
return {'defines':defines, 'includes':includes, 'sources': sources} return {'defines':defines, 'includes':includes, 'sources': sources}