3 # Generate the file lists for processing with g-ir-scanner
11 def gen_atk_filelist(srcroot
, subdir
, dest
):
12 vars = read_vars_from_AM(os
.path
.join(srcroot
, subdir
, 'Makefile.am'),
13 vars = {'top_builddir':'.'},
14 conds
= {'HAVE_INTROSPECTION':True},
15 filters
= ['introspection_sources', 'introspection_generated_sources'])
17 files
= vars['introspection_sources'].split() + \
18 vars['introspection_generated_sources'].split()
20 with
open(dest
, 'w') as d
:
22 if (i
.startswith('./atk/')):
23 i
= i
.replace('./atk/','')
24 d
.write(srcroot
+ '\\' + subdir
+ '\\' + i
.replace('/', '\\') + '\n')
26 def read_vars_from_AM(path
, vars = {}, conds
= {}, filters
= None):
28 path: path to the Makefile.am
29 vars: predefined variables
30 conds: condition variables for Makefile
31 filters: if None, all variables defined are returned,
32 otherwise, it is a list contains that variables should be returned
34 cur_vars
= vars.copy()
35 RE_AM_VAR_REF
= re
.compile(r
'\$\((\w+?)\)')
36 RE_AM_VAR
= re
.compile(r
'^\s*(\w+)\s*=(.*)$')
37 RE_AM_INCLUDE
= re
.compile(r
'^\s*include\s+(\w+)')
38 RE_AM_CONTINUING
= re
.compile(r
'\\\s*$')
39 RE_AM_IF
= re
.compile(r
'^\s*if\s+(\w+)')
40 RE_AM_ELSE
= re
.compile(r
'^\s*else')
41 RE_AM_ENDIF
= re
.compile(r
'^\s*endif')
43 return RE_AM_VAR_REF
.sub(lambda x
: cur_vars
.get(x
.group(1), ''), cont
)
44 with
open(path
, 'r') as f
:
45 contents
= f
.readlines()
46 #combine continuing lines
49 while i
< len(contents
):
51 if RE_AM_CONTINUING
.search(line
):
52 line
= RE_AM_CONTINUING
.sub('', line
)
54 while j
< len(contents
) and RE_AM_CONTINUING
.search(contents
[j
]):
55 line
+= RE_AM_CONTINUING
.sub('', contents
[j
])
65 #include, var define, var evaluation
69 while i
< len(ncont
) - 1:
72 mo
= RE_AM_IF
.search(line
)
75 skip
= False if mo
.group(1) in conds
and conds
[mo
.group(1)] \
78 mo
= RE_AM_ELSE
.search(line
)
82 mo
= RE_AM_ENDIF
.search(line
)
87 mo
= RE_AM_INCLUDE
.search(line
)
89 cur_vars
.update(read_vars_from_AM(am_eval(mo
.group(1)), cur_vars
, conds
, None))
91 mo
= RE_AM_VAR
.search(line
)
93 cur_vars
[mo
.group(1)] = am_eval(mo
.group(2).strip())
100 ret
[i
] = cur_vars
.get(i
, '')
108 gen_atk_filelist(srcroot
, subdir
, 'atk_list')
111 if __name__
== '__main__':
112 sys
.exit(main(sys
.argv
))